ClassicCompactor implements Compactor { @Nullable public SegmentNodeState compact(@NotNull NodeState state, Canceller canceller) throws IOException { return compact(EMPTY_NODE, state, EMPTY_NODE, canceller); } ClassicCompactor(
            @NotNull SegmentReader reader,
            @NotNull SegmentWriter writer,
            @Nullable BlobStore blobStore,
            @NotNull GCNodeWriteMonitor compactionMonitor); @Nullable SegmentNodeState compact(@NotNull NodeState state, Canceller canceller); @Nullable SegmentNodeState compact(
        @NotNull NodeState before,
        @NotNull NodeState after,
        @NotNull NodeState onto,
        Canceller canceller
    );  }
@Test public void testCompact() throws Exception { ClassicCompactor compactor = createCompactor(fileStore, null); addTestContent(nodeStore); SegmentNodeState uncompacted = (SegmentNodeState) nodeStore.getRoot(); SegmentNodeState compacted = compactor.compact(uncompacted, Canceller.newCanceller()); assertNotNull(compacted); assertFalse(uncompacted == compacted); assertEquals(uncompacted, compacted); assertEquals(uncompacted.getSegment().getGcGeneration().nextFull(), compacted.getSegment().getGcGeneration()); modifyTestContent(nodeStore); NodeState modified = nodeStore.getRoot(); compacted = compactor.compact(uncompacted, modified, compacted, Canceller.newCanceller()); assertNotNull(compacted); assertFalse(modified == compacted); assertEquals(modified, compacted); assertEquals(uncompacted.getSegment().getGcGeneration().nextFull(), compacted.getSegment().getGcGeneration()); }
@Test public void testExceedUpdateLimit() throws Exception { ClassicCompactor compactor = createCompactor(fileStore, null); addNodes(nodeStore, ClassicCompactor.UPDATE_LIMIT * 2 + 1); SegmentNodeState uncompacted = (SegmentNodeState) nodeStore.getRoot(); SegmentNodeState compacted = compactor.compact(uncompacted, Canceller.newCanceller()); assertNotNull(compacted); assertFalse(uncompacted == compacted); assertEquals(uncompacted, compacted); assertEquals(uncompacted.getSegment().getGcGeneration().nextFull(), compacted.getSegment().getGcGeneration()); }
@Test public void testCancel() throws IOException, CommitFailedException { ClassicCompactor compactor = createCompactor(fileStore, null); addTestContent(nodeStore); NodeBuilder builder = nodeStore.getRoot().builder(); builder.setChildNode("cancel").setProperty("cancel", "cancel"); nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); assertNull(compactor.compact(nodeStore.getRoot(), Canceller.newCanceller().withCondition("reason", () -> true))); }
@Test(expected = IOException.class) public void testIOException() throws IOException, CommitFailedException { ClassicCompactor compactor = createCompactor(fileStore, "IOException"); addTestContent(nodeStore); compactor.compact(nodeStore.getRoot(), Canceller.newCanceller()); }