private boolean isConservative(WriteInfo write) { return getStrategy(write) == TableMetadataPersistence.SweepStrategy.CONSERVATIVE; } }
@VisibleForTesting List<WriteInfo> filterOutUnsweepableTables(List<WriteInfo> writes) { return writes.stream() .filter(writeInfo -> getStrategy(writeInfo) != TableMetadataPersistence.SweepStrategy.NOTHING) .collect(Collectors.toList()); }
@Test public void getStrategyReturnsCorrectStrategy() { assertThat(partitioner.getStrategy(getWriteInfoWithFixedCellHash(NOTHING, 0))) .isEqualTo(TableMetadataPersistence.SweepStrategy.NOTHING); assertThat(partitioner.getStrategy(getWriteInfoWithFixedCellHash(CONSERVATIVE, 10))) .isEqualTo(TableMetadataPersistence.SweepStrategy.CONSERVATIVE); assertThat(partitioner.getStrategy(getWriteInfoWithFixedCellHash(THOROUGH, 100))) .isEqualTo(TableMetadataPersistence.SweepStrategy.THOROUGH); }
@Test public void getStrategyQueriesKvsOnlyOnceForEachTable() { for (int i = 0; i < 5; i++) { partitioner.getStrategy(getWriteInfoWithFixedCellHash(NOTHING, i)); partitioner.getStrategy(getWriteInfoWithFixedCellHash(CONSERVATIVE, i)); } verify(mockKvs, times(1)).getMetadataForTable(NOTHING); verify(mockKvs, times(1)).getMetadataForTable(CONSERVATIVE); verifyNoMoreInteractions(mockKvs); }
@Test public void getStrategyThrowsForIllegalMetadata() { when(mockKvs.getMetadataForTable(any())).thenReturn(AtlasDbConstants.EMPTY_TABLE_METADATA); assertThatThrownBy(() -> partitioner.getStrategy(getWriteInfoWithFixedCellHash(getTableRef("a"), 0))) .isInstanceOf(UncheckedExecutionException.class); }
@Test public void getStrategyThrowsOnUncheckedException() { RuntimeException cause = new RuntimeException("cause"); when(mockKvs.getMetadataForTable(any())).thenThrow(cause); assertThatThrownBy(() -> partitioner.getStrategy(getWriteInfoWithFixedCellHash(getTableRef("a"), 0))) .isInstanceOf(UncheckedExecutionException.class) .hasCause(cause); }
private boolean isConservative(WriteInfo write) { return getStrategy(write) == TableMetadataPersistence.SweepStrategy.CONSERVATIVE; } }
@VisibleForTesting List<WriteInfo> filterOutUnsweepableTables(List<WriteInfo> writes) { return writes.stream() .filter(writeInfo -> getStrategy(writeInfo) != TableMetadataPersistence.SweepStrategy.NOTHING) .collect(Collectors.toList()); }