(t *testing.T)
| 1537 | } |
| 1538 | |
| 1539 | func TestRing_GetInstancesWithTokensCounts(t *testing.T) { |
| 1540 | gen := initTokenGenerator(t) |
| 1541 | |
| 1542 | tests := map[string]struct { |
| 1543 | ringInstances map[string]InstanceDesc |
| 1544 | expectedInstancesWithTokensCount int |
| 1545 | expectedInstancesWithTokensInZoneCount map[string]int |
| 1546 | }{ |
| 1547 | "empty ring": { |
| 1548 | ringInstances: nil, |
| 1549 | expectedInstancesWithTokensCount: 0, |
| 1550 | expectedInstancesWithTokensInZoneCount: map[string]int{}, |
| 1551 | }, |
| 1552 | "single zone, no tokens": { |
| 1553 | ringInstances: map[string]InstanceDesc{ |
| 1554 | "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, |
| 1555 | "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: LEAVING, Tokens: []uint32{}}, |
| 1556 | "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: PENDING, Tokens: []uint32{}}, |
| 1557 | "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: JOINING, Tokens: []uint32{}}, |
| 1558 | }, |
| 1559 | expectedInstancesWithTokensCount: 0, |
| 1560 | expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 0}, |
| 1561 | }, |
| 1562 | "single zone, some tokens": { |
| 1563 | ringInstances: map[string]InstanceDesc{ |
| 1564 | "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, |
| 1565 | "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, |
| 1566 | "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: LEAVING, Tokens: gen.GenerateTokens(128, nil)}, |
| 1567 | "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: LEAVING, Tokens: []uint32{}}, |
| 1568 | "instance-5": {Addr: "127.0.0.5", Zone: "zone-a", State: PENDING, Tokens: gen.GenerateTokens(128, nil)}, |
| 1569 | "instance-6": {Addr: "127.0.0.6", Zone: "zone-a", State: PENDING, Tokens: []uint32{}}, |
| 1570 | "instance-7": {Addr: "127.0.0.7", Zone: "zone-a", State: JOINING, Tokens: gen.GenerateTokens(128, nil)}, |
| 1571 | "instance-8": {Addr: "127.0.0.8", Zone: "zone-a", State: JOINING, Tokens: []uint32{}}, |
| 1572 | }, |
| 1573 | expectedInstancesWithTokensCount: 4, |
| 1574 | expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 4}, |
| 1575 | }, |
| 1576 | "multiple zones": { |
| 1577 | ringInstances: map[string]InstanceDesc{ |
| 1578 | "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, |
| 1579 | "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, |
| 1580 | "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: LEAVING, Tokens: gen.GenerateTokens(128, nil)}, |
| 1581 | "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: LEAVING, Tokens: []uint32{}}, |
| 1582 | "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: PENDING, Tokens: gen.GenerateTokens(128, nil)}, |
| 1583 | "instance-6": {Addr: "127.0.0.6", Zone: "zone-d", State: PENDING, Tokens: []uint32{}}, |
| 1584 | "instance-7": {Addr: "127.0.0.7", Zone: "zone-c", State: JOINING, Tokens: gen.GenerateTokens(128, nil)}, |
| 1585 | "instance-8": {Addr: "127.0.0.8", Zone: "zone-d", State: JOINING, Tokens: []uint32{}}, |
| 1586 | }, |
| 1587 | expectedInstancesWithTokensCount: 4, |
| 1588 | expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 1, "zone-b": 1, "zone-c": 2, "zone-d": 0}, |
| 1589 | }, |
| 1590 | } |
| 1591 | |
| 1592 | for testName, testData := range tests { |
| 1593 | t.Run(testName, func(t *testing.T) { |
| 1594 | // Init the ring. |
| 1595 | ringDesc := &Desc{Ingesters: testData.ringInstances} |
| 1596 | for id, instance := range ringDesc.Ingesters { |
nothing calls this directly
no test coverage detected