List of usage examples for java.util.concurrent CompletableFuture get
@SuppressWarnings("unchecked") public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
From source file:org.onosproject.store.consistent.impl.ConsistentMapImpl.java
private static <T> T complete(CompletableFuture<T> future) { try {/*from w w w .jav a 2s . c o m*/ return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ConsistentMapException.Interrupted(); } catch (TimeoutException e) { throw new ConsistentMapException.Timeout(); } catch (ExecutionException e) { throw new ConsistentMapException(e.getCause()); } }
From source file:org.onosproject.store.consistent.impl.DatabaseManager.java
private static <T> T complete(CompletableFuture<T> future) { try {//w w w. j a va2s .c o m return future.get(DATABASE_OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new ConsistentMapException.Interrupted(); } catch (TimeoutException e) { throw new ConsistentMapException.Timeout(); } catch (ExecutionException e) { throw new ConsistentMapException(e.getCause()); } }
From source file:com.ikanow.aleph2.analytics.storm.utils.StormControllerUtil.java
/** * Restarts a storm job by first calling stop, then calling start * /*w w w . j av a 2 s. c o m*/ * @param bucket * @param underlying_artefacts * @param yarn_config_dir * @param user_lib_paths * @param topology * @return */ public static CompletableFuture<BasicMessageBean> restartJob(final IStormController storm_controller, final DataBucketBean bucket, final Optional<String> sub_job, final Collection<Object> underlying_artefacts, final Collection<String> user_lib_paths, final StormTopology topology, final Map<String, String> config, final String cached_jar_dir) { CompletableFuture<BasicMessageBean> stop_future = stopJob(storm_controller, bucket, sub_job); try { stop_future.get(5, TimeUnit.SECONDS); waitForJobToDie(storm_controller, bucket, sub_job, 30L); } catch (Exception e) { CompletableFuture<BasicMessageBean> error_future = new CompletableFuture<BasicMessageBean>(); error_future.complete(ErrorUtils.buildErrorMessage(StormControllerUtil.class, "restartJob", ErrorUtils.getLongForm("Error stopping storm job: {0}", e))); return error_future; } return startJob(storm_controller, bucket, sub_job, underlying_artefacts, user_lib_paths, topology, config, cached_jar_dir); }
From source file:com.devicehive.handler.notification.NotificationSearchHandlerTest.java
private Response waitForResponse(CompletableFuture<Response> future) { try {/*from ww w . ja v a 2 s . c om*/ return future.get(10, TimeUnit.SECONDS); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.devicehive.handler.notification.NotificationSearchHandlerTest.java
@Test public void shouldNotFindSingleNotificationByIdAndGuid() throws Exception { NotificationSearchRequest searchRequest = new NotificationSearchRequest(); searchRequest.setId(Long.MAX_VALUE); // nonexistent id searchRequest.setGuid(UUID.randomUUID().toString()); // random guid Request request = Request.newBuilder().withPartitionKey(searchRequest.getGuid()).withBody(searchRequest) .build();// ww w.j a v a2 s.co m CompletableFuture<Response> future = new CompletableFuture<>(); client.call(request, future::complete); Response response = future.get(10, TimeUnit.SECONDS); NotificationSearchResponse responseBody = (NotificationSearchResponse) response.getBody(); assertTrue(responseBody.getNotifications().isEmpty()); }
From source file:com.devicehive.handler.notification.NotificationSearchHandlerTest.java
@Test public void shouldHandleNotificationInsertAndQueryByDeviceGuidAndNotificationName() throws Exception { NotificationSearchRequest searchRequest = new NotificationSearchRequest(); searchRequest.setGuid(notifications.get(0).getDeviceGuid()); searchRequest.setNames(Collections.singleton(notifications.get(0).getNotification())); Request request = Request.newBuilder().withBody(searchRequest).build(); CompletableFuture<Response> future = new CompletableFuture<>(); client.call(request, future::complete); Response response = future.get(10, TimeUnit.SECONDS); NotificationSearchResponse responseBody = (NotificationSearchResponse) response.getBody(); assertEquals(1, responseBody.getNotifications().size()); assertEquals(notifications.get(0), responseBody.getNotifications().get(0)); }
From source file:com.devicehive.handler.notification.NotificationSearchHandlerTest.java
@Test public void shouldFindSingleNotificationByIdAndGuid() throws Exception { NotificationSearchRequest searchRequest = new NotificationSearchRequest(); searchRequest.setId(notifications.get(0).getId()); searchRequest.setGuid(notifications.get(0).getDeviceGuid()); Request request = Request.newBuilder().withPartitionKey(notifications.get(0).getDeviceGuid()) .withBody(searchRequest).build(); CompletableFuture<Response> future = new CompletableFuture<>(); client.call(request, future::complete); Response response = future.get(10, TimeUnit.SECONDS); NotificationSearchResponse responseBody = (NotificationSearchResponse) response.getBody(); assertEquals(1, responseBody.getNotifications().size()); assertEquals(notifications.get(0), responseBody.getNotifications().get(0)); }
From source file:io.ventu.rpc.integration.rest.TestRestInvocationRoundtrip.java
@Test public void invoke_basicRoundtrip_success() throws InterruptedException, TimeoutException, ExecutionException { RemoteInvoker invoker = HttpRestInvoker.host("localhost").port(23332).ssl(false).header("APIKEY", "123") .build();/* w w w .j a v a 2 s.c om*/ try { CompletableFuture<Res> future = invoker.invoke(new Req(25), Res.class); Res res = future.get(500, TimeUnit.MILLISECONDS); assertEquals(29, res.value); } finally { invoker.close().get(500, TimeUnit.MILLISECONDS); } }
From source file:com.devicehive.rpcclient.RpcClientActionTest.java
@Test public void testListUserAction() throws Exception { ListUserRequest listUserRequest = new ListUserRequest(); listUserRequest.setLogin(UUID.randomUUID().toString()); // nonexistent login Request request = Request.newBuilder().withBody(listUserRequest).build(); CompletableFuture<Response> future = new CompletableFuture<>(); client.call(request, future::complete); Response response = future.get(10, TimeUnit.SECONDS); ListUserResponse responseBody = (ListUserResponse) response.getBody(); assertNotNull(responseBody.getUsers().isEmpty()); }
From source file:com.devicehive.rpcclient.RpcClientActionTest.java
@Test public void testListNetworkAction() throws Exception { ListNetworkRequest listNetworkRequest = new ListNetworkRequest(); listNetworkRequest.setName(UUID.randomUUID().toString()); // nonexistent name Request request = Request.newBuilder().withBody(listNetworkRequest).build(); CompletableFuture<Response> future = new CompletableFuture<>(); client.call(request, future::complete); Response response = future.get(10, TimeUnit.SECONDS); ListNetworkResponse responseBody = (ListNetworkResponse) response.getBody(); assertNotNull(responseBody.getNetworks().isEmpty()); }