MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestMergeMissingIntoLeft

Function TestMergeMissingIntoLeft

pkg/ring/merge_test.go:455–495  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

453}
454
455func TestMergeMissingIntoLeft(t *testing.T) {
456 now := time.Now().Unix()
457
458 ring1 := func() *Desc {
459 return &Desc{
460 Ingesters: map[string]InstanceDesc{
461 "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
462 "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
463 "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT},
464 },
465 }
466 }
467
468 ring2 := func() *Desc {
469 return &Desc{
470 Ingesters: map[string]InstanceDesc{
471 "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
472 "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
473 },
474 }
475 }
476
477 {
478 our, ch := mergeLocalCAS(ring1(), ring2(), now+10)
479 assert.Equal(t, &Desc{
480 Ingesters: map[string]InstanceDesc{
481 "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
482 "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
483 "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT},
484 },
485 }, our)
486
487 assert.Equal(t, &Desc{
488 Ingesters: map[string]InstanceDesc{
489 "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{30, 40, 50}},
490 "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}},
491 // Ing 3 is not changed, it was already LEFT
492 },
493 }, ch)
494 }
495}
496
497func mergeLocalCAS(ring1, ring2 *Desc, nowUnixTime int64) (*Desc, *Desc) {
498 change, err := ring1.mergeWithTime(ring2, true, time.Unix(nowUnixTime, 0))

Callers

nothing calls this directly

Calls 2

mergeLocalCASFunction · 0.85
EqualMethod · 0.65

Tested by

no test coverage detected