@Override public void doFilter(HttpServletRequest wrappedRequest) { long lastAccessed = wrappedRequest.getSession().getLastAccessedTime(); assertThat(lastAccessed).isCloseTo( wrappedRequest.getSession().getCreationTime(), Offset.offset(5L)); SessionRepositoryFilterTests.this.request.setAttribute(ACCESS_ATTR, lastAccessed); } });
assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(50)); assertThat(elapsedList.get(2) - elapsedList.get(1)) .isCloseTo(200, Percentage.withPercentage(50)); assertThat(elapsedList.get(3) - elapsedList.get(2)) .isCloseTo(400, Percentage.withPercentage(50)); assertThat(elapsedList.get(4) - elapsedList.get(3)) .isCloseTo(800, Percentage.withPercentage(50));
assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(10)); assertThat(elapsedList.get(2) - elapsedList.get(1)) .isCloseTo(200, Percentage.withPercentage(10)); assertThat(elapsedList.get(3) - elapsedList.get(2)) .isCloseTo(400, Percentage.withPercentage(10)); assertThat(elapsedList.get(4) - elapsedList.get(3)) .isCloseTo(800, Percentage.withPercentage(10));
assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(50)); assertThat(elapsedList.get(2) - elapsedList.get(1)) .isCloseTo(200, Percentage.withPercentage(50)); assertThat(elapsedList.get(3) - elapsedList.get(2)) .isCloseTo(400, Percentage.withPercentage(50)); assertThat(elapsedList.get(4) - elapsedList.get(3)) .isCloseTo(800, Percentage.withPercentage(50));
@Test public void monoRetryRandomBackoff_minBackoffFloor() { for (int i = 0; i < 50; i++) { AtomicInteger errorCount = new AtomicInteger(); Exception exception = new IOException("boom retry loop #" + i); List<Long> elapsedList = new ArrayList<>(); StepVerifier.withVirtualTime(() -> Mono.error(exception) .doOnError(e -> { errorCount.incrementAndGet(); elapsedList.add(Schedulers.parallel().now(TimeUnit.MILLISECONDS)); }) .retryBackoff(1, Duration.ofMillis(100), Duration.ofMillis(2000), 0.9) ) .thenAwait(Duration.ofMinutes(1)) //ensure whatever the jittered delay that we have time to fit 4 retries .expectErrorSatisfies(e -> assertThat(e).isInstanceOf(IllegalStateException.class) .hasMessage("Retries exhausted: 1/1") .hasCause(exception)) .verify(Duration.ofSeconds(1)); //vts test shouldn't even take that long assertThat(errorCount).hasValue(2); assertThat(elapsedList).hasSize(2); assertThat(elapsedList.get(0)).isEqualTo(0L); assertThat(elapsedList.get(1) - elapsedList.get(0)) .isGreaterThanOrEqualTo(100) //min backoff .isCloseTo(100, Percentage.withPercentage(90)); } }
private void thenNonPutOverheadMillionthsIsVeryCloseTo(long expectedNonPutOverheadMillionths) { assertThat(getNonPutOverheadMillionths(profile, postCommitOverhead)) .isCloseTo(expectedNonPutOverheadMillionths, within(1L)); }
@Test public void testMetricsRecordedAfterIncompleteRunForOneIterationOnly() { setNoProgress(); setNextTableToSweep(TABLE_REF); SweepResults intermediateResults = SweepResults.builder() .staleValuesDeleted(2) .cellTsPairsExamined(10) .minSweptTimestamp(12345L) .nextStartRow(Optional.of(new byte[] {1, 2, 3})) .timeInMillis(10L) .timeSweepStarted(20L) .build(); setupTaskRunner(intermediateResults); backgroundSweeper.runOnce(); ArgumentCaptor<Long> sweepTime = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Long> totalTimeElapsed = ArgumentCaptor.forClass(Long.class); Mockito.verify(sweepMetrics).updateSweepTime( sweepTime.capture(), totalTimeElapsed.capture()); Assertions.assertThat(intermediateResults.getTimeInMillis()).isEqualTo(sweepTime.getValue()); Assertions.assertThat(intermediateResults.getTimeElapsedSinceStartedSweeping()) .isCloseTo(totalTimeElapsed.getValue(), Percentage.withPercentage(5d)); }
.isCloseTo(totalTimeElapsed.getValue(), Percentage.withPercentage(5d));
@Test void shouldGetAsyncSystemCurrentTime() throws Exception { Long time = new SystemTimeSupplier().getAsync().toCompletableFuture().get(); assertThat(time).isCloseTo(System.currentTimeMillis() / 1000L, Offset.offset(2L)); }
@Test void shouldGetReactiveSystemCurrentTime() { Long time = new SystemTimeSupplier().getReactive().block(); assertThat(time).isCloseTo(System.currentTimeMillis() / 1000L, Offset.offset(2L)); } }
@Test void shouldGetSystemCurrentTime() { Long time = new SystemTimeSupplier().get(); assertThat(time).isCloseTo(System.currentTimeMillis() / 1000L, Offset.offset(2L)); }
@Test public void testGetKeyTimeMillis() throws IOException { long t1 = System.currentTimeMillis(); String key = KeyGenerator.createKey(); long t2 = KeyGenerator.getKeyTimeMillis(key); assertThat(t2).isCloseTo(t1, Offset.offset(500L)); }
@Test public void testGetKeyTimeMillis() throws IOException { long t1 = System.currentTimeMillis(); String key = KeyGenerator.createKey(); long t2 = KeyGenerator.getKeyTimeMillis(key); assertThat(t2).isCloseTo(t1, Offset.offset(500L)); } }
@Test public void serializeDeserializeFindNeighborsPacketData() { final byte[] r = new byte[64]; new Random().nextBytes(r); final BytesValue target = BytesValue.wrap(r); final FindNeighborsPacketData packet = FindNeighborsPacketData.create(target); final BytesValue serialized = RLP.encode(packet::writeTo); assertNotNull(serialized); final FindNeighborsPacketData deserialized = FindNeighborsPacketData.readFrom(RLP.input(serialized)); assertThat(deserialized.getTarget()).isEqualTo(target); // Fuzziness: allow a skew of 1.5 seconds between the time the message was generated until the // assertion. assertThat(deserialized.getExpiration()) .isCloseTo( System.currentTimeMillis() + PacketData.DEFAULT_EXPIRATION_PERIOD_MS, offset(1500L)); }
public static void verifySpanDeepEquals( Span spanToVerify, Span expectedSpan, boolean allowStartTimeNanosFudgeFactor ) { assertThat(spanToVerify.getSpanStartTimeEpochMicros()).isEqualTo(expectedSpan.getSpanStartTimeEpochMicros()); if (allowStartTimeNanosFudgeFactor) { assertThat(spanToVerify.getSpanStartTimeNanos()) .isCloseTo(expectedSpan.getSpanStartTimeNanos(), Offset.offset(TimeUnit.MILLISECONDS.toNanos(1))); } else { assertThat(spanToVerify.getSpanStartTimeNanos()).isEqualTo(expectedSpan.getSpanStartTimeNanos()); } assertThat(spanToVerify.isCompleted()).isEqualTo(expectedSpan.isCompleted()); assertThat(spanToVerify.getTraceId()).isEqualTo(expectedSpan.getTraceId()); assertThat(spanToVerify.getSpanId()).isEqualTo(expectedSpan.getSpanId()); assertThat(spanToVerify.getParentSpanId()).isEqualTo(expectedSpan.getParentSpanId()); assertThat(spanToVerify.getSpanName()).isEqualTo(expectedSpan.getSpanName()); assertThat(spanToVerify.isSampleable()).isEqualTo(expectedSpan.isSampleable()); assertThat(spanToVerify.getUserId()).isEqualTo(expectedSpan.getUserId()); assertThat(spanToVerify.getDurationNanos()).isEqualTo(expectedSpan.getDurationNanos()); assertThat(spanToVerify.getSpanPurpose()).isEqualTo(expectedSpan.getSpanPurpose()); assertThat(spanToVerify.getTags()).isEqualTo(expectedSpan.getTags()); assertThat(spanToVerify.getTimestampedAnnotations()).isEqualTo(expectedSpan.getTimestampedAnnotations()); }
@Test public void neighborsPacketData() { final List<DiscoveryPeer> peers = helper.createDiscoveryPeers(5); final NeighborsPacketData packet = NeighborsPacketData.create(peers); final BytesValue serialized = RLP.encode(packet::writeTo); assertNotNull(serialized); final NeighborsPacketData deserialized = NeighborsPacketData.readFrom(RLP.input(serialized)); assertThat(deserialized.getNodes()).isEqualTo(peers); // Fuzziness: allow a skew of 1.5 seconds between the time the message was generated until the // assertion. assertThat(deserialized.getExpiration()) .isCloseTo( System.currentTimeMillis() + PacketData.DEFAULT_EXPIRATION_PERIOD_MS, offset(1500L)); }
assertThat(request.getTimestamp()).isCloseTo(System.currentTimeMillis(), byLessThan(2000L)); assertThat(request.getMethod()).isEqualTo(method); assertThat(request.getUrl()).isEqualTo(url);