List of usage examples for java.time Duration ofSeconds
public static Duration ofSeconds(long seconds)
From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerMonitorTest.java
@Test public void testRetryOnStartFailures() throws Exception { @Cleanup//w w w.j a v a2 s . c o m CuratorFramework zkClient = startClient(); initializeHostContainerMapping(zkClient); SegmentContainerRegistry containerRegistry = createMockContainerRegistry(); @Cleanup ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient); segMonitor.initialize(Duration.ofSeconds(1)); // Simulate a container that fails to start. CompletableFuture<ContainerHandle> failedFuture = FutureHelpers.failedFuture(new RuntimeException()); when(containerRegistry.startContainer(eq(2), any())).thenReturn(failedFuture); // Use ZK to send that information to the Container Manager. HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH); currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2)); zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData)); // Verify that it does not start. verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any()); assertEquals(0, segMonitor.getRegisteredContainers().size()); // Now simulate success for the same container. ContainerHandle containerHandle = mock(ContainerHandle.class); when(containerHandle.getContainerId()).thenReturn(2); when(containerRegistry.startContainer(eq(2), any())) .thenReturn(CompletableFuture.completedFuture(containerHandle)); // Verify that it retries and starts the same container again. verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any()); Thread.sleep(2000); assertEquals(1, segMonitor.getRegisteredContainers().size()); }
From source file:reactor.ipc.netty.tcp.TcpServerTests.java
@Test public void testIssue462() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); NettyContext server = TcpServer.create(0).newHandler((in, out) -> { in.receive().log("channel").subscribe(trip -> { countDownLatch.countDown();//w w w.jav a 2 s . c o m }); return Flux.never(); }).block(Duration.ofSeconds(30)); System.out.println("PORT +" + server.address().getPort()); NettyContext client = TcpClient.create(server.address().getPort()) .newHandler((in, out) -> out.sendString(Flux.just("test"))).block(Duration.ofSeconds(30)); client.dispose(); server.dispose(); assertThat("countDownLatch counted down", countDownLatch.await(5, TimeUnit.SECONDS)); }
From source file:com.netflix.spinnaker.front50.model.S3StorageService.java
@Override public long getHealthIntervalMillis() { return Duration.ofSeconds(2).toMillis(); }
From source file:reactor.ipc.netty.tcp.TcpServerTests.java
@Test @Ignore//from www. j a v a2 s . co m public void proxyTest() throws Exception { HttpServer server = HttpServer.create(); server.newRouter(r -> r.get("/search/{search}", (in, out) -> HttpClient.create().get("foaas.herokuapp.com/life/" + in.param("search")) .flatMap(repliesOut -> out.send(repliesOut.receive())))) .block(Duration.ofSeconds(30)).onClose().block(Duration.ofSeconds(30)); }
From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerMonitorTest.java
@Test public void testRetryOnExceptions() throws Exception { @Cleanup//from w w w.j a va 2s. c o m CuratorFramework zkClient = startClient(); initializeHostContainerMapping(zkClient); SegmentContainerRegistry containerRegistry = createMockContainerRegistry(); @Cleanup ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient); segMonitor.initialize(Duration.ofSeconds(1)); // Simulate a container that throws exception on start. when(containerRegistry.startContainer(eq(2), any())).thenThrow(new RuntimeException()); // Use ZK to send that information to the Container Manager. HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH); currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2)); zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData)); // Verify that it does not start. verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any()); assertEquals(0, segMonitor.getRegisteredContainers().size()); // Now simulate success for the same container. ContainerHandle containerHandle = mock(ContainerHandle.class); when(containerHandle.getContainerId()).thenReturn(2); when(containerRegistry.startContainer(eq(2), any())) .thenReturn(CompletableFuture.completedFuture(containerHandle)); // Verify that it retries and starts the same container again. verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any()); // Using wait here to ensure the private data structure is updated. // TODO: Removing dependency on sleep here and other places in this class // - https://github.com/pravega/pravega/issues/1079 Thread.sleep(2000); assertEquals(1, segMonitor.getRegisteredContainers().size()); }
From source file:reactor.ipc.netty.tcp.TcpServerTests.java
@Test @Ignore//w ww. jav a 2 s . c o m public void wsTest() throws Exception { HttpServer server = HttpServer.create(); server.newRouter(r -> r.get("/search/{search}", (in, out) -> HttpClient.create() .get("ws://localhost:3000", requestOut -> requestOut.sendWebsocket().sendString(Mono.just("ping"))) .flatMap(repliesOut -> out.sendGroups(repliesOut.receive().window(100))))) .block(Duration.ofSeconds(30)).onClose().block(Duration.ofSeconds(30)); }
From source file:ch.cyberduck.core.spectra.SpectraBulkService.java
/** * Get a list of all job chunks for a given job that are ready for client processing. * <p>/*w ww. j a va 2 s . co m*/ * For PUT jobs, this will allocate a working window of job chunks, if possible, and return the job chunks that the client can upload. * Any chunk returned is fully allocated, meaning that you do not have to handle HTTP 307 retries on subsequent PUTs for the chunks. * Retries adversely impact BlackPearl gateway performance and require you to provide the object data stream for every PUT retry. * <p> * For GET jobs, this will respond with which job chunks have been loaded into cache and are ready for download. * * @param file File * @param status Write job id into status parameters * @throws RetriableAccessDeniedException File is not yet in cache * @throws ch.cyberduck.core.exception.RedirectException Should be accessed from different node */ public List<TransferStatus> query(final Transfer.Type type, final Path file, final TransferStatus status) throws BackgroundException { // This will respond with which job chunks have been loaded into cache and are ready for download. try { if (!status.getParameters().containsKey(REQUEST_PARAMETER_JOBID_IDENTIFIER)) { throw new NotfoundException( String.format("Missing job id parameter in status for %s", file.getName())); } final String job = status.getParameters().get(REQUEST_PARAMETER_JOBID_IDENTIFIER); if (log.isDebugEnabled()) { log.debug(String.format("Query status for job %s", job)); } final MasterObjectList list = new MasterObjectList(); list.setObjects(Collections.emptyList()); List<TransferStatus> chunks = this.query(file, status, job, list); if (chunks.isEmpty()) { // Fetch current list from server final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); // For GET, the client may need to issue multiple GET requests for a single object if it has // been broken up into multiple pieces due to its large size // For PUT, This will allocate a working window of job chunks, if possible, and return a list of // the job chunks that the client can upload. The client should PUT all of the object parts // from the list of job chunks returned and repeat this process until all chunks are transferred final GetAvailableJobChunksResponse response = // GetJobChunksReadyForClientProcessing client.getAvailableJobChunks(new GetAvailableJobChunksRequest(UUID.fromString(job)) .withPreferredNumberOfChunks(Integer.MAX_VALUE)); if (log.isInfoEnabled()) { log.info(String.format("Job status %s for job %s", response.getStatus(), job)); } switch (response.getStatus()) { case RETRYLATER: { final Duration delay = Duration.ofSeconds(response.getRetryAfterSeconds()); throw new RetriableAccessDeniedException(String.format("Job %s not yet loaded into cache", job), delay); } } final MasterObjectList master = response.getMasterObjectList(); if (log.isInfoEnabled()) { log.info(String.format("Master object list with %d objects for %s", master.getObjects().size(), file)); log.info(String.format("Master object list status %s for %s", master.getStatus(), file)); } chunks = this.query(file, status, job, master); if (log.isInfoEnabled()) { log.info(String.format("Server returned %d chunks for %s", chunks.size(), file)); } if (chunks.isEmpty()) { log.error(String.format("File %s not found in object list for job %s", file.getName(), job)); // Still look for Retry-Afer header for non empty master object list final Headers headers = response.getResponse().getHeaders(); for (String header : headers.keys()) { if (HttpHeaders.RETRY_AFTER.equalsIgnoreCase(header)) { final Duration delay = Duration.ofSeconds(Integer.parseInt(headers.get(header).get(0))); throw new RetriableAccessDeniedException(String.format("Cache is full for job %s", job), delay); } } } } return chunks; } catch (FailedRequestException e) { throw new SpectraExceptionMappingService().map(e); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map(e); } catch (SignatureException e) { throw new DefaultExceptionMappingService().map(e); } }
From source file:com.orange.cloud.servicebroker.filter.securitygroups.filter.CreateSecurityGroupTest.java
private void givenCreateSecurityGroupsFailsWithDelay(CloudFoundryClient cloudFoundryClient, String securityGroupName) { given(cloudFoundryClient.securityGroups() .create(CreateSecurityGroupRequest.builder().name(securityGroupName).spaceId("space_id") .rule(RuleEntity.builder().description(RULE_DESCRIPTION).protocol(Protocol.TCP) .ports("3306").destination("127.0.0.1").build()) .build())).willReturn( Mono.delay(Duration.ofSeconds(2)).then(Mono.error(new ClientV2Exception(null, 999, "test-exception-description", "test-exception-errorCode")))); }
From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerMonitorTest.java
@Test public void testClose() throws Exception { @Cleanup//from ww w .j a v a 2 s . c o m CuratorFramework zkClient = startClient(); initializeHostContainerMapping(zkClient); SegmentContainerRegistry containerRegistry = mock(SegmentContainerRegistry.class); ContainerHandle containerHandle1 = mock(ContainerHandle.class); when(containerHandle1.getContainerId()).thenReturn(1); when(containerRegistry.startContainer(eq(1), any())) .thenReturn(CompletableFuture.completedFuture(containerHandle1)); when(containerRegistry.stopContainer(any(), any())).thenReturn(CompletableFuture.completedFuture(null)); ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient); segMonitor.initialize(Duration.ofSeconds(1)); segMonitor.close(); assertEquals(0, segMonitor.getRegisteredContainers().size()); }