|
22 | 22 | import java.util.ArrayList; |
23 | 23 | import java.util.Arrays; |
24 | 24 | import java.util.Collection; |
| 25 | +import java.util.Collections; |
25 | 26 | import java.util.Comparator; |
26 | 27 | import java.util.HashMap; |
27 | 28 | import java.util.HashSet; |
|
42 | 43 | import com.google.common.collect.ImmutableSet; |
43 | 44 | import com.google.common.collect.Iterables; |
44 | 45 | import com.google.common.collect.Sets; |
| 46 | + |
45 | 47 | import org.junit.Assert; |
46 | 48 | import org.junit.After; |
47 | 49 | import org.junit.Before; |
|
72 | 74 | import org.mockito.Mockito; |
73 | 75 |
|
74 | 76 | import static org.assertj.core.api.Assertions.assertThat; |
| 77 | + |
75 | 78 | import static org.junit.Assert.assertEquals; |
76 | 79 | import static org.junit.Assert.assertFalse; |
77 | 80 | import static org.junit.Assert.assertNotEquals; |
78 | 81 | import static org.junit.Assert.assertNotNull; |
79 | 82 | import static org.junit.Assert.assertNull; |
80 | 83 | import static org.junit.Assert.assertSame; |
81 | 84 | import static org.junit.Assert.assertTrue; |
| 85 | + |
82 | 86 | import static org.mockito.ArgumentMatchers.any; |
83 | 87 | import static org.mockito.ArgumentMatchers.anyDouble; |
84 | 88 | import static org.mockito.ArgumentMatchers.anyInt; |
@@ -2209,4 +2213,47 @@ public void testGetLevel() |
2209 | 2213 | assertEquals(0.25d, level.min, 0); |
2210 | 2214 | assertEquals(0.5d, level.max, 0); |
2211 | 2215 | } |
| 2216 | + |
| 2217 | + @Test |
| 2218 | + public void testSkippedAggregatesOnInsufficientDiskSpace() |
| 2219 | + { |
| 2220 | + long overheadSizeInBytes = 1000L; |
| 2221 | + long insufficientSpaceAvailable = 500L; |
| 2222 | + |
| 2223 | + BackgroundCompactions backgroundCompactions = Mockito.mock(BackgroundCompactions.class); |
| 2224 | + Controller controller = Mockito.mock(Controller.class, Mockito.withSettings().stubOnly()); |
| 2225 | + |
| 2226 | + when(controller.prioritize(anyList())).thenCallRealMethod(); |
| 2227 | + when(controller.getReservedThreads()).thenReturn(0); |
| 2228 | + when(controller.getReservationsType()).thenReturn(Reservations.Type.PER_LEVEL); |
| 2229 | + when(controller.getOverheadSizeInBytes(any(), anyLong())).thenReturn(overheadSizeInBytes); |
| 2230 | + when(controller.isRecentAdaptive(any())).thenReturn(false); |
| 2231 | + when(controller.overlapInclusionMethod()).thenReturn(Overlaps.InclusionMethod.TRANSITIVE); |
| 2232 | + when(controller.parallelizeOutputShards()).thenReturn(false); |
| 2233 | + |
| 2234 | + CompactionSSTable mockSSTable = Mockito.mock(CompactionSSTable.class); |
| 2235 | + CompactionPick pick = CompactionPick.create(TimeUUID.Generator.nextTimeUUID(), |
| 2236 | + 0, |
| 2237 | + ImmutableList.of(mockSSTable), |
| 2238 | + Collections.emptySet(), |
| 2239 | + 1, |
| 2240 | + overheadSizeInBytes, |
| 2241 | + overheadSizeInBytes, |
| 2242 | + overheadSizeInBytes); |
| 2243 | + |
| 2244 | + CompactionAggregate.UnifiedAggregate aggregate = Mockito.mock(CompactionAggregate.UnifiedAggregate.class, Mockito.withSettings().stubOnly()); |
| 2245 | + when(aggregate.getSelected()).thenReturn(pick); |
| 2246 | + when(aggregate.maxOverlap()).thenReturn(0); |
| 2247 | + |
| 2248 | + UnifiedCompactionStrategy strategy = new UnifiedCompactionStrategy(strategyFactory, backgroundCompactions, controller); |
| 2249 | + List<CompactionAggregate.UnifiedAggregate> pending = Arrays.asList(aggregate); |
| 2250 | + int[] perLevel = new int[1]; |
| 2251 | + |
| 2252 | + List<CompactionAggregate> result = strategy.getSelection(pending, 1, perLevel, insufficientSpaceAvailable, 0); |
| 2253 | + assertEquals("No compactions should be selected when insufficient disk space", 0, result.size()); |
| 2254 | + Mockito.verify(backgroundCompactions, Mockito.times(1)).incrementSkippedAggregatesDueToDiskSpace(); |
| 2255 | + |
| 2256 | + Mockito.when(backgroundCompactions.getSkippedAggregatesDueToDiskSpace()).thenReturn(1L); |
| 2257 | + assertThat(strategy.getSkippedAggregatesDueToDiskSpace()).isEqualTo(1); |
| 2258 | + } |
2212 | 2259 | } |
0 commit comments