func TestLinkedListNode(t *testing.T) { first := node.NewLinkedList(chord.ID(10)) checkMappings(t, map[chord.Node][]chord.ID{ first: []chord.ID{8, 10, 12}, }) second := &node.LinkedListNode{ ID: chord.ID(20), } assert.Equal(t, nil, first.Join(second)) checkMappings(t, map[chord.Node][]chord.ID{ first: []chord.ID{1, 40, 10}, second: []chord.ID{11, 19, 20}, }) third := &node.LinkedListNode{ ID: chord.ID(1), } assert.Equal(t, nil, first.Join(third)) checkMappings(t, map[chord.Node][]chord.ID{ first: []chord.ID{5, 10}, second: []chord.ID{11, 19}, third: []chord.ID{1, 40}, }) }
func TestRing(t *testing.T) { first := node.NewLinkedList(chord.ID(10)) r := ring.Ring{Known: first} for _, id := range []chord.ID{chord.ID(1), chord.ID(10), chord.ID(20)} { res, _ := r.Lookup(id) assert.Equal(t, first.Identifier(), res.Identifier()) } second := node.LinkedListNode{ ID: chord.ID(20), } assert.Nil(t, r.Join(&second)) first.Dump() var res chord.Node res, _ = r.Lookup(chord.ID(1)) assert.Equal(t, first.Identifier(), res.Identifier()) res, _ = r.Lookup(chord.ID(12)) assert.Equal(t, second.Identifier(), res.Identifier()) res, _ = r.Lookup(chord.ID(21)) assert.Equal(t, first.Identifier(), res.Identifier()) }