@Test public void shouldGetNewCommandsIteratorCorrectly() { // Given: when(commandConsumer.poll(any(Duration.class))).thenReturn(consumerRecords); // When: final Iterable<ConsumerRecord<CommandId, Command>> newCommands = commandTopic .getNewCommands(Duration.ofHours(1)); // Then: assertThat(newCommands, sameInstance(consumerRecords)); }
@Test(dataProvider = "caches") @CacheSpec(implementation = Implementation.Caffeine, population = Population.FULL, expiry = CacheExpiry.MOCKITO, expiryTime = Expire.ONE_MINUTE) public void getExpiresAfter_duration(Cache<Integer, Integer> cache, CacheContext context, VarExpiration<Integer, Integer> expireAfterVar) { assertThat(expireAfterVar.getExpiresAfter(context.absentKey()), is(Optional.empty())); assertThat(expireAfterVar.getExpiresAfter(context.firstKey()), is(Optional.of(Duration.ofMinutes(1L)))); when(context.expiry().expireAfterUpdate(any(), any(), anyLong(), anyLong())) .thenReturn(TimeUnit.HOURS.toNanos(1)); cache.put(context.firstKey(), context.absentValue()); assertThat(expireAfterVar.getExpiresAfter(context.firstKey()), is(Optional.of(Duration.ofHours(1)))); assertThat(expireAfterVar.getExpiresAfter(context.lastKey()), is(Optional.of(Duration.ofMinutes(1)))); }
@Test public void noDelayGreaterThanSize() { StepVerifier.create(Flux.range(1, 12) .windowTimeout(5, Duration.ofHours(1)) .concatMap(Flux::collectList) ) .assertNext(l -> assertThat(l).containsExactly(1, 2, 3, 4, 5)) .assertNext(l -> assertThat(l).containsExactly(6, 7, 8, 9, 10)) .assertNext(l -> assertThat(l).containsExactly(11, 12)) .verifyComplete(); }
@Override protected void configure(HttpSecurity http) throws Exception { Clock justOverOneHourAfterExpiry = Clock.fixed(Instant.ofEpochMilli(4687181595000L), ZoneId.systemDefault()); JwtTimestampValidator jwtValidator = new JwtTimestampValidator(Duration.ofHours(1)); jwtValidator.setClock(justOverOneHourAfterExpiry); this.jwtDecoder.setJwtValidator(jwtValidator); // @formatter:off http .oauth2ResourceServer() .jwt(); } }
@Test public void longDelaysStartEndEmitEmptyWindows() { StepVerifier.withVirtualTime(() -> Mono.just("foo") .delayElement(Duration.ofMillis(400 + 400 + 300)) .concatWith(Mono.delay(Duration.ofMillis(100 + 400 + 100)).then(Mono.empty())) .windowTimeout(1000, Duration.ofMillis(400)) .concatMap(Flux::collectList) ) .thenAwait(Duration.ofHours(1)) .assertNext(l -> assertThat(l).isEmpty()) .assertNext(l -> assertThat(l).isEmpty()) .assertNext(l -> assertThat(l).containsExactly("foo")) .assertNext(l -> assertThat(l).isEmpty()) .assertNext(l -> assertThat(l).isEmpty()) //closing window .verifyComplete(); }
@Test public void maxHandlesDifferentUnits() { Duration sixtyOneMinutes = Duration.ofMinutes(61); Duration oneHour = Duration.ofHours(1); assertThat(Temporals.max(sixtyOneMinutes, oneHour)).isEqualTo(sixtyOneMinutes); }
@Test public void timeoutDurationMessageDefault() { StepVerifier.withVirtualTime(() -> Mono.never() .timeout(Duration.ofHours(1))) .thenAwait(Duration.ofHours(2)) .expectErrorMessage("Did not observe any item or terminal signal within " + "3600000ms in 'source(MonoNever)' (and no fallback has been " + "configured)") .verify(); }
@Test public void timeoutDurationMessageDefault() { StepVerifier.withVirtualTime(() -> Flux.never() .timeout(Duration.ofHours(1))) .thenAwait(Duration.ofHours(2)) .expectErrorMessage("Did not observe any item or terminal signal within " + "3600000ms in 'source(FluxNever)' (and no fallback has been configured)") .verify(); }
@Override protected void configure(HttpSecurity http) throws Exception { Clock nearlyAnHourFromTokenExpiry = Clock.fixed(Instant.ofEpochMilli(4687181540000L), ZoneId.systemDefault()); JwtTimestampValidator jwtValidator = new JwtTimestampValidator(Duration.ofHours(1)); jwtValidator.setClock(nearlyAnHourFromTokenExpiry); this.jwtDecoder.setJwtValidator(jwtValidator); // @formatter:off http .oauth2ResourceServer() .jwt(); // @formatter:on } }
@Test public void verifyVirtualTimeOnNext() { StepVerifier.withVirtualTime(() -> Flux.just("foo", "bar", "foobar") .delayElements(Duration.ofHours(1)) .log()) .thenAwait(Duration.ofHours(1)) .expectNext("foo") .thenAwait(Duration.ofHours(1)) .expectNext("bar") .thenAwait(Duration.ofHours(1)) .expectNext("foobar") .expectComplete() .verify(); }
@Test public void virtualTimeSchedulerVeryLong() { StepVerifier.withVirtualTime(() -> Flux.interval(Duration.ofMillis(1)) .map(tick -> new Date()) .take(100000) .collectList()) .thenAwait(Duration.ofHours(1000)) .consumeNextWith(list -> Assert.assertTrue(list.size() == 100000)) .verifyComplete(); }
@Test public void timeoutDurationMessageWithName() { StepVerifier.withVirtualTime(() -> Mono.never() .name("Name") .timeout(Duration.ofHours(1))) .thenAwait(Duration.ofHours(2)) .expectErrorMessage("Did not observe any item or terminal signal within " + "3600000ms in 'Name' (and no fallback has been " + "configured)") .verify(); }
@Test public void timeoutDurationMessageWithName() { StepVerifier.withVirtualTime(() -> Flux.never() .name("Name") .timeout(Duration.ofHours(1))) .thenAwait(Duration.ofHours(2)) .expectErrorMessage("Did not observe any item or terminal signal within " + "3600000ms in 'Name' (and no fallback has been configured)") .verify(); }
@Test public void cancelUpstreamOnceWhenCancelled() { VirtualTimeScheduler vts = VirtualTimeScheduler.create(); AtomicLong upstreamCancelCount = new AtomicLong(); Mono<String> source = Mono.just("foo").log().hide() .doOnCancel(() -> upstreamCancelCount.incrementAndGet()); StepVerifier.withVirtualTime( () -> new MonoDelayElement<>(source, 2, TimeUnit.SECONDS, vts), () -> vts, Long.MAX_VALUE) .expectSubscription() .expectNoEvent(Duration.ofSeconds(1)) .thenCancel() .verify(); vts.advanceTimeBy(Duration.ofHours(1)); assertThat(upstreamCancelCount.get()).isEqualTo(1); }
private static Stream<AnyValue> unsupportedValues() { return Stream.of( nodeValue( 42, stringArray( "Person" ), EMPTY_MAP ), newRelationshipValue(), pointValue( CoordinateReferenceSystem.WGS84, new double[2] ), byteArray( new byte[]{1, 2, 3} ), Values.of( Duration.ofHours( 1 ) ), Values.of( LocalDate.now() ), Values.of( LocalTime.now() ), Values.of( OffsetTime.now() ), Values.of( LocalDateTime.now() ), Values.of( ZonedDateTime.now() ) ); }
@Test(timeout = 3000) public void verifyVirtualTimeOnNextIntervalManual() { VirtualTimeScheduler vts = VirtualTimeScheduler.create(); StepVerifier.withVirtualTime(() -> Flux.interval(Duration.ofMillis(1000), vts) .map(d -> "t" + d)) .then(() -> vts.advanceTimeBy(Duration.ofHours(1))) .expectNextCount(3600) .thenCancel() .verify(); }
@Test public void gh783_firstSmallAdvance() { StepVerifier.withVirtualTime(() -> Flux.just("foo").flatMap(message -> Flux.interval(Duration.ofMinutes(5)).take(12))) .expectSubscription() .expectNoEvent(Duration.ofMinutes(3)) .thenAwait(Duration.ofHours(1)) .expectNextCount(12) .expectComplete() .verify(Duration.ofMillis(500)); }
@Test public void shouldCommitPeriodically() { // 10 hours OffsetCommitPolicy policy = OffsetCommitPolicy.periodic(Configuration.create().with(EmbeddedEngine.OFFSET_FLUSH_INTERVAL_MS, 10 * 60 * 60 * 1000).build()); assertThat(policy.performCommit(0, Duration.ofNanos(0))).isFalse(); assertThat(policy.performCommit(10000, Duration.ofHours(9))).isFalse(); assertThat(policy.performCommit(0, Duration.ofHours(10))).isTrue(); }