-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrebalancing_options_test.go
More file actions
159 lines (135 loc) · 5.3 KB
/
rebalancing_options_test.go
File metadata and controls
159 lines (135 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package hdf5
import (
"os"
"testing"
"time"
"github.com/scigolib/hdf5/internal/structures"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestFunctionalOptions_Default tests default behavior (NO rebalancing).
func TestFunctionalOptions_Default(t *testing.T) {
tempFile := "testdata/functional_options_default.h5"
defer os.Remove(tempFile)
// Default: NO rebalancing (like C library)
fw, err := CreateForWrite(tempFile, CreateTruncate)
require.NoError(t, err)
defer fw.Close()
// Verify NO rebalancing configs
assert.Nil(t, fw.lazyRebalancingConfig, "Default should have NO lazy rebalancing")
assert.Nil(t, fw.incrementalRebalancingConfig, "Default should have NO incremental rebalancing")
assert.Nil(t, fw.smartRebalancingConfig, "Default should have NO smart rebalancing")
}
// TestFunctionalOptions_LazyRebalancing tests lazy rebalancing options.
func TestFunctionalOptions_LazyRebalancing(t *testing.T) {
tempFile := "testdata/functional_options_lazy.h5"
defer os.Remove(tempFile)
// Enable lazy rebalancing with custom config
fw, err := CreateForWrite(tempFile, CreateTruncate,
WithLazyRebalancing(
LazyThreshold(0.10),
LazyMaxDelay(10*time.Minute),
LazyBatchSize(200),
),
)
require.NoError(t, err)
defer fw.Close()
// Verify lazy config is set
require.NotNil(t, fw.lazyRebalancingConfig)
assert.Equal(t, 0.10, fw.lazyRebalancingConfig.Threshold)
assert.Equal(t, 10*time.Minute, fw.lazyRebalancingConfig.MaxDelay)
assert.Equal(t, 200, fw.lazyRebalancingConfig.BatchSize)
}
// TestFunctionalOptions_IncrementalRebalancing tests incremental rebalancing options.
func TestFunctionalOptions_IncrementalRebalancing(t *testing.T) {
tempFile := "testdata/functional_options_incremental.h5"
defer os.Remove(tempFile)
// Enable incremental rebalancing with custom config
fw, err := CreateForWrite(tempFile, CreateTruncate,
WithIncrementalRebalancing(
IncrementalBudget(200*time.Millisecond),
IncrementalInterval(10*time.Second),
),
)
require.NoError(t, err)
defer fw.Close()
// Verify incremental config is set
require.NotNil(t, fw.incrementalRebalancingConfig)
assert.Equal(t, 200*time.Millisecond, fw.incrementalRebalancingConfig.Budget)
assert.Equal(t, 10*time.Second, fw.incrementalRebalancingConfig.Interval)
}
// TestFunctionalOptions_Combined tests combining multiple options.
func TestFunctionalOptions_Combined(t *testing.T) {
tempFile := "testdata/functional_options_combined.h5"
defer os.Remove(tempFile)
// Combine lazy + incremental (prerequisite for incremental)
fw, err := CreateForWrite(tempFile, CreateTruncate,
WithLazyRebalancing(
LazyThreshold(0.05),
),
WithIncrementalRebalancing(
IncrementalBudget(100*time.Millisecond),
),
)
require.NoError(t, err)
defer fw.Close()
// Verify both configs are set
assert.NotNil(t, fw.lazyRebalancingConfig)
assert.NotNil(t, fw.incrementalRebalancingConfig)
assert.Equal(t, 0.05, fw.lazyRebalancingConfig.Threshold)
assert.Equal(t, 100*time.Millisecond, fw.incrementalRebalancingConfig.Budget)
}
// TestFunctionalOptions_SmartRebalancing tests smart rebalancing options (placeholder).
func TestFunctionalOptions_SmartRebalancing(t *testing.T) {
tempFile := "testdata/functional_options_smart.h5"
defer os.Remove(tempFile)
// Smart rebalancing (Phase 3 - not fully implemented yet)
fw, err := CreateForWrite(tempFile, CreateTruncate,
WithSmartRebalancing(
SmartAutoDetect(true),
SmartAutoSwitch(true),
SmartMinFileSize(10*MB),
),
)
require.NoError(t, err)
defer fw.Close()
// For now, smart rebalancing is a placeholder
// Full implementation in Phase 3
t.Log("Smart rebalancing API tested (placeholder for Phase 3)")
}
// TestFunctionalOptions_DefaultLazyConfig tests default lazy configuration.
func TestFunctionalOptions_DefaultLazyConfig(t *testing.T) {
tempFile := "testdata/functional_options_default_lazy.h5"
defer os.Remove(tempFile)
// Use default lazy config (no options)
fw, err := CreateForWrite(tempFile, CreateTruncate,
WithLazyRebalancing(), // No options = defaults
)
require.NoError(t, err)
defer fw.Close()
// Verify default values
require.NotNil(t, fw.lazyRebalancingConfig)
assert.Equal(t, 0.05, fw.lazyRebalancingConfig.Threshold) // Default 5%
assert.Equal(t, 5*time.Minute, fw.lazyRebalancingConfig.MaxDelay) // Default 5 min
assert.Equal(t, 100, fw.lazyRebalancingConfig.BatchSize) // Default 100
}
// TestFunctionalOptions_ProgressCallback tests incremental progress callback.
func TestFunctionalOptions_ProgressCallback(t *testing.T) {
tempFile := "testdata/functional_options_callback.h5"
defer os.Remove(tempFile)
fw, err := CreateForWrite(tempFile, CreateTruncate,
WithIncrementalRebalancing(
IncrementalProgressCallback(func(p structures.RebalancingProgress) {
t.Logf("Progress: %d nodes rebalanced, %d remaining", p.NodesRebalanced, p.NodesRemaining)
}),
),
)
require.NoError(t, err)
defer fw.Close()
// Verify callback is set (won't be called in this test since no rebalancing happens)
require.NotNil(t, fw.incrementalRebalancingConfig)
assert.NotNil(t, fw.incrementalRebalancingConfig.ProgressCallback)
// Note: Callback won't actually be called in this test since we don't trigger rebalancing
// This just verifies the API works
t.Log("Progress callback API tested (callback won't fire without rebalancing operations)")
}