WriteInfoPartitioner { @VisibleForTesting Optional<SweeperStrategy> getStrategy(WriteInfo writeInfo) { return cache.getUnchecked(writeInfo.tableRef()); } WriteInfoPartitioner(KeyValueService kvs, Supplier<Integer> numShards); Map<PartitionInfo, List<WriteInfo>> filterAndPartition(List<WriteInfo> writes);  }
@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); }
@Test public void getStrategyReturnsCorrectStrategy() { assertThat(partitioner.getStrategy(getWriteInfoWithFixedCellHash(NOTHING, 0))).isEmpty(); assertThat(partitioner.getStrategy(getWriteInfoWithFixedCellHash(CONSERVATIVE, 10))) .contains(SweeperStrategy.CONSERVATIVE); assertThat(partitioner.getStrategy(getWriteInfoWithFixedCellHash(THOROUGH, 100))) .contains(SweeperStrategy.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); }