| 184 | } |
| 185 | |
| 186 | func TestPartitionRingDesc_Merge_AddPartition(t *testing.T) { |
| 187 | tests := map[string]struct { |
| 188 | local *PartitionRingDesc |
| 189 | incoming *PartitionRingDesc |
| 190 | expectedUpdatedLocal memberlist.Mergeable |
| 191 | expectedChange memberlist.Mergeable |
| 192 | }{ |
| 193 | "the first partition is added without owners": { |
| 194 | local: &PartitionRingDesc{ |
| 195 | Partitions: map[int32]PartitionDesc{}, |
| 196 | Owners: map[string]OwnerDesc{}, |
| 197 | }, |
| 198 | incoming: &PartitionRingDesc{ |
| 199 | Partitions: map[int32]PartitionDesc{ |
| 200 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 201 | }, |
| 202 | Owners: map[string]OwnerDesc{}, |
| 203 | }, |
| 204 | expectedUpdatedLocal: &PartitionRingDesc{ |
| 205 | Partitions: map[int32]PartitionDesc{ |
| 206 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 207 | }, |
| 208 | Owners: map[string]OwnerDesc{}, |
| 209 | }, |
| 210 | expectedChange: &PartitionRingDesc{ |
| 211 | Partitions: map[int32]PartitionDesc{ |
| 212 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 213 | }, |
| 214 | Owners: map[string]OwnerDesc{}, |
| 215 | }, |
| 216 | }, |
| 217 | "the first partition is added with owners": { |
| 218 | local: &PartitionRingDesc{ |
| 219 | Partitions: map[int32]PartitionDesc{}, |
| 220 | Owners: map[string]OwnerDesc{}, |
| 221 | }, |
| 222 | incoming: &PartitionRingDesc{ |
| 223 | Partitions: map[int32]PartitionDesc{ |
| 224 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 225 | }, |
| 226 | Owners: map[string]OwnerDesc{ |
| 227 | "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, |
| 228 | "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, |
| 229 | }, |
| 230 | }, |
| 231 | expectedUpdatedLocal: &PartitionRingDesc{ |
| 232 | Partitions: map[int32]PartitionDesc{ |
| 233 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 234 | }, |
| 235 | Owners: map[string]OwnerDesc{ |
| 236 | "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, |
| 237 | "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, |
| 238 | }, |
| 239 | }, |
| 240 | expectedChange: &PartitionRingDesc{ |
| 241 | Partitions: map[int32]PartitionDesc{ |
| 242 | 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, |
| 243 | }, |