Example usage for java.time Duration ofSeconds

List of usage examples for java.time Duration ofSeconds

Introduction

In this page you can find the example usage for java.time Duration ofSeconds.

Prototype

public static Duration ofSeconds(long seconds) 

Source Link

Document

Obtains a Duration representing a number of seconds.

Usage

From source file:org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfigurationUnitTests.java

@Test // DATAREDIS-667
public void shouldCreateEmptyConfiguration() {

    LettucePoolingClientConfiguration configuration = LettucePoolingClientConfiguration.defaultConfiguration();

    assertThat(configuration.getPoolConfig()).isNotNull();
    assertThat(configuration.isUseSsl()).isFalse();
    assertThat(configuration.isVerifyPeer()).isTrue();
    assertThat(configuration.isStartTls()).isFalse();
    assertThat(configuration.getClientOptions()).isEmpty();
    assertThat(configuration.getClientResources()).isEmpty();
    assertThat(configuration.getCommandTimeout()).isEqualTo(Duration.ofSeconds(60));
    assertThat(configuration.getShutdownTimeout()).isEqualTo(Duration.ofMillis(100));
    assertThat(configuration.getShutdownQuietPeriod()).isEqualTo(Duration.ofMillis(100));
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void pushCanBeCanceled() throws Exception {
    String appName = appHarness.randomAppName();
    IProject project = projects.createBootWebProject("slow-starter");
    File jarFile = BootJarPackagingTest.packageAsJar(project, ui);

    CancelationTokens cancelationTokens = new CancelationTokens();
    try (CFPushArguments params = new CFPushArguments()) {
        params.setAppName(appName);//from   w  w  w  .jav a 2  s .com
        params.setRoutes(appName + "." + CFAPPS_IO());
        params.setApplicationData(jarFile);

        long starting = System.currentTimeMillis();
        Future<Void> pushResult = doAsync(() -> {
            System.out.println("Pushing...");
            client.push(params, cancelationTokens.create());
            long duration = System.currentTimeMillis() - starting;
            System.out.println("Pushing took: " + duration + " ms");
        });
        Thread.sleep(Duration.ofSeconds(10).toMillis());
        long cancelTime = System.currentTimeMillis();
        System.out.println("Canceling...");
        cancelationTokens.cancelAll();

        try {
            pushResult.get(5, TimeUnit.SECONDS); // Cancel should happen pretty 'fast'!
            fail("push completed but it should have been canceled");
        } catch (ExecutionException e) { // real exception is wrapped in EE by Future.get
            e.printStackTrace();
            long duration = System.currentTimeMillis() - cancelTime;
            assertEquals(OperationCanceledException.class, ExceptionUtil.getDeepestCause(e).getClass());
            System.out.println("\nPush Canceled after: " + duration + " ms");
        }
    }
}

From source file:org.springframework.integration.config.xml.GatewayParserTests.java

@Test
public void testMonoGateway() throws Exception {
    PollableChannel requestChannel = context.getBean("requestChannel", PollableChannel.class);
    MessageChannel replyChannel = context.getBean("replyChannel", MessageChannel.class);
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("promise", TestService.class);
    Mono<Message<?>> result = service.promise("foo");
    Message<?> reply = result.block(Duration.ofSeconds(1));
    assertEquals("foo", reply.getPayload());
    assertNotNull(TestUtils.getPropertyValue(context.getBean("&promise"), "asyncExecutor"));
}

From source file:org.springframework.session.web.http.HttpSessionAdapter.java

@Override
public void setMaxInactiveInterval(int interval) {
    this.session.setMaxInactiveInterval(Duration.ofSeconds(interval));
}

From source file:org.springframework.web.server.handler.FilteringWebHandlerTests.java

@Test
public void asyncFilter() throws Exception {

    AsyncFilter filter = new AsyncFilter();
    StubWebHandler targetHandler = new StubWebHandler();

    new FilteringWebHandler(targetHandler, Collections.singletonList(filter))
            .handle(MockServerWebExchange.from(MockServerHttpRequest.get("/"))).block(Duration.ofSeconds(5));

    assertTrue(filter.invoked());//from  w w  w  .j ava 2  s.  c  o m
    assertTrue(targetHandler.invoked());
}