List of usage examples for java.util.concurrent CountDownLatch countDown
public void countDown()
From source file:com.vmware.photon.controller.api.client.resource.DisksRestApiTest.java
@Test public void testDeleteAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); DisksApi disksApi = new DisksRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); disksApi.deleteAsync("persistentDisk", new FutureCallback<Task>() { @Override//from w w w.j av a2s .c o m public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); 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.googlecode.xmlzen.XmlSlicerTest.java
@Test public void testXmlSlicerListConcurrency() throws Exception { final CountDownLatch latch = new CountDownLatch(SLICER_ITERATIONS); final XmlSlicerList xsl = new XmlSlicerList(); xsl.add(XmlSlicer.cut("1")); xsl.add(XmlSlicer.cut("2")); xsl.add(XmlSlicer.cut("3")); for (int i = 0; i < SLICER_ITERATIONS; i++) { new Thread(new Runnable() { public void run() { assertEquals(Arrays.asList(new String[] { "1", "2", "3" }), xsl.asList()); latch.countDown(); }// w ww . j av a 2 s.c om }).start(); } latch.await(); }
From source file:com.vmware.photon.controller.api.client.resource.ImagesApiTest.java
@Test public void testDeleteImageAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ImagesApi imagesApi = new ImagesApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.deleteAsync("foo", new FutureCallback<Task>() { @Override/*from w ww . jav a 2 s. c o m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); 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.ImagesRestApiTest.java
@Test public void testDeleteImageAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); ImagesApi imagesApi = new ImagesRestApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.deleteAsync("foo", new FutureCallback<Task>() { @Override// ww w.j a v a2 s . c om public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); 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:ninja.eivind.hotsreplayuploader.files.tempwatcher.RecursiveTempWatcherTest.java
@Test public void testCallbackIsInvokedWhenRelevantFileIsDiscovered() throws Exception { CountDownLatch latch = new CountDownLatch(1); final File[] fileAccessor = new File[1]; final File tempWriteReplayFolder = new File(directories.getRemainder(), "TempWriteReplayP99"); final File target = new File(tempWriteReplayFolder, BattleLobbyWatcher.REPLAY_SERVER_BATTLELOBBY); tempWatcher.setCallback(file -> { fileAccessor[0] = file;/*from w ww.j a va2 s .com*/ latch.countDown(); }); if (!(tempWriteReplayFolder.mkdirs() && target.createNewFile())) { fail("Could not create file to drop target " + target + " in"); } if (!latch.await(50000, TimeUnit.MILLISECONDS)) { fail("Latch was not tripped."); } final String expected = target.getName(); final String actual = fileAccessor[0].getName(); assertEquals(expected, actual); }
From source file:com.hortonworks.streamline.streams.runtime.storm.bolt.rules.WindowRulesBoltTest.java
private boolean doTest(String rulesJson, int expectedExecuteCount, Function<Integer, Tuple> tupleGen) throws Exception { RulesProcessor rulesProcessor = Utils.createObjectFromJson(rulesJson, RulesProcessor.class); Window windowConfig = rulesProcessor.getRules().get(0).getWindow(); final CountDownLatch latch = new CountDownLatch(expectedExecuteCount); WindowRulesBolt wb = new WindowRulesBolt(rulesJson, RuleProcessorRuntime.ScriptType.SQL) { @Override//from w w w . j av a 2 s . c o m public void execute(TupleWindow inputWindow) { super.execute(inputWindow); latch.countDown(); } }; wb.withWindowConfig(windowConfig); WindowedBoltExecutor wbe = new WindowedBoltExecutor(wb); Map<String, Object> conf = wb.getComponentConfiguration(); conf.put("topology.message.timeout.secs", 30); wbe.prepare(conf, mockContext, mockCollector); Thread.sleep(100); for (int i = 1; i <= 20; i++) { wbe.execute(tupleGen.apply(i)); } // wait for up to 5 secs for the bolt's execute to finish return latch.await(5, TimeUnit.SECONDS); }
From source file:com.vmware.photon.controller.api.client.resource.ImagesApiTest.java
@Test public void testGetImageAsync() throws IOException, InterruptedException { final Image image = new Image(); image.setId("image1"); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(image); setupMocks(serializedTask, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImageAsync(image.getId(), new FutureCallback<Image>() { @Override/* w w w .j a v a 2 s.c o m*/ public void onSuccess(@Nullable Image result) { assertEquals(result, image); 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.ImagesRestApiTest.java
@Test public void testGetImageAsync() throws IOException, InterruptedException { final Image image = new Image(); image.setId("image1"); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(image); setupMocks(serializedTask, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesRestApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImageAsync(image.getId(), new FutureCallback<Image>() { @Override/* w ww . j a va2s . co m*/ public void onSuccess(@Nullable Image result) { assertEquals(result, image); 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.gitpitch.services.OfflineService.java
private void releaseCountDownLatch(ConcurrentHashMap<String, CountDownLatch> latchMap, String latchKey) { CountDownLatch completedLatch = latchMap.remove(latchKey); if (completedLatch != null) { completedLatch.countDown(); }//w ww. ja v a 2s .c om }
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// www.j a v a 2 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)); }