@@ -35,53 +35,93 @@ import (
35
35
func TestIsolationPickWritePartition (t * testing.T ) {
36
36
tl := "tl"
37
37
cases := []struct {
38
- name string
39
- group string
40
- isolationGroups [] string
41
- numWrite int
42
- shouldFallback bool
43
- allowed []string
38
+ name string
39
+ group string
40
+ config * types. TaskListPartitionConfig
41
+ disableIsolation bool
42
+ shouldFallback bool
43
+ allowed []string
44
44
}{
45
45
{
46
- name : "single partition" ,
47
- group : "a" ,
48
- numWrite : 1 ,
49
- isolationGroups : []string {"a" },
50
- allowed : []string {tl },
46
+ name : "single partition" ,
47
+ group : "a" ,
48
+ config : & types.TaskListPartitionConfig {
49
+ WritePartitions : map [int ]* types.TaskListPartition {
50
+ 0 : {},
51
+ },
52
+ },
53
+ allowed : []string {tl },
54
+ },
55
+ {
56
+ name : "single partition - allowed" ,
57
+ group : "a" ,
58
+ config : & types.TaskListPartitionConfig {
59
+ WritePartitions : map [int ]* types.TaskListPartition {
60
+ 0 : {[]string {"a" }},
61
+ },
62
+ },
63
+ allowed : []string {tl },
64
+ },
65
+ {
66
+ name : "single partition - not allowed" ,
67
+ group : "a" ,
68
+ config : & types.TaskListPartitionConfig {
69
+ WritePartitions : map [int ]* types.TaskListPartition {
70
+ 0 : {[]string {"b" }},
71
+ },
72
+ },
73
+ shouldFallback : true ,
74
+ allowed : []string {"fallback" },
51
75
},
52
76
{
53
- name : "multiple partitions - single option" ,
54
- group : "b" ,
55
- numWrite : 2 ,
56
- isolationGroups : []string {"a" , "b" },
57
- allowed : []string {getPartitionTaskListName (tl , 1 )},
77
+ name : "single partition - isolation disabled" ,
78
+ group : "a" ,
79
+ config : & types.TaskListPartitionConfig {
80
+ WritePartitions : map [int ]* types.TaskListPartition {
81
+ 0 : {},
82
+ },
83
+ },
84
+ disableIsolation : true ,
85
+ shouldFallback : true ,
86
+ allowed : []string {"fallback" },
58
87
},
59
88
{
60
- name : "multiple partitions - multiple options" ,
61
- group : "a" ,
62
- numWrite : 2 ,
63
- isolationGroups : []string {"a" },
64
- allowed : []string {tl , getPartitionTaskListName (tl , 1 )},
89
+ name : "multiple partitions - single option" ,
90
+ group : "b" ,
91
+ config : & types.TaskListPartitionConfig {
92
+ WritePartitions : map [int ]* types.TaskListPartition {
93
+ 0 : {[]string {"a" }},
94
+ 1 : {[]string {"b" }},
95
+ },
96
+ },
97
+ allowed : []string {getPartitionTaskListName (tl , 1 )},
65
98
},
66
99
{
67
- name : "fallback - no group" ,
68
- numWrite : 2 ,
69
- isolationGroups : []string {"a" },
70
- shouldFallback : true ,
71
- allowed : []string {"fallback" },
100
+ name : "multiple partitions - multiple options" ,
101
+ group : "a" ,
102
+ config : & types.TaskListPartitionConfig {
103
+ WritePartitions : map [int ]* types.TaskListPartition {
104
+ 0 : {[]string {"a" }},
105
+ 1 : {[]string {"a" }},
106
+ },
107
+ },
108
+ allowed : []string {tl , getPartitionTaskListName (tl , 1 )},
72
109
},
73
110
{
74
- name : "fallback - no groups" ,
75
- group : "a" ,
76
- numWrite : 2 ,
77
- isolationGroups : []string {"" },
78
- shouldFallback : true ,
79
- allowed : []string {"fallback" },
111
+ name : "fallback - no group" ,
112
+ config : & types.TaskListPartitionConfig {
113
+ WritePartitions : map [int ]* types.TaskListPartition {
114
+ 0 : {[]string {"a" }},
115
+ 1 : {[]string {"b" }},
116
+ },
117
+ },
118
+ shouldFallback : true ,
119
+ allowed : []string {"fallback" },
80
120
},
81
121
}
82
122
for _ , tc := range cases {
83
123
t .Run (tc .name , func (t * testing.T ) {
84
- lb , fallback := createWithMocks (t , tc .isolationGroups , tc .numWrite , tc . numWrite )
124
+ lb , fallback := createWithMocks (t , ! tc .disableIsolation , tc .config )
85
125
req := & types.AddDecisionTaskRequest {
86
126
DomainUUID : "domainId" ,
87
127
TaskList : & types.TaskList {
@@ -106,69 +146,93 @@ func TestIsolationPickWritePartition(t *testing.T) {
106
146
func TestIsolationPickReadPartition (t * testing.T ) {
107
147
tl := "tl"
108
148
cases := []struct {
109
- name string
110
- group string
111
- isolationGroups []string
112
- numRead int
113
- numWrite int
114
- shouldFallback bool
115
- allowed []string
149
+ name string
150
+ group string
151
+ config * types.TaskListPartitionConfig
152
+ disableIsolation bool
153
+ shouldFallback bool
154
+ allowed []string
116
155
}{
117
156
{
118
- name : "single partition" ,
119
- group : "a" ,
120
- numRead : 1 ,
121
- numWrite : 1 ,
122
- isolationGroups : []string {"a" },
123
- allowed : []string {tl },
157
+ name : "single partition" ,
158
+ group : "a" ,
159
+ config : & types.TaskListPartitionConfig {
160
+ ReadPartitions : map [int ]* types.TaskListPartition {
161
+ 0 : {},
162
+ },
163
+ },
164
+ allowed : []string {tl },
165
+ },
166
+ {
167
+ name : "single partition - allowed" ,
168
+ group : "a" ,
169
+ config : & types.TaskListPartitionConfig {
170
+ ReadPartitions : map [int ]* types.TaskListPartition {
171
+ 0 : {[]string {"a" }},
172
+ },
173
+ },
174
+ allowed : []string {tl },
124
175
},
125
176
{
126
- name : "multiple partitions - single option" ,
127
- group : "b" ,
128
- numRead : 2 ,
129
- numWrite : 2 ,
130
- isolationGroups : []string {"a" , "b" },
131
- allowed : []string {getPartitionTaskListName (tl , 1 )},
177
+ name : "single partition - not allowed" ,
178
+ group : "a" ,
179
+ config : & types.TaskListPartitionConfig {
180
+ ReadPartitions : map [int ]* types.TaskListPartition {
181
+ 0 : {[]string {"b" }},
182
+ },
183
+ },
184
+ shouldFallback : true ,
185
+ allowed : []string {"fallback" },
132
186
},
133
187
{
134
- name : "multiple partitions - multiple options" ,
135
- group : "a" ,
136
- numRead : 2 ,
137
- numWrite : 2 ,
138
- isolationGroups : []string {"a" },
139
- allowed : []string {tl , getPartitionTaskListName (tl , 1 )},
188
+ name : "single partition - isolation disabled" ,
189
+ group : "a" ,
190
+ config : & types.TaskListPartitionConfig {
191
+ ReadPartitions : map [int ]* types.TaskListPartition {
192
+ 0 : {},
193
+ },
194
+ },
195
+ disableIsolation : true ,
196
+ shouldFallback : true ,
197
+ allowed : []string {"fallback" },
140
198
},
141
199
{
142
- name : "scaling - multiple options" ,
143
- group : "d" ,
144
- numRead : 4 ,
145
- numWrite : 3 ,
146
- isolationGroups : []string {"a" , "b" , "c" , "d" },
147
- // numRead = 4 means tasks for d could be in the last partition (idx=3)
148
- // numWrite = 3 means new tasks for d are being written to the root (idx=0)
149
- allowed : []string {tl , getPartitionTaskListName (tl , 3 )},
200
+ name : "multiple partitions - single option" ,
201
+ group : "b" ,
202
+ config : & types.TaskListPartitionConfig {
203
+ ReadPartitions : map [int ]* types.TaskListPartition {
204
+ 0 : {[]string {"a" }},
205
+ 1 : {[]string {"b" }},
206
+ },
207
+ },
208
+ allowed : []string {getPartitionTaskListName (tl , 1 )},
150
209
},
151
210
{
152
- name : "fallback - no group" ,
153
- numRead : 2 ,
154
- numWrite : 2 ,
155
- isolationGroups : []string {"a" },
156
- shouldFallback : true ,
157
- allowed : []string {"fallback" },
211
+ name : "multiple partitions - multiple options" ,
212
+ group : "a" ,
213
+ config : & types.TaskListPartitionConfig {
214
+ ReadPartitions : map [int ]* types.TaskListPartition {
215
+ 0 : {[]string {"a" }},
216
+ 1 : {[]string {"a" }},
217
+ },
218
+ },
219
+ allowed : []string {tl , getPartitionTaskListName (tl , 1 )},
158
220
},
159
221
{
160
- name : "fallback - no groups" ,
161
- group : "a" ,
162
- numRead : 2 ,
163
- numWrite : 2 ,
164
- isolationGroups : []string {"" },
165
- shouldFallback : true ,
166
- allowed : []string {"fallback" },
222
+ name : "fallback - no group" ,
223
+ config : & types.TaskListPartitionConfig {
224
+ ReadPartitions : map [int ]* types.TaskListPartition {
225
+ 0 : {[]string {"a" }},
226
+ 1 : {[]string {"b" }},
227
+ },
228
+ },
229
+ shouldFallback : true ,
230
+ allowed : []string {"fallback" },
167
231
},
168
232
}
169
233
for _ , tc := range cases {
170
234
t .Run (tc .name , func (t * testing.T ) {
171
- lb , fallback := createWithMocks (t , tc .isolationGroups , tc .numWrite , tc . numRead )
235
+ lb , fallback := createWithMocks (t , ! tc .disableIsolation , tc .config )
172
236
req := & types.MatchingQueryWorkflowRequest {
173
237
DomainUUID : "domainId" ,
174
238
TaskList : & types.TaskList {
@@ -187,69 +251,85 @@ func TestIsolationPickReadPartition(t *testing.T) {
187
251
188
252
func TestIsolationGetPartitionsForGroup (t * testing.T ) {
189
253
cases := []struct {
190
- name string
191
- group string
192
- isolationGroups []string
193
- partitions int
194
- expected []int
254
+ name string
255
+ group string
256
+ partitions map [int ]* types.TaskListPartition
257
+ expected []int
195
258
}{
196
259
{
197
- name : "single partition" ,
198
- group : "a" ,
199
- isolationGroups : []string {"a" , "b" , "c" },
200
- partitions : 1 ,
201
- expected : []int {0 },
260
+ name : "single partition" ,
261
+ group : "a" ,
262
+ partitions : map [int ]* types.TaskListPartition {
263
+ 0 : {[]string {"a" , "b" , "c" }},
264
+ },
265
+ expected : []int {0 },
202
266
},
203
267
{
204
- name : "partitions less than groups" ,
205
- group : "b" ,
206
- isolationGroups : []string {"a" , "b" , "c" },
207
- partitions : 2 ,
208
- expected : []int {1 },
268
+ name : "single partition - wildcard" ,
269
+ group : "a" ,
270
+ partitions : map [int ]* types.TaskListPartition {
271
+ 0 : {},
272
+ },
273
+ expected : []int {0 },
209
274
},
210
275
{
211
- name : "partitions equals groups" ,
212
- group : "c" ,
213
- isolationGroups : []string {"a" , "b" , "c" },
214
- partitions : 3 ,
215
- expected : []int {2 },
276
+ name : "single partition - no options" ,
277
+ group : "a" ,
278
+ partitions : map [int ]* types.TaskListPartition {
279
+ 0 : {[]string {"b" }},
280
+ },
281
+ expected : nil ,
216
282
},
217
283
{
218
- name : "partitions greater than groups" ,
219
- group : "c" ,
220
- isolationGroups : []string {"a" , "b" , "c" },
221
- partitions : 4 ,
222
- expected : []int {2 },
284
+ name : "multiple partitions - single option" ,
285
+ group : "b" ,
286
+ partitions : map [int ]* types.TaskListPartition {
287
+ 0 : {[]string {"a" , "c" }},
288
+ 1 : {[]string {"b" }},
289
+ },
290
+ expected : []int {1 },
223
291
},
224
292
{
225
- name : "partitions greater than groups - multiple assigned" ,
226
- group : "a" ,
227
- isolationGroups : []string {"a" , "b" , "c" },
228
- partitions : 4 ,
229
- expected : []int {0 , 3 },
293
+ name : "multiple partitions - multiple options" ,
294
+ group : "b" ,
295
+ partitions : map [int ]* types.TaskListPartition {
296
+ 0 : {[]string {"a" , "b" , "c" }},
297
+ 1 : {[]string {"b" }},
298
+ 2 : {[]string {"d" }},
299
+ },
300
+ expected : []int {0 , 1 },
230
301
},
231
302
{
232
- name : "not ok - no isolation group" ,
233
- group : "" ,
234
- isolationGroups : []string {"a" },
235
- partitions : 4 ,
303
+ name : "multiple partitions - multiple options with wildcard" ,
304
+ group : "b" ,
305
+ partitions : map [int ]* types.TaskListPartition {
306
+ 0 : {[]string {"a" , "c" }},
307
+ 1 : {[]string {"b" }},
308
+ 2 : {},
309
+ },
310
+ expected : []int {1 , 2 },
236
311
},
237
312
{
238
- name : "not ok - no isolation groups" ,
239
- group : "a" ,
240
- isolationGroups : []string {},
241
- partitions : 4 ,
313
+ name : "multiple partitions - no options" ,
314
+ group : "d" ,
315
+ partitions : map [int ]* types.TaskListPartition {
316
+ 0 : {[]string {"a" , "c" }},
317
+ 1 : {[]string {"b" }},
318
+ 2 : {[]string {"c" }},
319
+ },
320
+ expected : nil ,
242
321
},
243
322
{
244
- name : "not ok - unknown isolation group" ,
245
- group : "d" ,
246
- isolationGroups : []string {"a" , "b" , "c" },
247
- partitions : 4 ,
323
+ name : "no group" ,
324
+ partitions : map [int ]* types.TaskListPartition {
325
+ 0 : {[]string {"a" , "b" , "c" }},
326
+ },
327
+ expected : nil ,
248
328
},
249
329
}
250
330
for _ , tc := range cases {
251
331
t .Run (tc .name , func (t * testing.T ) {
252
- lb , _ := createWithMocks (t , tc . isolationGroups , tc . partitions , tc . partitions )
332
+ lb , _ := createWithMocks (t , true , nil )
253
333
actual , ok := lb .getPartitionsForGroup (tc .group , tc .partitions )
254
334
if tc .expected == nil {
255
335
assert .Nil (t , actual )
@@ -266,18 +346,20 @@ func TestIsolationGetPartitionsForGroup(t *testing.T) {
266
346
}
267
347
}
268
348
269
- func createWithMocks (t * testing.T , isolationGroups [] string , writePartitions , readPartitions int ) (* isolationLoadBalancer , * MockLoadBalancer ) {
349
+ func createWithMocks (t * testing.T , isolationEnabled bool , config * types. TaskListPartitionConfig ) (* isolationLoadBalancer , * MockLoadBalancer ) {
270
350
ctrl := gomock .NewController (t )
271
351
fallback := NewMockLoadBalancer (ctrl )
272
352
cfg := NewMockPartitionConfigProvider (ctrl )
273
- cfg .EXPECT ().GetNumberOfWritePartitions (gomock .Any (), gomock .Any (), gomock .Any ()).Return (writePartitions ).AnyTimes ()
274
- cfg .EXPECT ().GetNumberOfReadPartitions (gomock .Any (), gomock .Any (), gomock .Any ()).Return (readPartitions ).AnyTimes ()
275
- allIsolationGroups := func () []string {
276
- return isolationGroups
277
- }
353
+ cfg .EXPECT ().GetPartitionConfig (gomock .Any (), gomock .Any (), gomock .Any ()).Return (config ).AnyTimes ()
354
+
278
355
return & isolationLoadBalancer {
279
- provider : cfg ,
280
- fallback : fallback ,
281
- allIsolationGroups : allIsolationGroups ,
356
+ provider : cfg ,
357
+ fallback : fallback ,
358
+ domainIDToName : func (s string ) (string , error ) {
359
+ return s , nil
360
+ },
361
+ isolationEnabled : func (s string ) bool {
362
+ return isolationEnabled
363
+ },
282
364
}, fallback
283
365
}
0 commit comments