TieredCompactionStrategy extends CompactionStrategy { @Override public boolean shouldCompact(MajorCompactionRequest request) throws IOException { boolean shouldCompact = false; for (TieredCompactorSupplier supplier : compactors) { CompactionStrategy strategy = supplier.get(request.getTableProperties()); shouldCompact = strategy.shouldCompact(request); if (shouldCompact) { break; } } return shouldCompact; } TieredCompactionStrategy(); Collection<TieredCompactorSupplier> getCompactors(); @Override void init(Map<String, String> config); @Override void gatherInformation(MajorCompactionRequest request); @Override boolean shouldCompact(MajorCompactionRequest request); @Override CompactionPlan getCompactionPlan(MajorCompactionRequest request); static final String TIERED_PREFIX; static final String TIERED_CLASS; static final String TIERED_OPTS; }
@Test public void shouldCompactStopsAtTier() throws IOException { CompactionStrategy c1 = EasyMock.createMock("c1", CompactionStrategy.class); CompactionStrategy c2 = EasyMock.createMock("c2", CompactionStrategy.class); CompactionStrategy c3 = EasyMock.createMock("c3", CompactionStrategy.class); EasyMock.expect(c1.shouldCompact(EasyMock.anyObject())).andReturn(false); EasyMock.expect(c2.shouldCompact(EasyMock.anyObject())).andReturn(true); EasyMock.replay(c1, c2, c3); TieredCompactionStrategy strategy = newStrategy(c1, c2, c3); CompactionRequestBuilder builder = new CompactionRequestBuilder(); MajorCompactionRequest request = builder.build(); boolean result = strategy.shouldCompact(request); assertTrue(result); EasyMock.verify(c1, c2, c3); }
@Test public void shouldCompactWithSingleTier() throws Exception { CompactionStrategy c1 = EasyMock.createMock("c1", CompactionStrategy.class); EasyMock.expect(c1.shouldCompact(EasyMock.anyObject())).andReturn(false); EasyMock.replay(c1); TieredCompactionStrategy strategy = newStrategy(c1); CompactionRequestBuilder builder = new CompactionRequestBuilder(); MajorCompactionRequest request = builder.build(); boolean result = strategy.shouldCompact(request); assertFalse(result); EasyMock.verify(c1); }