forked from armon/go-chord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker_server_test.go
72 lines (58 loc) · 1.98 KB
/
tracker_server_test.go
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
package buddystore
/*
func TestTrackerHandleJoin(t *testing.T) {
ringId := "ring1"
tr := NewTracker()
vnode1 := &Vnode{Host: "localnode1:1234", Id: []byte("vnode1")}
vnode2 := &Vnode{Host: "localnode2:3456", Id: []byte("vnode2")}
vnode3 := &Vnode{Host: "localnode3:9876", Id: []byte("vnode3")}
existing, err := tr.handleJoinRing(ringId, vnode1)
assert.NoError(t, err)
assert.Empty(t, existing)
existing, err = tr.handleJoinRing(ringId, vnode2)
assert.NoError(t, err)
assert.NotNil(t, existing)
assert.Equal(t, len(existing), 1)
assert.Equal(t, existing[0], vnode1)
existing, err = tr.handleJoinRing(ringId, vnode3)
assert.NoError(t, err)
assert.NotNil(t, existing)
assert.Equal(t, len(existing), 2)
// TODO: Shouldn't be testing order of vnodes here.
assert.Equal(t, existing[0], vnode1)
assert.Equal(t, existing[1], vnode2)
}
func TestTrackerHandleReJoin(t *testing.T) {
ringId := "ring1"
tr := NewTracker()
vnode1 := &Vnode{Host: "localnode1:1234", Id: []byte("vnode1")}
existing, err := tr.handleJoinRing(ringId, vnode1)
assert.NoError(t, err)
assert.Empty(t, existing)
existing, err = tr.handleJoinRing(ringId, vnode1)
assert.NoError(t, err)
assert.NotNil(t, existing)
assert.Equal(t, len(existing), 1)
assert.Equal(t, existing[0], vnode1)
existing, err = tr.handleJoinRing(ringId, vnode1)
assert.NoError(t, err)
assert.NotNil(t, existing)
assert.Equal(t, len(existing), 1)
assert.Equal(t, existing[0], vnode1)
}
func TestTrackerJoinTimeout(t *testing.T) {
ringId := "ring1"
c := NewFrozenClock()
tr := NewTrackerWithClock(c)
vnode1 := &Vnode{Host: "localnode1:1234", Id: []byte("vnode1")}
vnode2 := &Vnode{Host: "localnode2:3456", Id: []byte("vnode2")}
c.On("AfterFunc", mock.Anything, mock.Anything).Return(nil)
existing, err := tr.(*TrackerImpl).handleJoinRing(ringId, vnode1)
assert.NoError(t, err)
assert.Empty(t, existing)
c.Advance(650 * time.Second)
existing, err = tr.handleJoinRing(ringId, vnode2)
assert.NoError(t, err)
assert.Empty(t, existing)
}
*/