TieredCompactionStrategy extends CompactionStrategy { @Override public CompactionPlan getCompactionPlan(MajorCompactionRequest request) throws IOException { CompactionPlan plan = null; Iterator<TieredCompactorSupplier> iter = compactors.iterator(); while ((null == plan || plan.inputFiles.isEmpty()) && iter.hasNext()) { CompactionStrategy strategy = iter.next().get(request.getTableProperties()); plan = strategy.getCompactionPlan(request); } return plan; } 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 getCompactionPlanSkipsWhenEmptyInputAndStopsAtTier() throws IOException { CompactionPlan p1 = new CompactionPlan(); p1.inputFiles.add(new FileRef("hdfs: CompactionStrategy c1 = EasyMock.createMock("c1", CompactionStrategy.class); CompactionStrategy c2 = EasyMock.createMock("c2", CompactionStrategy.class); CompactionStrategy c3 = EasyMock.createMock("c3", CompactionStrategy.class); EasyMock.expect(c1.getCompactionPlan(EasyMock.anyObject())).andReturn(new CompactionPlan()); EasyMock.expect(c2.getCompactionPlan(EasyMock.anyObject())).andReturn(p1); EasyMock.replay(c1, c2, c3); TieredCompactionStrategy strategy = newStrategy(c1, c2, c3); CompactionRequestBuilder builder = new CompactionRequestBuilder(); MajorCompactionRequest request = builder.build(); CompactionPlan actualPlan = strategy.getCompactionPlan(request); assertNotNull(actualPlan); assertSame(p1, actualPlan); EasyMock.verify(c1, c2, c3); }
@Test public void getCompactionPlanWillReturnNullIfNonCompact() 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.getCompactionPlan(EasyMock.anyObject())).andReturn(null); EasyMock.expect(c2.getCompactionPlan(EasyMock.anyObject())).andReturn(null); EasyMock.expect(c3.getCompactionPlan(EasyMock.anyObject())).andReturn(null); EasyMock.replay(c1, c2, c3); TieredCompactionStrategy strategy = newStrategy(c1, c2, c3); CompactionRequestBuilder builder = new CompactionRequestBuilder(); MajorCompactionRequest request = builder.build(); CompactionPlan actualPlan = strategy.getCompactionPlan(request); assertNull(actualPlan); EasyMock.verify(c1, c2, c3); }
@Test public void getCompactionPlanSkipsAndStopsAtTier() throws IOException { CompactionPlan p1 = new CompactionPlan(); p1.inputFiles.add(new FileRef("hdfs: CompactionStrategy c1 = EasyMock.createMock("c1", CompactionStrategy.class); CompactionStrategy c2 = EasyMock.createMock("c2", CompactionStrategy.class); CompactionStrategy c3 = EasyMock.createMock("c3", CompactionStrategy.class); EasyMock.expect(c1.getCompactionPlan(EasyMock.anyObject())).andReturn(null); EasyMock.expect(c2.getCompactionPlan(EasyMock.anyObject())).andReturn(p1); EasyMock.replay(c1, c2, c3); TieredCompactionStrategy strategy = newStrategy(c1, c2, c3); CompactionRequestBuilder builder = new CompactionRequestBuilder(); MajorCompactionRequest request = builder.build(); CompactionPlan actualPlan = strategy.getCompactionPlan(request); assertNotNull(actualPlan); assertSame(p1, actualPlan); EasyMock.verify(c1, c2, c3); }