MCPcopy
hub / github.com/grafana/dskit / TestNormalizationAndConflictResolution

Function TestNormalizationAndConflictResolution

ring/merge_test.go:10–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestNormalizationAndConflictResolution(t *testing.T) {
11 now := time.Now().Unix()
12
13 first := &Desc{
14 Ingesters: map[string]InstanceDesc{
15 "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{50, 40, 40, 30}},
16 "Ing 2": {Addr: "addr2", Timestamp: 123456, State: LEAVING, Tokens: []uint32{100, 5, 5, 100, 100, 200, 20, 10}},
17 "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT, Tokens: []uint32{100, 200, 300}},
18 "Ing 4": {Addr: "addr4", Timestamp: now, State: LEAVING, Tokens: []uint32{30, 40, 50}},
19 "Unknown": {Tokens: []uint32{100}},
20 },
21 }
22
23 second := &Desc{
24 Ingesters: map[string]InstanceDesc{
25 "Unknown": {
26 Timestamp: now + 10,
27 Tokens: []uint32{1000, 2000},
28 },
29 },
30 }
31
32 change, err := first.Merge(second, false)
33 if err != nil {
34 t.Fatal(err)
35 }
36 changeRing := (*Desc)(nil)
37 if change != nil {
38 changeRing = change.(*Desc)
39 }
40
41 assert.Equal(t, &Desc{
42 Ingesters: map[string]InstanceDesc{
43 "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
44 "Ing 2": {Addr: "addr2", Timestamp: 123456, State: LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}},
45 "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT},
46 "Ing 4": {Addr: "addr4", Timestamp: now, State: LEAVING},
47 "Unknown": {Timestamp: now + 10, Tokens: []uint32{1000, 2000}},
48 },
49 }, first)
50
51 assert.Equal(t, &Desc{
52 // change ring is always normalized, "Unknown" ingester has lost two tokens: 100 from first ring (because of second ring), and 1000 (conflict resolution)
53 Ingesters: map[string]InstanceDesc{
54 "Unknown": {Timestamp: now + 10, Tokens: []uint32{1000, 2000}},
55 },
56 }, changeRing)
57}
58
59func merge(ring1, ring2 *Desc) (*Desc, *Desc) {
60 change, err := ring1.Merge(ring2, false)

Callers

nothing calls this directly

Calls 3

MergeMethod · 0.95
FatalMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected