CompactorScanner implements InternalScanner { @VisibleForTesting public boolean shouldRetainNonTransactionallyDeletedCell(Cell cell) { return (CellUtil.isDelete(cell) || CellUtil.isDeleteFamily(cell)) && retainNonTransactionallyDeletedCells; } CompactorScanner(ObserverContext<RegionCoprocessorEnvironment> e,
                            InternalScanner internalScanner,
                            Client commitTableClient,
                            boolean isMajorCompaction,
                            boolean preserveNonTransactionallyDeletedCells); @Override boolean next(List<Cell> results); boolean next(List<Cell> result, ScannerContext scannerContext); boolean next(List<Cell> result, int limit); @Override void close(); @VisibleForTesting boolean shouldRetainNonTransactionallyDeletedCell(Cell cell);  }
@Test(dataProvider = "cell-retain-options", timeOut = 60_000) public void testShouldRetainNonTransactionallyDeletedCellMethod(int optionIdx, boolean retainOption) throws Exception { @SuppressWarnings("unchecked") ObserverContext<RegionCoprocessorEnvironment> ctx = mock(ObserverContext.class); InternalScanner internalScanner = mock(InternalScanner.class); CommitTable.Client ctClient = mock(CommitTable.Client.class); RegionCoprocessorEnvironment rce = mock(RegionCoprocessorEnvironment.class); HRegion hRegion = mock(HRegion.class); HRegionInfo hRegionInfo = mock(HRegionInfo.class); SettableFuture<Long> f = SettableFuture.create(); f.set(TEST_TS); when(ctClient.readLowWatermark()).thenReturn(f); when(ctx.getEnvironment()).thenReturn(rce); when(rce.getRegion()).thenReturn(hRegion); when(hRegion.getRegionInfo()).thenReturn(hRegionInfo); LOG.info("Testing when retain is {}", retainOption); try (CompactorScanner scanner = spy(new CompactorScanner(ctx, internalScanner, ctClient, false, retainOption))) { KeyValue regularKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.Put); KeyValue deleteKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.Delete); KeyValue deleteColumnKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.DeleteColumn); KeyValue deleteFamilyKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.DeleteFamily); KeyValue deleteFamilyVersionKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.DeleteFamilyVersion); assertFalse(scanner.shouldRetainNonTransactionallyDeletedCell(regularKV)); assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteKV), retainOption); assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteColumnKV), retainOption); assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteFamilyKV), retainOption); assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteFamilyVersionKV), retainOption); } }