@Override public void run(SourceContext<Email> ctx) throws Exception { // Sleep for 10 seconds on start to allow time to copy jobid Thread.sleep(10000L); int types = LabelSurrogate.Type.values().length; while (isRunning) { int r = random.nextInt(100); final EmailId emailId = new EmailId(Integer.toString(random.nextInt())); final Instant timestamp = Instant.now().minus(Duration.ofDays(1L)); final String foo = String.format("foo #%d", r); final LabelSurrogate label = new LabelSurrogate(LabelSurrogate.Type.values()[r % types], "bar"); synchronized (ctx.getCheckpointLock()) { ctx.collect(new Email(emailId, timestamp, foo, label)); } Thread.sleep(30L); } }
public static OAuth2AccessToken scopes(String... scopes) { return new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, "scopes", Instant.now(), Instant.now().plus(Duration.ofDays(1)), new HashSet<>(Arrays.asList(scopes))); } }
public static OAuth2AccessToken noScopes() { return new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, "no-scopes", Instant.now(), Instant.now().plus(Duration.ofDays(1))); }
@Test public void build_filled() { Timeouts t = TimeoutsBuilder.timeouts() .read(Duration.ofDays(1)) .write(Duration.ofDays(2)) .connection(Duration.ofDays(3)) .build(); assertThat(t.getReadOperationTimeout()).isEqualTo(Duration.ofDays(1)); assertThat(t.getWriteOperationTimeout()).isEqualTo(Duration.ofDays(2)); assertThat(t.getConnectionTimeout()).isEqualTo(Duration.ofDays(3)); }
@GwtIncompatible // java.time.Duration public void testLargeDurations() { java.time.Duration threeHundredYears = java.time.Duration.ofDays(365 * 300); CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); try { builder.expireAfterWrite(threeHundredYears); fail(); } catch (ArithmeticException expected) { } try { builder.expireAfterAccess(threeHundredYears); fail(); } catch (ArithmeticException expected) { } try { builder.refreshAfterWrite(threeHundredYears); fail(); } catch (ArithmeticException expected) { } }
@Test public void shouldSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid() { testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 3, Duration.ofSeconds( 5 ) ); testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 1, Duration.ofSeconds( 11 ) ); testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 22, Duration.ofMinutes( 2 ) ); testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( 42, Duration.ofDays( 4 ) ); }
@Test public void shouldFailWhenDurationIsSentWithRun() throws Exception { testFailureWithV2Value( ValueUtils.of( Duration.ofDays( 10 ) ), "Duration" ); }
@Test(expected = IllegalArgumentException.class) public void failTime(){ Flux.never() .replay( Duration.ofDays(-1)); }
@Test public void maxAge() { Duration maxAge = Duration.ofDays(365); String expires = HttpHeaders.formatDate(System.currentTimeMillis() + maxAge.toMillis()); expires = expires.substring(0, expires.indexOf(":") + 1); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge.getSeconds()).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); }
@Test public void testWriteReadNegativeDuration() { handle.execute("insert into intervals(id, foo) values(?, ?)", 8, Duration.ofDays(-3).plusMinutes(2)); final Duration d = handle.createQuery("select foo from intervals where id=?") .bind(0, 8) .mapTo(Duration.class) .findOnly(); assertThat(d).isEqualTo(Duration.ofDays(-3).plusMinutes(2)); }
@Test public void shouldCallExternalErrorOnDuration() throws Exception { assumeThat( packerUnderTest.version(), equalTo( 1L ) ); testUnpackableStructParametersWithKnownType( new Neo4jPackV2(), durationValue( Duration.ofDays( 10 ) ), "Duration values cannot be unpacked with this version of bolt." ); }
@Test public void verifyVirtualTimeNoEventError() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.withVirtualTime(() -> Mono.just("foo") .delaySubscription(Duration.ofDays(2))) .expectSubscription() .expectNoEvent(Duration.ofDays(2)) .expectNext("foo") .expectNoEvent(Duration.ofDays(2)) .expectComplete() .verify()) .withMessage("Unexpected completion during a no-event expectation"); }
@Test public void testReadNegativeDuration() { handle.execute("insert into intervals(id, foo) values(?, interval '-2 days -3 hours')", 7); final Duration d = handle.createQuery("select foo from intervals where id=?") .bind(0, 7) .mapTo(Duration.class) .findOnly(); assertThat(d).isEqualTo(Duration.ofDays(-2).plusHours(-3)); }
@Test(expected = IllegalArgumentException.class) public void failOnHighTimeout() { SettableLimit limit = SettableLimit.startingAt(1); BlockingLimiter<Void> limiter = BlockingLimiter.wrap(SimpleLimiter.newBuilder().limit(limit).build(), Duration.ofDays(1)); } }
@Test public void verifyVirtualTimeNoEventNever() { StepVerifier.withVirtualTime(() -> Mono.never() .log()) .expectSubscription() .expectNoEvent(Duration.ofDays(10000)) .thenCancel() .verify(); }
@Test public void shouldAlwaysCommit() { OffsetCommitPolicy policy = OffsetCommitPolicy.always(); assertThat(policy.performCommit(0, Duration.ofNanos(0))).isTrue(); assertThat(policy.performCommit(10000, Duration.ofDays(1000))).isTrue(); }
@Test public void verifyVirtualTimeNoEventNeverError() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.withVirtualTime(() -> Mono.never() .log()) .expectNoEvent(Duration.ofDays(10000)) .thenCancel() .verify()) .withMessageStartingWith("expectation failed (expected no event: onSubscribe("); }