List of usage examples for java.util.concurrent CountDownLatch await
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
From source file:com.vmware.photon.controller.deployer.dcp.DeployerDcpServiceHostTest.java
private void waitForServicesStartup(DeployerDcpServiceHost host) throws TimeoutException, InterruptedException, NoSuchFieldException, IllegalAccessException { serviceSelfLinks = ServiceHostUtils.getServiceSelfLinks( DeployerDcpServiceHost.FACTORY_SERVICE_FIELD_NAME_SELF_LINK, DeployerDcpServiceHost.FACTORY_SERVICES); final CountDownLatch latch = new CountDownLatch(serviceSelfLinks.size()); Operation.CompletionHandler handler = new Operation.CompletionHandler() { @Override/*from w w w.jav a2s . co m*/ public void handle(Operation completedOp, Throwable failure) { latch.countDown(); } }; String[] links = new String[serviceSelfLinks.size()]; host.registerForServiceAvailability(handler, serviceSelfLinks.toArray(links)); if (!latch.await(10, TimeUnit.SECONDS)) { throw new TimeoutException(); } }
From source file:com.vmware.photon.controller.api.client.resource.DisksApiTest.java
@Test public void testGetDiskAsync() throws IOException, InterruptedException { final PersistentDisk persistentDisk = new PersistentDisk(); persistentDisk.setId("persistentDisk"); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(persistentDisk); setupMocks(serializedTask, HttpStatus.SC_OK); DisksApi disksApi = new DisksApi(restClient); final CountDownLatch latch = new CountDownLatch(1); disksApi.getDiskAsync("disk1", new FutureCallback<PersistentDisk>() { @Override/*from ww w .jav a2 s . c o m*/ public void onSuccess(@Nullable PersistentDisk result) { assertEquals(result, persistentDisk); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.DisksRestApiTest.java
@Test public void testGetDiskAsync() throws IOException, InterruptedException { final PersistentDisk persistentDisk = new PersistentDisk(); persistentDisk.setId("persistentDisk"); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(persistentDisk); setupMocks(serializedTask, HttpStatus.SC_OK); DisksApi disksApi = new DisksRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); disksApi.getDiskAsync("disk1", new FutureCallback<PersistentDisk>() { @Override/*from w w w . j a v a2s.c om*/ public void onSuccess(@Nullable PersistentDisk result) { assertEquals(result, persistentDisk); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java
@Test public void testDeleteTransportNode() throws IOException, InterruptedException { setupMocks(null, HttpStatus.SC_OK);//from w ww . java 2s. c o m FabricApi client = new FabricApi(restClient); final CountDownLatch latch = new CountDownLatch(1); client.deleteTransportNode("id", new com.google.common.util.concurrent.FutureCallback<Void>() { @Override public void onSuccess(Void result) { latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java
@Test public void testDeleteTransportZone() throws IOException, InterruptedException { setupMocks(null, HttpStatus.SC_OK);/*from w ww . j a v a 2 s.c om*/ FabricApi client = new FabricApi(restClient); final CountDownLatch latch = new CountDownLatch(1); client.deleteTransportZone("id", new com.google.common.util.concurrent.FutureCallback<Void>() { @Override public void onSuccess(Void result) { latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.amazonaws.eclipse.core.accounts.profiles.SdkCredentialsFileContentMonitorTest.java
@Test public void testMonitorInStoppedStatus() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); SdkCredentialsFileContentMonitor monitor = new SdkCredentialsFileContentMonitor(targetFile, MONITOR_POLLING_INTERVAL_MILLIS, new FileAlterationListenerAdaptor() { @Override//from w ww .j ava 2s .c o m public void onFileChange(final File changedFile) { System.err.println("stopped"); latch.countDown(); } }); monitor.setDebugMode(true); monitor.start(); monitor.stop(); touch(targetFile); long waitTime = MONITOR_POLLING_INTERVAL_MILLIS * 2; Assert.assertFalse("Who counted it down to zero???", latch.await(waitTime, TimeUnit.MILLISECONDS)); }
From source file:com.vmware.photon.controller.nsxclient.apis.FabricApiTest.java
@Test public void testUnregisterFabricNode() throws IOException, InterruptedException { setupMocks(null, HttpStatus.SC_OK);//from ww w .j a va 2 s .co m FabricApi client = new FabricApi(restClient); final CountDownLatch latch = new CountDownLatch(1); client.unregisterFabricNode("nodeId", new com.google.common.util.concurrent.FutureCallback<Void>() { @Override public void onSuccess(Void result) { latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.ResourceTicketApiTest.java
@Test public void testGetResourceTicketTasksAsync() throws IOException, InterruptedException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); final ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(taskResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); ResourceTicketApi resourceTicketApi = new ResourceTicketApi(restClient); final CountDownLatch latch = new CountDownLatch(1); resourceTicketApi.getTasksForResourceTicketAsync("foo", new FutureCallback<ResourceList<Task>>() { @Override/* w ww.j a va2s. co m*/ public void onSuccess(@Nullable ResourceList<Task> result) { assertEquals(result.getItems(), taskResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); ; }
From source file:com.vmware.photon.controller.api.client.resource.ResourceTicketRestApiTest.java
@Test public void testGetResourceTicketTasksAsync() throws IOException, InterruptedException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); final ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(taskResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); ResourceTicketApi resourceTicketApi = new ResourceTicketRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); resourceTicketApi.getTasksForResourceTicketAsync("foo", new FutureCallback<ResourceList<Task>>() { @Override/* www .j ava2 s.c om*/ public void onSuccess(@Nullable ResourceList<Task> result) { assertEquals(result.getItems(), taskResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); ; }