| 742 | } |
| 743 | |
| 744 | func TestPartitionRingDesc_Merge_AddOwner(t *testing.T) { |
| 745 | tests := map[string]struct { |
| 746 | local *PartitionRingDesc |
| 747 | incoming *PartitionRingDesc |
| 748 | expectedUpdatedLocal memberlist.Mergeable |
| 749 | expectedChange memberlist.Mergeable |
| 750 | }{ |
| 751 | "add the first owner to a partition": { |
| 752 | local: &PartitionRingDesc{ |
| 753 | Partitions: map[int32]PartitionDesc{ |
| 754 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 755 | }, |
| 756 | Owners: map[string]OwnerDesc{}, |
| 757 | }, |
| 758 | incoming: &PartitionRingDesc{ |
| 759 | Partitions: map[int32]PartitionDesc{ |
| 760 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 761 | }, |
| 762 | Owners: map[string]OwnerDesc{ |
| 763 | "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, |
| 764 | }, |
| 765 | }, |
| 766 | expectedUpdatedLocal: &PartitionRingDesc{ |
| 767 | Partitions: map[int32]PartitionDesc{ |
| 768 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 769 | }, |
| 770 | Owners: map[string]OwnerDesc{ |
| 771 | "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, |
| 772 | }, |
| 773 | }, |
| 774 | expectedChange: &PartitionRingDesc{ |
| 775 | Partitions: map[int32]PartitionDesc{}, |
| 776 | Owners: map[string]OwnerDesc{ |
| 777 | "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, |
| 778 | }, |
| 779 | }, |
| 780 | }, |
| 781 | "add the second owner to a partition": { |
| 782 | local: &PartitionRingDesc{ |
| 783 | Partitions: map[int32]PartitionDesc{ |
| 784 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 785 | }, |
| 786 | Owners: map[string]OwnerDesc{ |
| 787 | "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, |
| 788 | }, |
| 789 | }, |
| 790 | incoming: &PartitionRingDesc{ |
| 791 | Partitions: map[int32]PartitionDesc{ |
| 792 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 793 | }, |
| 794 | Owners: map[string]OwnerDesc{ |
| 795 | "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, |
| 796 | "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 20}, |
| 797 | }, |
| 798 | }, |
| 799 | expectedUpdatedLocal: &PartitionRingDesc{ |
| 800 | Partitions: map[int32]PartitionDesc{ |
| 801 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |