@Test public void executeLargeUpdates() { List<Integer> inputs = newArrayList(); for (int i = 0; i < 2010; i++) { inputs.add(i); } List<Integer> processed = newArrayList(); DatabaseUtils.executeLargeUpdates(inputs, input -> { assertThat(input.size()).isLessThanOrEqualTo(1000); processed.addAll(input); }); assertThat(processed).containsExactlyElementsOf(inputs); }
@Test public void executeLargeInputs() { List<Integer> inputs = newArrayList(); List<String> expectedOutputs = newArrayList(); for (int i = 0; i < 2010; i++) { inputs.add(i); expectedOutputs.add(Integer.toString(i)); } List<String> outputs = DatabaseUtils.executeLargeInputs(inputs, input -> { // Check that each partition is only done on 1000 elements max assertThat(input.size()).isLessThanOrEqualTo(1000); return input.stream().map(String::valueOf).collect(MoreCollectors.toList()); }); assertThat(outputs).isEqualTo(expectedOutputs); }
@Test public void childExecutorService() { executorServiceRule.submit(() -> { executorService = Executors.newCachedThreadPool(); executorService.submit(() -> terminateLatch.await(TIMEOUT_MILLIS, MILLISECONDS)); executorService.submit(() -> terminateLatch.await(TIMEOUT_MILLIS, MILLISECONDS)); submittedChildren.set(true); }); await().untilTrue(submittedChildren); assertThat(executorServiceRule.getThreads().size()).isLessThanOrEqualTo(1); }
private void upperBoundGivesNonMeaningfulScore(Integer ref, double ratio) { int upperBound = (int) Math.ceil(ref * ratio); assertThat(underTest.score(listOf(ref), listOf(upperBound))) .describedAs("Score for %s%% lines of %s (ie. %s lines) should be 84 or less", ratio * 100, ref, upperBound) .isLessThanOrEqualTo(84); }
private void lowerBoundGivesNonMeaningfulScore(Integer ref, double ratio) { int lowerBound = (int) Math.floor(ref * ratio); assertThat(underTest.score(listOf(ref), listOf(lowerBound))) .describedAs("Score for %s%% lines of %s (ie. %s lines) should be 84 or less", ratio * 100, ref, lowerBound) .isLessThanOrEqualTo(84); }
@Test public void findAvailablePidShouldReturnLessThanOrEqualToUpperBound() throws Exception { availablePid = new AvailablePid(new AvailablePid.Bounds(1, 10)); Stopwatch stopwatch = Stopwatch.createStarted(); do { assertThat(availablePid.findAvailablePid()).isLessThanOrEqualTo(10); } while (stopwatch.elapsed(SECONDS) < 2); }
@Test(timeout = 50000) public void testSweepBatchesInDifferentRows() { CellsSweeper cellsSweeper = Mockito.mock(CellsSweeper.class); SweepTaskRunner spiedSweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper); putTwoValuesInEachCell(BIG_LIST_OF_CELLS_IN_DIFFERENT_ROWS); int deleteBatchSize = 2; Pair<List<List<Cell>>, SweepResults> sweptCellsAndSweepResults = runSweep(cellsSweeper, spiedSweepRunner, 10, 1, deleteBatchSize); List<List<Cell>> sweptCells = sweptCellsAndSweepResults.getLhSide(); SweepResults sweepResults = sweptCellsAndSweepResults.getRhSide(); assertThat(Iterables.concat(sweptCells)).containsExactlyElementsOf(BIG_LIST_OF_CELLS_IN_DIFFERENT_ROWS); for (List<Cell> sweptBatch : sweptCells.subList(0, sweptCells.size() - 1)) { // We requested deleteBatchSize = 2, so we expect between 2 and 4 timestamps deleted at a time. // We also expect a single timestamp to be swept per each cell. assertThat(sweptBatch.size()).isBetween(deleteBatchSize, 2 * deleteBatchSize); } // The last batch can be smaller than deleteBatchSize assertThat(sweptCells.get(sweptCells.size() - 1).size()).isLessThanOrEqualTo(2 * deleteBatchSize); assertEquals("Expected Ts Pairs Examined should add up to entire table (2 values in each cell)", 2 * BIG_LIST_OF_CELLS_IN_DIFFERENT_ROWS.size(), sweepResults.getCellTsPairsExamined()); }
@Test(timeout = 50000) public void testSweepBatches() { CellsSweeper cellsSweeper = Mockito.mock(CellsSweeper.class); SweepTaskRunner spiedSweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper); putTwoValuesInEachCell(BIG_LIST_OF_CELLS); int deleteBatchSize = 2; Pair<List<List<Cell>>, SweepResults> sweptCellsAndSweepResults = runSweep(cellsSweeper, spiedSweepRunner, 1000, 1, deleteBatchSize); List<List<Cell>> sweptCells = sweptCellsAndSweepResults.getLhSide(); SweepResults sweepResults = sweptCellsAndSweepResults.getRhSide(); assertThat(Iterables.concat(sweptCells)).containsExactlyElementsOf(BIG_LIST_OF_CELLS); for (List<Cell> sweptBatch : sweptCells.subList(0, sweptCells.size() - 1)) { // We requested deleteBatchSize = 2, so we expect between 2 and 4 timestamps deleted at a time. // We also expect a single timestamp to be swept per each cell. assertThat(sweptBatch.size()).isBetween(deleteBatchSize, 2 * deleteBatchSize); } // The last batch can be smaller than deleteBatchSize assertThat(sweptCells.get(sweptCells.size() - 1).size()).isLessThanOrEqualTo(2 * deleteBatchSize); assertEquals("Expected Ts Pairs Examined should add up to entire table (2 values in each cell)", 2 * BIG_LIST_OF_CELLS.size(), sweepResults.getCellTsPairsExamined()); }
@Test public void canRequestTimestampRangeWithGetFreshTimestamps() { int expectedNumTimestamps = 5; TimestampRange range = timestampService.getFreshTimestamps(expectedNumTimestamps); Assertions.assertThat((int) range.size()) .withFailMessage("Expected %d timestamps, got %d timestamps. (The returned range was: %d-%d)", expectedNumTimestamps, range.size(), range.getLowerBound(), range.getUpperBound()) .isGreaterThanOrEqualTo(1) .isLessThanOrEqualTo(expectedNumTimestamps); }
DocumentList posts = db.getPublishedPosts(true); assertThat(posts.size()).isLessThanOrEqualTo(2);
assertThat(openChannels.size()) .as("Number of open connections does not meet expected: %s", openChannels) .isLessThanOrEqualTo(maxConnections);
@Override protected void assertPartialResultMatchesExpectation( final List<BytesValue> requestedData, final List<BytesValue> partialResponse) { assertThat(partialResponse.size()).isLessThanOrEqualTo(requestedData.size()); assertThat(partialResponse.size()).isGreaterThan(0); assertThat(requestedData).containsAll(partialResponse); }
@Override protected void assertPartialResultMatchesExpectation( final List<BlockHeader> requestedData, final List<BlockHeader> partialResponse) { assertThat(partialResponse.size()).isLessThanOrEqualTo(requestedData.size()); assertThat(partialResponse.size()).isGreaterThan(0); for (final BlockHeader header : partialResponse) { assertThat(requestedData).contains(header); } }
@Override protected void assertPartialResultMatchesExpectation( final List<Block> requestedData, final List<Block> partialResponse) { assertThat(partialResponse.size()).isLessThanOrEqualTo(requestedData.size()); assertThat(partialResponse.size()).isGreaterThan(0); for (final Block block : partialResponse) { assertThat(requestedData).contains(block); } } }
@Override protected void assertPartialResultMatchesExpectation( final List<BlockHeader> requestedData, final List<BlockHeader> partialResponse) { assertThat(partialResponse.size()).isLessThanOrEqualTo(requestedData.size()); assertThat(partialResponse.size()).isGreaterThan(0); for (final BlockHeader header : partialResponse) { assertThat(requestedData).contains(header); } }
@Example void currentlyNoCodepointsAboveAllowedMaxAreCreated() { assertAllGenerated(arbitrary.generator(10), s -> { for (int i = 0; i < s.length(); i++) { Assertions.assertThat(s.codePointAt(i)).isLessThanOrEqualTo(Character.MAX_CODE_POINT); } }); }
@Test public void canRequestTimestampRangeWithGetFreshTimestamps() { int expectedNumTimestamps = 5; TimestampRange range = timestampService.getFreshTimestamps(expectedNumTimestamps); Assertions.assertThat((int) range.size()) .withFailMessage("Expected %d timestamps, got %d timestamps. (The returned range was: %d-%d)", expectedNumTimestamps, range.size(), range.getLowerBound(), range.getUpperBound()) .isGreaterThanOrEqualTo(1) .isLessThanOrEqualTo(expectedNumTimestamps); }
@Test public void customClient() { final HttpClient httpClient = createCustomHttpClient(); final CompletionStage<HttpResponse> completionStage = httpClient.execute(HttpRequest.of(GET, "http://commercetools.com")); final HttpResponse httpResponse = completionStage.toCompletableFuture().join(); assertThat(httpResponse.getStatusCode()).isLessThanOrEqualTo(302); httpClient.close(); } }
private <T> void integer(final DevelopmentBuilder builder, final Function<Integer, DevelopmentBuilder> setter, final Supplier<Integer> getter, final int value) { assertThat(getter.get()).as("False before setting.").isLessThanOrEqualTo(0); final DevelopmentBuilder newBuilder = setter.apply(value); assertSoftly(softly -> { softly.assertThat(newBuilder).as("Setter returned itself.").isSameAs(builder); softly.assertThat(getter.get()).as("Correct value was set.").isEqualTo(value); }); }
private <T> void integer(final LoanBuilder builder, final Function<Integer, LoanBuilder> setter, final Supplier<Integer> getter, final int value) { assertThat(getter.get()).as("False before setting.").isLessThanOrEqualTo(0); final LoanBuilder newBuilder = setter.apply(value); assertSoftly(softly -> { softly.assertThat(newBuilder).as("Setter returned itself.").isSameAs(builder); softly.assertThat(getter.get()).as("Correct value was set.").isEqualTo(value); }); }