MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestRing_Get_ExtendedReplicationSet

Function TestRing_Get_ExtendedReplicationSet

pkg/ring/ring_test.go:739–934  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

737}
738
739func TestRing_Get_ExtendedReplicationSet(t *testing.T) {
740 healthyTimestamp := time.Now().Unix()
741 unhealthyTimestamp := time.Now().Add(-2 * time.Minute).Unix()
742
743 tests := map[string]struct {
744 operation Operation
745 instances map[string]InstanceDesc
746 numberOfZones int
747 replicationFactor int
748 expectedInstances []InstanceDesc
749 }{
750 "should return exactly number of replication factor when there is no extended replica set": {
751 operation: NewOp([]InstanceState{JOINING, ACTIVE}, func(s InstanceState) bool { return s == JOINING }),
752 instances: map[string]InstanceDesc{
753 "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Tokens: []uint32{1}, Timestamp: healthyTimestamp},
754 "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Tokens: []uint32{2}, Timestamp: healthyTimestamp},
755 "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Tokens: []uint32{3}, Timestamp: healthyTimestamp},
756 "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Tokens: []uint32{4}, Timestamp: healthyTimestamp},
757 },
758 numberOfZones: 0,
759 replicationFactor: 3,
760 expectedInstances: []InstanceDesc{
761 {Addr: "127.0.0.1", State: ACTIVE, Tokens: []uint32{1}, Timestamp: healthyTimestamp},
762 {Addr: "127.0.0.2", State: ACTIVE, Tokens: []uint32{2}, Timestamp: healthyTimestamp},
763 {Addr: "127.0.0.3", State: ACTIVE, Tokens: []uint32{3}, Timestamp: healthyTimestamp},
764 },
765 },
766 "extended replica set should be included in the set": {
767 operation: NewOp([]InstanceState{JOINING, ACTIVE}, func(s InstanceState) bool { return s == JOINING }),
768 instances: map[string]InstanceDesc{
769 "instance-1": {Addr: "127.0.0.1", State: JOINING, Tokens: []uint32{1}, Timestamp: healthyTimestamp},
770 "instance-2": {Addr: "127.0.0.2", State: JOINING, Tokens: []uint32{2}, Timestamp: healthyTimestamp},
771 "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Tokens: []uint32{3}, Timestamp: healthyTimestamp},
772 "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Tokens: []uint32{4}, Timestamp: healthyTimestamp},
773 "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Tokens: []uint32{5}, Timestamp: healthyTimestamp},
774 },
775 numberOfZones: 0,
776 replicationFactor: 3,
777 expectedInstances: []InstanceDesc{
778 {Addr: "127.0.0.1", State: JOINING, Tokens: []uint32{1}, Timestamp: healthyTimestamp},
779 {Addr: "127.0.0.2", State: JOINING, Tokens: []uint32{2}, Timestamp: healthyTimestamp},
780 {Addr: "127.0.0.3", State: ACTIVE, Tokens: []uint32{3}, Timestamp: healthyTimestamp},
781 {Addr: "127.0.0.4", State: ACTIVE, Tokens: []uint32{4}, Timestamp: healthyTimestamp},
782 {Addr: "127.0.0.5", State: ACTIVE, Tokens: []uint32{5}, Timestamp: healthyTimestamp},
783 },
784 },
785 "unhealthy instances should be excluded from the set": {
786 operation: NewOp([]InstanceState{JOINING, ACTIVE}, func(s InstanceState) bool { return s == JOINING }),
787 instances: map[string]InstanceDesc{
788 "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Tokens: []uint32{1}, Timestamp: unhealthyTimestamp},
789 "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Tokens: []uint32{2}, Timestamp: healthyTimestamp},
790 "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Tokens: []uint32{3}, Timestamp: healthyTimestamp},
791 "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Tokens: []uint32{4}, Timestamp: healthyTimestamp},
792 },
793 numberOfZones: 3,
794 replicationFactor: 3,
795 expectedInstances: []InstanceDesc{
796 {Addr: "127.0.0.2", State: ACTIVE, Tokens: []uint32{2}, Timestamp: healthyTimestamp},

Callers

nothing calls this directly

Calls 10

GetTokensMethod · 0.95
getTokensByZoneMethod · 0.95
getTokensInfoMethod · 0.95
GetMethod · 0.95
NewOpFunction · 0.85
getZonesFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected