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

Function TestRing_GetWithOptions

ring/ring_test.go:730–956  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

728}
729
730func TestRing_GetWithOptions(t *testing.T) {
731 const testCount = 10_000
732
733 healthyHeartbeat := time.Now()
734 unhealthyHeartbeat := healthyHeartbeat.Add(-2 * time.Minute)
735
736 type testCase struct {
737 name string
738 ringInstances map[string]InstanceDesc
739 strategy ReplicationStrategy
740 options []Option
741 expectedSetSize int
742 expectError bool
743 }
744 cases := []testCase{
745 {
746 name: "no options, default strategy",
747 ringInstances: map[string]InstanceDesc{
748 "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
749 "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
750 "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
751 "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
752 "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
753 "instance-6": {Addr: "127.0.0.6", Zone: "zone-c", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
754 },
755 strategy: NewDefaultReplicationStrategy(),
756 expectedSetSize: 3,
757 expectError: false,
758 },
759 {
760 name: "invalid replication factor, default strategy",
761 ringInstances: map[string]InstanceDesc{
762 "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
763 "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
764 "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
765 "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
766 "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
767 "instance-6": {Addr: "127.0.0.6", Zone: "zone-c", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
768 },
769 strategy: NewDefaultReplicationStrategy(),
770 options: []Option{WithReplicationFactor(1)},
771 expectedSetSize: 3,
772 expectError: false,
773 },
774 {
775 name: "higher replication factor, default strategy",
776 ringInstances: map[string]InstanceDesc{
777 "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
778 "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
779 "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
780 "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
781 "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
782 "instance-6": {Addr: "127.0.0.6", Zone: "zone-c", State: ACTIVE, Timestamp: healthyHeartbeat.Unix()},
783 },
784 strategy: NewDefaultReplicationStrategy(),
785 options: []Option{WithReplicationFactor(6)},
786 expectedSetSize: 0,
787 expectError: true,

Callers

nothing calls this directly

Calls 13

WithReplicationFactorFunction · 0.85
initTokenGeneratorFunction · 0.85
NewDescFunction · 0.85
newRingForTestingFunction · 0.85
RunMethod · 0.80
setRingStateFromDescMethod · 0.80
AddMethod · 0.65
GenerateTokensMethod · 0.65
GetWithOptionsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected