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

Function TestPartitionRingDesc_Merge_RemoveOwner

ring/partition_ring_model_test.go:836–1046  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

834}
835
836func TestPartitionRingDesc_Merge_RemoveOwner(t *testing.T) {
837 now := time.Unix(10000, 0)
838
839 tests := map[string]struct {
840 localCAS bool
841 local *PartitionRingDesc
842 incoming *PartitionRingDesc
843 expectedUpdatedLocal memberlist.Mergeable
844 expectedChange memberlist.Mergeable
845 }{
846 "local change: owner removed and local owner state is not deleted yet": {
847 localCAS: true,
848 local: &PartitionRingDesc{
849 Partitions: map[int32]PartitionDesc{
850 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10},
851 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20},
852 },
853 Owners: map[string]OwnerDesc{
854 "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10},
855 "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20},
856 },
857 },
858 incoming: &PartitionRingDesc{
859 Partitions: map[int32]PartitionDesc{
860 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10},
861 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20},
862 },
863 Owners: map[string]OwnerDesc{
864 "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10},
865 // Owner ingester-zone-a-1 removed.
866 },
867 },
868 expectedUpdatedLocal: &PartitionRingDesc{
869 Partitions: map[int32]PartitionDesc{
870 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10},
871 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20},
872 },
873 Owners: map[string]OwnerDesc{
874 "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10},
875 "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: now.Unix()},
876 },
877 },
878 expectedChange: &PartitionRingDesc{
879 Partitions: map[int32]PartitionDesc{},
880 Owners: map[string]OwnerDesc{
881 "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: now.Unix()},
882 },
883 },
884 },
885 "local change: partition removed and local partition state is already deleted": {
886 localCAS: true,
887 local: &PartitionRingDesc{
888 Partitions: map[int32]PartitionDesc{
889 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10},
890 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20},
891 },
892 Owners: map[string]OwnerDesc{
893 "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10},

Callers

nothing calls this directly

Calls 4

RunMethod · 0.80
CloneMethod · 0.65
mergeWithTimeMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected