@Test public void should_have_empty_branch_purge_date() { PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), 30, Optional.of(10), System2.INSTANCE, emptyList()); assertThat(conf.maxLiveDateOfInactiveShortLivingBranches()).isNotEmpty(); long tenDaysAgo = DateUtils.addDays(new Date(System2.INSTANCE.now()), -10).getTime(); assertThat(conf.maxLiveDateOfInactiveShortLivingBranches().get().getTime()).isBetween(tenDaysAgo - 5000, tenDaysAgo + 5000); }
@Test(timeout = 20000L) public void testBaseline() throws Exception { final long baselineNanos = baselineNanos(); // Measure the time taken for stopping the server after handling a single request. server.start(); final SleepService.Iface client = newClient(); client.sleep(0); final long startTime = System.nanoTime(); server.stop().join(); final long stopTime = System.nanoTime(); // .. which should be on par with the baseline. assertThat(stopTime - startTime).isBetween(baselineNanos - MILLISECONDS.toNanos(400), baselineNanos + MILLISECONDS.toNanos(400)); }
assertThat(stopTime - startTime).isBetween(baselineNanos + MILLISECONDS.toNanos(600), baselineNanos + MILLISECONDS.toNanos(1400));
@Test(timeout = 20000) public void testHardTimeout() throws Exception { final long baselineNanos = baselineNanos(); final Server server = GracefulShutdownIntegrationTest.server.start(); // Keep sending a request after shutdown starts so that the hard limit is reached. final SleepService.Iface client = newClient(); final CompletableFuture<Long> stopFuture = CompletableFuture.supplyAsync(() -> { final long startTime = System.nanoTime(); server.stop().join(); final long stopTime = System.nanoTime(); return stopTime - startTime; }); for (int i = 0; i < 50; i++) { try { client.sleep(100); } catch (Exception e) { // Server has been shut down break; } } // Should take 1 more second than the baseline, because the requests will extend the quiet period // until the shutdown timeout is triggered. assertThat(stopFuture.join()).isBetween(baselineNanos + MILLISECONDS.toNanos(600), baselineNanos + MILLISECONDS.toNanos(1400)); }
@Test(timeout = 20000L) public void waitsForRequestToComplete() throws Exception { final long baselineNanos = baselineNanos(); server.start(); final SleepService.Iface client = newClient(); final AtomicBoolean completed = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); CompletableFuture.runAsync(() -> { try { latch.countDown(); client.sleep(500L); completed.set(true); } catch (Throwable t) { fail("Shouldn't happen: " + t); } }); // Wait for the latch to make sure the request has been sent before shutting down. latch.await(); final long startTime = System.nanoTime(); server.stop().join(); final long stopTime = System.nanoTime(); assertTrue(completed.get()); // Should take 500 more milliseconds than the baseline. assertThat(stopTime - startTime).isBetween(baselineNanos + MILLISECONDS.toNanos(100), baselineNanos + MILLISECONDS.toNanos(900)); }
assertThat(l).isBetween(0L, Long.MAX_VALUE); l = RandomUtil.nextLong(RandomUtil.threadLocalRandom()); assertThat(l).isBetween(0L, Long.MAX_VALUE); assertThat(l).isBetween(0L, 10L); l = RandomUtil.nextLong(RandomUtil.threadLocalRandom(), 10L); assertThat(l).isBetween(0L, 10L); assertThat(l).isBetween(10L, 20L); l = RandomUtil.nextLong(RandomUtil.threadLocalRandom(), 10, 20); assertThat(l).isBetween(10L, 20L);
@Test public void testScaleWriters() { try { // small table that will only have one writer assertUpdate( Session.builder(getSession()) .setSystemProperty("scale_writers", "true") .setSystemProperty("writer_min_size", "32MB") .build(), "CREATE TABLE scale_writers_small AS SELECT * FROM tpch.tiny.orders", (long) computeActual("SELECT count(*) FROM tpch.tiny.orders").getOnlyValue()); assertEquals(computeActual("SELECT count(DISTINCT \"$path\") FROM scale_writers_small").getOnlyValue(), 1L); // large table that will scale writers to multiple machines assertUpdate( Session.builder(getSession()) .setSystemProperty("scale_writers", "true") .setSystemProperty("writer_min_size", "1MB") .build(), "CREATE TABLE scale_writers_large WITH (format = 'RCBINARY') AS SELECT * FROM tpch.sf1.orders", (long) computeActual("SELECT count(*) FROM tpch.sf1.orders").getOnlyValue()); long files = (long) computeScalar("SELECT count(DISTINCT \"$path\") FROM scale_writers_large"); long workers = (long) computeScalar("SELECT count(*) FROM system.runtime.nodes"); assertThat(files).isBetween(2L, workers); } finally { assertUpdate("DROP TABLE IF EXISTS scale_writers_large"); assertUpdate("DROP TABLE IF EXISTS scale_writers_small"); } }
private void verifyExpectedArgument(long sweepTime, long totalTimeElapsed) { assertThat(RESULTS_NO_MORE_TO_SWEEP.getTimeInMillis()).isEqualTo(sweepTime); assertThat(totalTimeElapsed).isBetween( RESULTS_NO_MORE_TO_SWEEP.getTimeElapsedSinceStartedSweeping() - 1000L, RESULTS_NO_MORE_TO_SWEEP.getTimeElapsedSinceStartedSweeping()); }
@Test(enabled = false) void testExponentialBackoffDelaySmallInterval5() throws InterruptedException { long period = 5; long acceptableDelay = period - 1; long startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(period, 2, 1, 5, "TEST FAILURE: 1"); long elapsedTime = (System.nanoTime() - startTime) / 1000000; assertThat(elapsedTime).isBetween(period, period + acceptableDelay); }
@Test(enabled = false) void testExponentialBackoffDelaySmallInterval1() throws InterruptedException { long period = 1; long acceptableDelay = 5; long startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(period, 2, 1, 5, "TEST FAILURE: 1"); long elapsedTime = (System.nanoTime() - startTime) / 1000000; assertThat(elapsedTime).isBetween(period, period + acceptableDelay); }
@Test void testExponentialBackoffDelaySmallInterval0() throws InterruptedException { long period = 0; long acceptableDelay = 5; long startTime = System.nanoTime(); handler.imposeBackoffExponentialDelay(period, 2, 1, 5, "TEST FAILURE: 1"); long elapsedTime = (System.nanoTime() - startTime) / 1000000; assertThat(elapsedTime).isBetween(period, period + acceptableDelay); }
@Test public void testUpsertBasic() { GitInfo original = newGitInfo(123, "Overwatch", "master"); GitInfo inserted = branchService.upsert(original); assertThat(inserted.getId().isPresent()).isTrue(); Optional<GitInfo> retrieved = branchService.get(inserted.getId().get()); assertThat(retrieved.isPresent()).isTrue(); assertThat(retrieved.get()).isEqualTo(inserted); assertThat(retrieved.get().getCreatedTimestamp()).isBetween(System.currentTimeMillis() - 1000, System.currentTimeMillis()); assertThat(retrieved.get().getUpdatedTimestamp()).isBetween(System.currentTimeMillis() - 1000, System.currentTimeMillis()); assertThat(retrieved.get().getUpdatedTimestamp()).isEqualTo(retrieved.get().getCreatedTimestamp()); }
@Test public void TimestampedAnnotation_forCurrentTime_works_as_expected() { // given String value = UUID.randomUUID().toString(); // when long beforeMillis = System.currentTimeMillis(); TimestampedAnnotation result = TimestampedAnnotation.forCurrentTime(value); long afterMillis = System.currentTimeMillis(); // then long beforeMicros = TimeUnit.MILLISECONDS.toMicros(beforeMillis); long afterMicros = TimeUnit.MILLISECONDS.toMicros(afterMillis); assertThat(result.getTimestampEpochMicros()).isBetween(beforeMicros, afterMicros); assertThat(result.getValue()).isEqualTo(value); }
@Test public void testRoundTrip() { Module m = mock(Module.class); VirtualFile f = mock(VirtualFile.class); SonarLintJob job = new SonarLintJob(m, Collections.singleton(f), TriggerType.COMPILATION); assertThat(job.allFiles()).containsOnly(f); assertThat(job.filesPerModule().keySet()).containsOnly(m); assertThat(job.trigger()).isEqualTo(TriggerType.COMPILATION); assertThat(job.creationTime()).isBetween(System.currentTimeMillis() - 5000, System.currentTimeMillis()); }
@Test public void testUpsertRepositoryRename() { GitInfo original = newGitInfo(123, "Overwatch", "master"); original = branchService.upsert(original); GitInfo renamed = newGitInfo(123, "Underwatch", "master"); renamed = branchService.upsert(renamed); assertThat(renamed.getId().get()).isEqualTo(original.getId().get()); Optional<GitInfo> retrieved = branchService.get(original.getId().get()); assertThat(retrieved.isPresent()).isTrue(); assertThat(retrieved.get()).isEqualTo(renamed); assertThat(retrieved.get().getUpdatedTimestamp()).isBetween(System.currentTimeMillis() - 1000, System.currentTimeMillis()); assertThat(retrieved.get().getUpdatedTimestamp()).isGreaterThan(retrieved.get().getCreatedTimestamp()); }
@Test public void test_scheduler() { assertThat(telemetry.scheduledFuture).isNotNull(); assertThat(telemetry.scheduledFuture.getDelay(TimeUnit.MINUTES)).isBetween(0L, 1L); telemetry.stop(); assertThat(telemetry.scheduledFuture).isNull(); }
private void verifyDurationBetweenLowerAndUpperBounds(Span span, long beforeCompletionCallNanoTime, long afterCompletionCallNanoTime) { long durationLowerBound = beforeCompletionCallNanoTime - span.getSpanStartTimeNanos(); long durationUpperBound = afterCompletionCallNanoTime - span.getSpanStartTimeNanos(); assertThat(span.getDurationNanos()).isNotNull(); assertThat(span.getDurationNanos()).isBetween(durationLowerBound, durationUpperBound); }
@Test void testRandomJitter() { assertThat(IntakeV2ReportingEventHandler.getRandomJitter(0)).isZero(); assertThat(IntakeV2ReportingEventHandler.getRandomJitter(1)).isZero(); assertThat(IntakeV2ReportingEventHandler.getRandomJitter(100)).isBetween(-10L, 10L); }
@Test public void testBuilder_successful_run() throws InterruptedException { QueryExecutionResult.QueryExecutionResultBuilder queryExecutionResultBuilder = new QueryExecutionResult.QueryExecutionResultBuilder(queryExecution()) .setRowsCount(100); queryExecutionResultBuilder.startTimer(); TimeUnit.MILLISECONDS.sleep(500L); queryExecutionResultBuilder.endTimer(); QueryExecutionResult execution = queryExecutionResultBuilder.build(); assertThat(execution.isSuccessful()).isTrue(); assertThat(execution.getRowsCount()).isEqualTo(100); assertThat(execution.getQueryDuration().toMillis()).isBetween(500L, 600L); }
@Test public void testBuilder_successful_run() throws InterruptedException { QueryExecutionResult.QueryExecutionResultBuilder queryExecutionResultBuilder = new QueryExecutionResult.QueryExecutionResultBuilder(queryExecution()) .setRowsCount(100); queryExecutionResultBuilder.startTimer(); TimeUnit.MILLISECONDS.sleep(500L); queryExecutionResultBuilder.endTimer(); QueryExecutionResult execution = queryExecutionResultBuilder.build(); assertThat(execution.isSuccessful()).isTrue(); assertThat(execution.getRowsCount()).isEqualTo(100); assertThat(execution.getQueryDuration().toMillis()).isBetween(500L, 600L); }