@@ -26,14 +26,14 @@ var testArgs = Args{
26
26
var testScheduler = & Scheduler {
27
27
args : & testArgs ,
28
28
sessionCtx : nil ,
29
- localInstance : & mockInstance {name : "127.0.0.1" },
29
+ localInstance : & mockInstance {id : "127.0.0.1" },
30
30
}
31
31
32
32
type mockCluster struct {
33
33
}
34
34
35
35
// RegInstance 注册本地实例
36
- func (m * mockCluster ) RegInstance (ctx context.Context , name string ) (base.Instance , error ) {
36
+ func (m * mockCluster ) RegInstance (ctx context.Context , id string ) (base.Instance , error ) {
37
37
return nil , nil
38
38
}
39
39
@@ -44,7 +44,7 @@ func (m *mockCluster) UnregInstance(ctx context.Context) error {
44
44
45
45
// GetLocalInstance 获取本地实例
46
46
func (m * mockCluster ) GetLocalInstance (ctx context.Context ) (base.Instance , error ) {
47
- return & mockInstance {name : "127.0.0.1" }, nil
47
+ return & mockInstance {id : "127.0.0.1" }, nil
48
48
}
49
49
50
50
// GetAllInstances 获取所有实例的列表
@@ -188,7 +188,7 @@ func TestScheduler_calShard(t *testing.T) {
188
188
name : "case2" ,
189
189
args : args {
190
190
allIns : []base.Instance {
191
- & mockInstance {name : "" }, & mockInstance {name : "127.0.0.1" },
191
+ & mockInstance {id : "" }, & mockInstance {id : "127.0.0.1" },
192
192
},
193
193
},
194
194
want : & shardInfo {
@@ -199,9 +199,9 @@ func TestScheduler_calShard(t *testing.T) {
199
199
name : "case with min ws shard num 1" ,
200
200
args : args {
201
201
allIns : []base.Instance {
202
- & mockInstance {name : "fakeip1" },
203
- & mockInstance {name : "fakeip2" },
204
- & mockInstance {name : "127.0.0.1" },
202
+ & mockInstance {id : "fakeip1" },
203
+ & mockInstance {id : "fakeip2" },
204
+ & mockInstance {id : "127.0.0.1" },
205
205
},
206
206
},
207
207
want : & shardInfo {
@@ -212,9 +212,9 @@ func TestScheduler_calShard(t *testing.T) {
212
212
name : "case with min ws shard num 2" ,
213
213
args : args {
214
214
allIns : []base.Instance {
215
- & mockInstance {name : "127.0.0.1" },
216
- & mockInstance {name : "fakeip3" },
217
- & mockInstance {name : "fakeip4" },
215
+ & mockInstance {id : "127.0.0.1" },
216
+ & mockInstance {id : "fakeip3" },
217
+ & mockInstance {id : "fakeip4" },
218
218
},
219
219
},
220
220
want : & shardInfo {
@@ -225,9 +225,9 @@ func TestScheduler_calShard(t *testing.T) {
225
225
name : "case with min ws shard num 3" ,
226
226
args : args {
227
227
allIns : []base.Instance {
228
- & mockInstance {name : "fakeip5" },
229
- & mockInstance {name : "127.0.0.1" },
230
- & mockInstance {name : "fakeip6" },
228
+ & mockInstance {id : "fakeip5" },
229
+ & mockInstance {id : "127.0.0.1" },
230
+ & mockInstance {id : "fakeip6" },
231
231
},
232
232
},
233
233
want : & shardInfo {
@@ -259,22 +259,17 @@ func TestScheduler_calShard(t *testing.T) {
259
259
260
260
// mockInstance 模拟服务实例信息
261
261
type mockInstance struct {
262
- name string
262
+ id string
263
263
}
264
264
265
265
// GetName 获取名称
266
- func (m * mockInstance ) GetName () string {
267
- return m .name
266
+ func (m * mockInstance ) GetID () string {
267
+ return m .id
268
268
}
269
269
270
270
// IsValid 是否有效
271
271
func (m * mockInstance ) IsValid () bool {
272
- return m .name != ""
273
- }
274
-
275
- // IsSame 是否相同
276
- func (m * mockInstance ) IsSame (ins base.Instance ) bool {
277
- return m .name == ins .GetName ()
272
+ return m .id != ""
278
273
}
279
274
280
275
func Test_shardsEqual (t * testing.T ) {
0 commit comments