(t *testing.T)
| 547 | } |
| 548 | |
| 549 | func TestRing_Get_ZoneAwarenessWithIngesterLeaving(t *testing.T) { |
| 550 | const testCount = 10000 |
| 551 | |
| 552 | tests := map[string]struct { |
| 553 | replicationFactor int |
| 554 | expectedInstances int |
| 555 | expectedZones int |
| 556 | }{ |
| 557 | "should succeed if there are enough instances per zone on RF = 3": { |
| 558 | replicationFactor: 3, |
| 559 | expectedInstances: 3, |
| 560 | expectedZones: 3, |
| 561 | }, |
| 562 | "should succeed if there are enough instances per zone on RF = 2": { |
| 563 | replicationFactor: 2, |
| 564 | expectedInstances: 2, |
| 565 | expectedZones: 2, |
| 566 | }, |
| 567 | } |
| 568 | |
| 569 | for testName, testData := range tests { |
| 570 | t.Run(testName, func(t *testing.T) { |
| 571 | gen := initTokenGenerator(t) |
| 572 | |
| 573 | r := NewDesc() |
| 574 | instances := map[string]InstanceDesc{ |
| 575 | "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE}, |
| 576 | "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE}, |
| 577 | "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: ACTIVE}, |
| 578 | "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: ACTIVE}, |
| 579 | "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: LEAVING}, |
| 580 | "instance-6": {Addr: "127.0.0.6", Zone: "zone-c", State: ACTIVE}, |
| 581 | } |
| 582 | var prevTokens []uint32 |
| 583 | for id, instance := range instances { |
| 584 | ingTokens := gen.GenerateTokens(128, prevTokens) |
| 585 | r.AddIngester(id, instance.Addr, instance.Zone, ingTokens, instance.State, time.Now(), false, time.Time{}, nil) |
| 586 | prevTokens = append(prevTokens, ingTokens...) |
| 587 | } |
| 588 | instancesList := make([]InstanceDesc, 0, len(r.GetIngesters())) |
| 589 | for _, v := range r.GetIngesters() { |
| 590 | instancesList = append(instancesList, v) |
| 591 | } |
| 592 | |
| 593 | ring := newRingForTesting(Config{ |
| 594 | HeartbeatTimeout: time.Hour, |
| 595 | ReplicationFactor: testData.replicationFactor, |
| 596 | ZoneAwarenessEnabled: true, |
| 597 | }, false) |
| 598 | ring.setRingStateFromDesc(r, false, false, false) |
| 599 | |
| 600 | _, bufHosts, bufZones := MakeBuffersForGet() |
| 601 | |
| 602 | // Use the GenerateTokens to get an array of random uint32 values. |
| 603 | testValues := gen.GenerateTokens(testCount, nil) |
| 604 | |
| 605 | for i := 0; i < testCount; i++ { |
| 606 | set, err := ring.Get(testValues[i], Write, instancesList, bufHosts, bufZones) |
nothing calls this directly
no test coverage detected