@Test public void testWithReferences() throws Exception { StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create()); StripeCompactor sc = mock(StripeCompactor.class); StoreFile ref = createFile(); when(ref.isReference()).thenReturn(true); StripeInformationProvider si = mock(StripeInformationProvider.class); Collection<StoreFile> sfs = al(ref, createFile()); when(si.getStorefiles()).thenReturn(sfs); assertTrue(policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); assertEquals(si.getStorefiles(), scr.getRequest().getFiles()); scr.execute(sc, NoLimitCompactionThroughputController.INSTANCE, null); verify(sc, only()).compact(eq(scr.getRequest()), anyInt(), anyLong(), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY), any(NoLimitCompactionThroughputController.class), any(User.class)); }
@Test public void testSplitOffStripeDropDeletes() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setInt(StripeStoreConfig.MIN_FILES_KEY, 2); StripeCompactionPolicy policy = createPolicy(conf); Long[] toSplit = new Long[] { defaultSplitSize / 2, defaultSplitSize / 2 }; Long[] noSplit = new Long[] { 1L }; long splitTargetSize = (long)(defaultSplitSize / defaultSplitCount); // Verify the deletes can be dropped if there are no L0 files. StripeCompactionPolicy.StripeInformationProvider si = createStripesWithSizes(0, 0, noSplit, toSplit); verifyWholeStripesCompaction(policy, si, 1, 1, true, null, splitTargetSize); // But cannot be dropped if there are. si = createStripesWithSizes(2, 2, noSplit, toSplit); verifyWholeStripesCompaction(policy, si, 1, 1, false, null, splitTargetSize); }
/** * Verify arbitrary compaction. * @param policy Policy to test. * @param si Stripe information pre-set with stripes to test. * @param sfs Files that should be compacted. * @param dropDeletesFrom Row from which to drop deletes. * @param dropDeletesTo Row to which to drop deletes. * @param boundaries Expected target stripe boundaries. */ private void verifyCompaction(StripeCompactionPolicy policy, StripeInformationProvider si, Collection<StoreFile> sfs, byte[] dropDeletesFrom, byte[] dropDeletesTo, final List<byte[]> boundaries) throws Exception { StripeCompactor sc = mock(StripeCompactor.class); assertTrue(policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); verifyCollectionsEqual(sfs, scr.getRequest().getFiles()); scr.execute(sc, NoLimitCompactionThroughputController.INSTANCE, null); verify(sc, times(1)).compact(eq(scr.getRequest()), argThat(new ArgumentMatcher<List<byte[]>>() { @Override public boolean matches(Object argument) { @SuppressWarnings("unchecked") List<byte[]> other = (List<byte[]>) argument; if (other.size() != boundaries.size()) return false; for (int i = 0; i < other.size(); ++i) { if (!Bytes.equals(other.get(i), boundaries.get(i))) return false; } return true; } }), dropDeletesFrom == null ? isNull(byte[].class) : aryEq(dropDeletesFrom), dropDeletesTo == null ? isNull(byte[].class) : aryEq(dropDeletesTo), any(NoLimitCompactionThroughputController.class), any(User.class)); }
/** Verify arbitrary flush. */ protected void verifyFlush(StripeCompactionPolicy policy, StripeInformationProvider si, KeyValue[] input, KeyValue[][] expected, byte[][] boundaries) throws IOException { StoreFileWritersCapture writers = new StoreFileWritersCapture(); StripeStoreFlusher.StripeFlushRequest req = policy.selectFlush(si, input.length); StripeMultiFileWriter mw = req.createWriter(); mw.init(null, writers, new KeyValue.KVComparator()); for (KeyValue kv : input) { mw.append(kv); } boolean hasMetadata = boundaries != null; mw.commitWriters(0, false); writers.verifyKvs(expected, true, hasMetadata); if (hasMetadata) { writers.verifyBoundaries(boundaries); } }
@Test public void testWithReferences() throws Exception { StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create()); StripeCompactor sc = mock(StripeCompactor.class); StoreFile ref = createFile(); when(ref.isReference()).thenReturn(true); StripeInformationProvider si = mock(StripeInformationProvider.class); Collection<StoreFile> sfs = al(ref, createFile()); when(si.getStorefiles()).thenReturn(sfs); assertTrue(policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); assertEquals(si.getStorefiles(), scr.getRequest().getFiles()); scr.execute(sc); verify(sc, only()).compact(eq(scr.getRequest()), anyInt(), anyLong(), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY)); }
@Test public void testSingleStripeDropDeletes() throws Exception { Configuration conf = HBaseConfiguration.create(); StripeCompactionPolicy policy = createPolicy(conf); // Verify the deletes can be dropped if there are no L0 files. Long[][] stripes = new Long[][] { new Long[] { 3L, 2L, 2L, 2L }, new Long[] { 6L } }; StripeInformationProvider si = createStripesWithSizes(0, 0, stripes); verifySingleStripeCompaction(policy, si, 0, true); // But cannot be dropped if there are. si = createStripesWithSizes(2, 2, stripes); verifySingleStripeCompaction(policy, si, 0, false); // Unless there are enough to cause L0 compaction. si = createStripesWithSizes(6, 2, stripes); ConcatenatedLists<StoreFile> sfs = new ConcatenatedLists<StoreFile>(); sfs.addSublist(si.getLevel0Files()); sfs.addSublist(si.getStripes().get(0)); verifyCompaction( policy, si, sfs, si.getStartRow(0), si.getEndRow(0), si.getStripeBoundaries()); // If we cannot actually compact all files in some stripe, L0 is chosen. si = createStripesWithSizes(6, 2, new Long[][] { new Long[] { 10L, 1L, 1L, 1L, 1L }, new Long[] { 12L } }); verifyCompaction(policy, si, si.getLevel0Files(), null, null, si.getStripeBoundaries()); }
/** * Verify arbitrary compaction. * @param policy Policy to test. * @param si Stripe information pre-set with stripes to test. * @param sfs Files that should be compacted. * @param dropDeletesFrom Row from which to drop deletes. * @param dropDeletesTo Row to which to drop deletes. * @param boundaries Expected target stripe boundaries. */ private void verifyCompaction(StripeCompactionPolicy policy, StripeInformationProvider si, Collection<StoreFile> sfs, byte[] dropDeletesFrom, byte[] dropDeletesTo, final List<byte[]> boundaries) throws Exception { StripeCompactor sc = mock(StripeCompactor.class); assertTrue(policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); verifyCollectionsEqual(sfs, scr.getRequest().getFiles()); scr.execute(sc); verify(sc, times(1)).compact(eq(scr.getRequest()), argThat( new ArgumentMatcher<List<byte[]>>() { @Override public boolean matches(Object argument) { @SuppressWarnings("unchecked") List<byte[]> other = (List<byte[]>)argument; if (other.size() != boundaries.size()) return false; for (int i = 0; i < other.size(); ++i) { if (!Bytes.equals(other.get(i), boundaries.get(i))) return false; } return true; } }), dropDeletesFrom == null ? isNull(byte[].class) : aryEq(dropDeletesFrom), dropDeletesTo == null ? isNull(byte[].class) : aryEq(dropDeletesTo)); }
@Test public void testWithReferences() throws Exception { StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create()); StripeCompactor sc = mock(StripeCompactor.class); HStoreFile ref = createFile(); when(ref.isReference()).thenReturn(true); StripeInformationProvider si = mock(StripeInformationProvider.class); Collection<HStoreFile> sfs = al(ref, createFile()); when(si.getStorefiles()).thenReturn(sfs); assertTrue(policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); // UnmodifiableCollection does not implement equals so we need to change it here to a // collection that implements it. assertEquals(si.getStorefiles(), new ArrayList<>(scr.getRequest().getFiles())); scr.execute(sc, NoLimitThroughputController.INSTANCE, null); verify(sc, only()).compact(eq(scr.getRequest()), anyInt(), anyLong(), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY), any(), any()); }
@Test public void testSplitOffStripeOffPeak() throws Exception { // for HBASE-11439 Configuration conf = HBaseConfiguration.create(); // Test depends on this not being set to pass. Default breaks test. TODO: Revisit. conf.unset("hbase.hstore.compaction.min.size"); conf.setInt(StripeStoreConfig.MIN_FILES_KEY, 2); // Select the last 2 files. StripeCompactionPolicy.StripeInformationProvider si = createStripesWithSizes(0, 0, new Long[] { defaultSplitSize - 2, 1L, 1L }); assertEquals(2, createPolicy(conf).selectCompaction(si, al(), false).getRequest().getFiles() .size()); // Make sure everything is eligible in offpeak. conf.setFloat("hbase.hstore.compaction.ratio.offpeak", 500f); assertEquals(3, createPolicy(conf).selectCompaction(si, al(), true).getRequest().getFiles() .size()); }
/** * Verify arbitrary compaction. * @param policy Policy to test. * @param si Stripe information pre-set with stripes to test. * @param sfs Files that should be compacted. * @param dropDeletesFrom Row from which to drop deletes. * @param dropDeletesTo Row to which to drop deletes. * @param boundaries Expected target stripe boundaries. */ private void verifyCompaction(StripeCompactionPolicy policy, StripeInformationProvider si, Collection<HStoreFile> sfs, byte[] dropDeletesFrom, byte[] dropDeletesTo, final List<byte[]> boundaries) throws Exception { StripeCompactor sc = mock(StripeCompactor.class); assertTrue(policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); verifyCollectionsEqual(sfs, scr.getRequest().getFiles()); scr.execute(sc, NoLimitThroughputController.INSTANCE, null); verify(sc, times(1)).compact(eq(scr.getRequest()), argThat(new ArgumentMatcher<List<byte[]>>() { @Override public boolean matches(List<byte[]> argument) { List<byte[]> other = argument; if (other.size() != boundaries.size()) return false; for (int i = 0; i < other.size(); ++i) { if (!Bytes.equals(other.get(i), boundaries.get(i))) return false; } return true; } }), dropDeletesFrom == null ? isNull(byte[].class) : aryEq(dropDeletesFrom), dropDeletesTo == null ? isNull(byte[].class) : aryEq(dropDeletesTo), any(), any()); }
/** Verify arbitrary flush. */ protected void verifyFlush(StripeCompactionPolicy policy, StripeInformationProvider si, KeyValue[] input, KeyValue[][] expected, byte[][] boundaries) throws IOException { StoreFileWritersCapture writers = new StoreFileWritersCapture(); StripeStoreFlusher.StripeFlushRequest req = policy.selectFlush(CellComparatorImpl.COMPARATOR, si, input.length); StripeMultiFileWriter mw = req.createWriter(); mw.init(null, writers); for (KeyValue kv : input) { mw.append(kv); } boolean hasMetadata = boundaries != null; mw.commitWriters(0, false); writers.verifyKvs(expected, true, hasMetadata); if (hasMetadata) { writers.verifyBoundaries(boundaries); } }
@Test public void testNoStripesFromFlush() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setBoolean(StripeStoreConfig.FLUSH_TO_L0_KEY, true); StripeCompactionPolicy policy = createPolicy(conf); StripeInformationProvider si = createStripesL0Only(0, 0); KeyValue[] input = new KeyValue[] { KV_A, KV_B, KV_C, KV_D, KV_E }; KeyValue[][] expected = new KeyValue[][] { input }; verifyFlush(policy, si, input, expected, null); }
@Test public void testOldStripesFromFlush() throws Exception { StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create()); StripeInformationProvider si = createStripes(0, KEY_C, KEY_D); KeyValue[] input = new KeyValue[] { KV_B, KV_C, KV_C, KV_D, KV_E }; KeyValue[][] expected = new KeyValue[][] { new KeyValue[] { KV_B }, new KeyValue[] { KV_C, KV_C }, new KeyValue[] { KV_D, KV_E } }; verifyFlush(policy, si, input, expected, new byte[][] { OPEN_KEY, KEY_C, KEY_D, OPEN_KEY }); }
@Test public void testNewStripesFromFlush() throws Exception { StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create()); StripeInformationProvider si = createStripesL0Only(0, 0); KeyValue[] input = new KeyValue[] { KV_B, KV_C, KV_C, KV_D, KV_E }; // Starts with one stripe; unlike flush results, must have metadata KeyValue[][] expected = new KeyValue[][] { input }; verifyFlush(policy, si, input, expected, new byte[][] { OPEN_KEY, OPEN_KEY }); }
@Test public void testWithParallelCompaction() throws Exception { // TODO: currently only one compaction at a time per store is allowed. If this changes, // the appropriate file exclusion testing would need to be done in respective tests. assertNull(createPolicy(HBaseConfiguration.create()).selectCompaction( mock(StripeInformationProvider.class), al(createFile()), false)); }
@Test public void testInitialCountFromL0() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setInt(StripeStoreConfig.MIN_FILES_L0_KEY, 2); StripeCompactionPolicy policy = createPolicy( conf, defaultSplitSize, defaultSplitCount, 2, false); StripeCompactionPolicy.StripeInformationProvider si = createStripesL0Only(3, 8); verifyCompaction(policy, si, si.getStorefiles(), true, 2, 12L, OPEN_KEY, OPEN_KEY, true); si = createStripesL0Only(3, 10); // If result would be too large, split into smaller parts. verifyCompaction(policy, si, si.getStorefiles(), true, 3, 10L, OPEN_KEY, OPEN_KEY, true); policy = createPolicy(conf, defaultSplitSize, defaultSplitCount, 6, false); verifyCompaction(policy, si, si.getStorefiles(), true, 6, 5L, OPEN_KEY, OPEN_KEY, true); }
@Test public void testExistingStripesFromL0() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setInt(StripeStoreConfig.MIN_FILES_L0_KEY, 3); StripeCompactionPolicy.StripeInformationProvider si = createStripes(3, KEY_A); verifyCompaction( createPolicy(conf), si, si.getLevel0Files(), null, null, si.getStripeBoundaries()); }
@Test public void testNothingToCompactFromL0() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setInt(StripeStoreConfig.MIN_FILES_L0_KEY, 4); StripeCompactionPolicy.StripeInformationProvider si = createStripesL0Only(3, 10); StripeCompactionPolicy policy = createPolicy(conf); verifyNoCompaction(policy, si); si = createStripes(3, KEY_A); verifyNoCompaction(policy, si); }
@Test public void testSplitOffStripe() throws Exception { Configuration conf = HBaseConfiguration.create(); // First test everything with default split count of 2, then split into more. conf.setInt(StripeStoreConfig.MIN_FILES_KEY, 2); Long[] toSplit = new Long[] { defaultSplitSize - 2, 1L, 1L }; Long[] noSplit = new Long[] { defaultSplitSize - 2, 1L }; long splitTargetSize = (long)(defaultSplitSize / defaultSplitCount); // Don't split if not eligible for compaction. StripeCompactionPolicy.StripeInformationProvider si = createStripesWithSizes(0, 0, new Long[] { defaultSplitSize - 2, 2L }); assertNull(createPolicy(conf).selectCompaction(si, al(), false)); // Make sure everything is eligible. conf.setFloat(CompactionConfiguration.HBASE_HSTORE_COMPACTION_RATIO_KEY, 500f); StripeCompactionPolicy policy = createPolicy(conf); verifyWholeStripesCompaction(policy, si, 0, 0, null, 2, splitTargetSize); // Add some extra stripes... si = createStripesWithSizes(0, 0, noSplit, noSplit, toSplit); verifyWholeStripesCompaction(policy, si, 2, 2, null, 2, splitTargetSize); // In the middle. si = createStripesWithSizes(0, 0, noSplit, toSplit, noSplit); verifyWholeStripesCompaction(policy, si, 1, 1, null, 2, splitTargetSize); // No split-off with different config (larger split size). // However, in this case some eligible stripe will just be compacted alone. StripeCompactionPolicy specPolicy = createPolicy( conf, defaultSplitSize + 1, defaultSplitCount, defaultInitialCount, false); verifySingleStripeCompaction(specPolicy, si, 1, null); }
@Test public void testSplitOffStripeOffPeak() throws Exception { // for HBASE-11439 Configuration conf = HBaseConfiguration.create(); conf.setInt(StripeStoreConfig.MIN_FILES_KEY, 2); // Select the last 2 files. StripeCompactionPolicy.StripeInformationProvider si = createStripesWithSizes(0, 0, new Long[] { defaultSplitSize - 2, 1L, 1L }); assertEquals(2, createPolicy(conf).selectCompaction(si, al(), false).getRequest().getFiles() .size()); // Make sure everything is eligible in offpeak. conf.setFloat("hbase.hstore.compaction.ratio.offpeak", 500f); assertEquals(3, createPolicy(conf).selectCompaction(si, al(), true).getRequest().getFiles() .size()); }
@SuppressWarnings("unchecked") @Test public void testMergeExpiredFiles() throws Exception { ManualEnvironmentEdge edge = new ManualEnvironmentEdge(); long now = defaultTtl + 2; edge.setValue(now); EnvironmentEdgeManager.injectEdge(edge); try { StoreFile expiredFile = createFile(), notExpiredFile = createFile(); when(expiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl - 1); when(notExpiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl + 1); List<StoreFile> expired = Lists.newArrayList(expiredFile, expiredFile); List<StoreFile> notExpired = Lists.newArrayList(notExpiredFile, notExpiredFile); List<StoreFile> mixed = Lists.newArrayList(expiredFile, notExpiredFile); StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create(), defaultSplitSize, defaultSplitCount, defaultInitialCount, true); // Merge expired if there are eligible stripes. StripeCompactionPolicy.StripeInformationProvider si = createStripesWithFiles(expired, expired, expired); verifyWholeStripesCompaction(policy, si, 0, 2, null, 1, Long.MAX_VALUE, false); // Don't merge if nothing expired. si = createStripesWithFiles(notExpired, notExpired, notExpired); assertNull(policy.selectCompaction(si, al(), false)); // Merge one expired stripe with next. si = createStripesWithFiles(notExpired, expired, notExpired); verifyWholeStripesCompaction(policy, si, 1, 2, null, 1, Long.MAX_VALUE, false); // Merge the biggest run out of multiple options. // Merge one expired stripe with next. si = createStripesWithFiles(notExpired, expired, notExpired, expired, expired, notExpired); verifyWholeStripesCompaction(policy, si, 3, 4, null, 1, Long.MAX_VALUE, false); // Stripe with a subset of expired files is not merged. si = createStripesWithFiles(expired, expired, notExpired, expired, mixed); verifyWholeStripesCompaction(policy, si, 0, 1, null, 1, Long.MAX_VALUE, false); } finally { EnvironmentEdgeManager.reset(); } }
@SuppressWarnings("unchecked") @Test public void testMergeExpiredStripes() throws Exception { // HBASE-11397 ManualEnvironmentEdge edge = new ManualEnvironmentEdge(); long now = defaultTtl + 2; edge.setValue(now); EnvironmentEdgeManager.injectEdge(edge); try { StoreFile expiredFile = createFile(), notExpiredFile = createFile(); when(expiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl - 1); when(notExpiredFile.getReader().getMaxTimestamp()).thenReturn(now - defaultTtl + 1); List<StoreFile> expired = Lists.newArrayList(expiredFile, expiredFile); List<StoreFile> notExpired = Lists.newArrayList(notExpiredFile, notExpiredFile); StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create(), defaultSplitSize, defaultSplitCount, defaultInitialCount, true); // Merge all three expired stripes into one. StripeCompactionPolicy.StripeInformationProvider si = createStripesWithFiles(expired, expired, expired); verifyMergeCompatcion(policy, si, 0, 2); // Merge two adjacent expired stripes into one. si = createStripesWithFiles(notExpired, expired, notExpired, expired, expired, notExpired); verifyMergeCompatcion(policy, si, 3, 4); } finally { EnvironmentEdgeManager.reset(); } }
@Test public void testSingleStripeDropDeletes() throws Exception { Configuration conf = HBaseConfiguration.create(); StripeCompactionPolicy policy = createPolicy(conf); // Verify the deletes can be dropped if there are no L0 files. Long[][] stripes = new Long[][] { new Long[] { 3L, 2L, 2L, 2L }, new Long[] { 6L } }; StripeInformationProvider si = createStripesWithSizes(0, 0, stripes); verifySingleStripeCompaction(policy, si, 0, true); // But cannot be dropped if there are. si = createStripesWithSizes(2, 2, stripes); verifySingleStripeCompaction(policy, si, 0, false); // Unless there are enough to cause L0 compaction. si = createStripesWithSizes(6, 2, stripes); ConcatenatedLists<StoreFile> sfs = new ConcatenatedLists<StoreFile>(); sfs.addSublist(si.getLevel0Files()); sfs.addSublist(si.getStripes().get(0)); verifyCompaction( policy, si, sfs, si.getStartRow(0), si.getEndRow(0), si.getStripeBoundaries()); // If we cannot actually compact all files in some stripe, L0 is chosen. si = createStripesWithSizes(6, 2, new Long[][] { new Long[] { 10L, 1L, 1L, 1L, 1L }, new Long[] { 12L } }); verifyCompaction(policy, si, si.getLevel0Files(), null, null, si.getStripeBoundaries()); // even if L0 has no file // if all files of stripe aren't selected, delete must not be dropped. stripes = new Long[][] { new Long[] { 100L, 3L, 2L, 2L, 2L }, new Long[] { 6L } }; si = createStripesWithSizes(0, 0, stripes); List<StoreFile> compact_file = new ArrayList<StoreFile>(); Iterator<StoreFile> iter = si.getStripes().get(0).listIterator(1); while (iter.hasNext()) { compact_file.add(iter.next()); } verifyCompaction(policy, si, compact_file, false, 1, null, si.getStartRow(0), si.getEndRow(0), true); }
private void verifyMergeCompatcion(StripeCompactionPolicy policy, StripeInformationProvider si, int from, int to) throws Exception { StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); Collection<StoreFile> sfs = getAllFiles(si, from, to); verifyCollectionsEqual(sfs, scr.getRequest().getFiles()); // All the Stripes are expired, so the Compactor will not create any Writers. We need to create // an empty file to preserve metadata StripeCompactor sc = createCompactor(); List<Path> paths = scr.execute(sc, NoLimitCompactionThroughputController.INSTANCE, null); assertEquals(1, paths.size()); }
/** * Verify arbitrary compaction. * @param policy Policy to test. * @param si Stripe information pre-set with stripes to test. * @param sfs Files that should be compacted. * @param dropDeletes Whether to drop deletes from compaction range. * @param count Expected # of resulting stripes, null if not checked. * @param size Expected target stripe size, null if not checked. * @param start Left boundary of the compaction. * @param righr Right boundary of the compaction. */ private void verifyCompaction(StripeCompactionPolicy policy, StripeInformationProvider si, Collection<StoreFile> sfs, Boolean dropDeletes, Integer count, Long size, byte[] start, byte[] end, boolean needsCompaction) throws IOException { StripeCompactor sc = mock(StripeCompactor.class); assertTrue(!needsCompaction || policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); verifyCollectionsEqual(sfs, scr.getRequest().getFiles()); scr.execute(sc, NoLimitCompactionThroughputController.INSTANCE, null); verify(sc, times(1)).compact(eq(scr.getRequest()), count == null ? anyInt() : eq(count.intValue()), size == null ? anyLong() : eq(size.longValue()), aryEq(start), aryEq(end), dropDeletesMatcher(dropDeletes, start), dropDeletesMatcher(dropDeletes, end), any(NoLimitCompactionThroughputController.class), any(User.class)); }
private static List<StoreFile> getAllFiles( StripeInformationProvider si, int fromStripe, int toStripe) { ArrayList<StoreFile> expected = new ArrayList<StoreFile>(); for (int i = fromStripe; i <= toStripe; ++i) { expected.addAll(si.getStripes().get(i)); } return expected; }
/** * @param l0Count Number of L0 files. * @param boundaries Target boundaries. * @return Mock stripes. */ private static StripeInformationProvider createStripes( int l0Count, byte[]... boundaries) throws Exception { List<Long> l0Sizes = new ArrayList<Long>(); for (int i = 0; i < l0Count; ++i) { l0Sizes.add(5L); } List<List<Long>> sizes = new ArrayList<List<Long>>(); for (int i = 0; i <= boundaries.length; ++i) { sizes.add(Arrays.asList(Long.valueOf(5))); } return createStripes(Arrays.asList(boundaries), sizes, l0Sizes); }