(t *testing.T)
| 1094 | } |
| 1095 | |
| 1096 | func TestPartitionRingDesc_RemoveTombstones(t *testing.T) { |
| 1097 | now := time.Now() |
| 1098 | |
| 1099 | createTestRing := func() *PartitionRingDesc { |
| 1100 | desc := NewPartitionRingDesc() |
| 1101 | desc.AddPartition(1, PartitionActive, now.Add(1*time.Second)) |
| 1102 | desc.AddPartition(2, PartitionInactive, now.Add(2*time.Second)) |
| 1103 | desc.AddPartition(3, PartitionDeleted, now.Add(3*time.Second)) |
| 1104 | desc.AddOrUpdateOwner("owner-1", OwnerActive, 1, now.Add(4*time.Second)) |
| 1105 | desc.AddOrUpdateOwner("owner-2", OwnerActive, 2, now.Add(4*time.Second)) |
| 1106 | desc.AddOrUpdateOwner("owner-3", OwnerDeleted, 3, now.Add(4*time.Second)) |
| 1107 | return desc |
| 1108 | } |
| 1109 | |
| 1110 | t.Run("should remove all tombstones when limit is zero value", func(t *testing.T) { |
| 1111 | desc := createTestRing() |
| 1112 | total, removed := desc.RemoveTombstones(time.Time{}) |
| 1113 | assert.Equal(t, 0, total) |
| 1114 | assert.Equal(t, 2, removed) |
| 1115 | assert.False(t, desc.HasPartition(3)) |
| 1116 | assert.False(t, desc.HasOwner("owner-3")) |
| 1117 | }) |
| 1118 | |
| 1119 | t.Run("should remove tombstones older or equal to the limit when specified", func(t *testing.T) { |
| 1120 | desc := createTestRing() |
| 1121 | |
| 1122 | total, removed := desc.RemoveTombstones(now) |
| 1123 | assert.Equal(t, 2, total) |
| 1124 | assert.Equal(t, 0, removed) |
| 1125 | assert.True(t, desc.HasPartition(3)) |
| 1126 | assert.True(t, desc.HasOwner("owner-3")) |
| 1127 | |
| 1128 | total, removed = desc.RemoveTombstones(now.Add(3 * time.Second)) |
| 1129 | assert.Equal(t, 1, total) |
| 1130 | assert.Equal(t, 1, removed) |
| 1131 | assert.False(t, desc.HasPartition(3)) |
| 1132 | assert.True(t, desc.HasOwner("owner-3")) |
| 1133 | |
| 1134 | total, removed = desc.RemoveTombstones(now.Add(4 * time.Second)) |
| 1135 | assert.Equal(t, 0, total) |
| 1136 | assert.Equal(t, 1, removed) |
| 1137 | assert.False(t, desc.HasPartition(3)) |
| 1138 | assert.False(t, desc.HasOwner("owner-3")) |
| 1139 | }) |
| 1140 | } |
| 1141 | |
| 1142 | func TestPartitionRingDesc_UpdatePartitionState(t *testing.T) { |
| 1143 | now := time.Now() |
nothing calls this directly
no test coverage detected