@@ -26,14 +26,14 @@ var testArgs = Args{
2626var testScheduler = & Scheduler {
2727 args : & testArgs ,
2828 sessionCtx : nil ,
29- localInstance : & mockInstance {name : "127.0.0.1" },
29+ localInstance : & mockInstance {id : "127.0.0.1" },
3030}
3131
3232type mockCluster struct {
3333}
3434
3535// 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 ) {
3737 return nil , nil
3838}
3939
@@ -44,7 +44,7 @@ func (m *mockCluster) UnregInstance(ctx context.Context) error {
4444
4545// GetLocalInstance 获取本地实例
4646func (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
4848}
4949
5050// GetAllInstances 获取所有实例的列表
@@ -188,7 +188,7 @@ func TestScheduler_calShard(t *testing.T) {
188188 name : "case2" ,
189189 args : args {
190190 allIns : []base.Instance {
191- & mockInstance {name : "" }, & mockInstance {name : "127.0.0.1" },
191+ & mockInstance {id : "" }, & mockInstance {id : "127.0.0.1" },
192192 },
193193 },
194194 want : & shardInfo {
@@ -199,9 +199,9 @@ func TestScheduler_calShard(t *testing.T) {
199199 name : "case with min ws shard num 1" ,
200200 args : args {
201201 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" },
205205 },
206206 },
207207 want : & shardInfo {
@@ -212,9 +212,9 @@ func TestScheduler_calShard(t *testing.T) {
212212 name : "case with min ws shard num 2" ,
213213 args : args {
214214 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" },
218218 },
219219 },
220220 want : & shardInfo {
@@ -225,9 +225,9 @@ func TestScheduler_calShard(t *testing.T) {
225225 name : "case with min ws shard num 3" ,
226226 args : args {
227227 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" },
231231 },
232232 },
233233 want : & shardInfo {
@@ -259,22 +259,17 @@ func TestScheduler_calShard(t *testing.T) {
259259
260260// mockInstance 模拟服务实例信息
261261type mockInstance struct {
262- name string
262+ id string
263263}
264264
265265// GetName 获取名称
266- func (m * mockInstance ) GetName () string {
267- return m .name
266+ func (m * mockInstance ) GetID () string {
267+ return m .id
268268}
269269
270270// IsValid 是否有效
271271func (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 != ""
278273}
279274
280275func Test_shardsEqual (t * testing.T ) {
0 commit comments