List of usage examples for java.util.concurrent CountDownLatch countDown
public void countDown()
From source file:ninja.eivind.hotsreplayuploader.files.tempwatcher.RecursiveTempWatcherTest.java
@Test public void testSetCallbackIsAppliedProperly() throws Exception { CountDownLatch latch = new CountDownLatch(1); tempWatcher.setCallback(file -> latch.countDown()); TempWatcher lastChild = getChildRecursively(tempWatcher); Consumer<File> callback = lastChild.getCallback(); callback.accept(null);//from w w w.j a va 2s. co m if (!latch.await(500, TimeUnit.MILLISECONDS)) { throw new TimeoutException("Latch was not tripped."); } }
From source file:uk.co.sdev.undertow.rx.services.offers.OffersServiceTest.java
@Test public void shouldReturnObservableOfOffers() throws Exception { OffersService service = new OffersService(mapper, client, "http://localhost:9101/offers"); stubGet("/offers?count=2", Arrays.asList(new Offer("offer1", "description1", "offer1.jpg"), new Offer("offer2", "description2", "offer2.jpg"))); List<Offer> offers = new ArrayList<>(); List<Throwable> throwables = new ArrayList<>(); CountDownLatch finished = new CountDownLatch(1); Observable<Offer> offer = service.offers(2); new Thread(() -> offer.subscribe(o -> offers.add(o), t -> throwables.add(t), () -> finished.countDown())) .start();// w w w. j a v a 2s.com finished.await(5, TimeUnit.SECONDS); assertThat(offers.size(), is(2)); assertThat(offers.get(0).getTitle(), is("offer1")); assertThat(offers.get(1).getTitle(), is("offer2")); }
From source file:com.playhaven.android.diagnostic.test.PHTestCase.java
public void markReadyForTesting(Object toTest) { String name = toTest.getClass().getSimpleName(); CountDownLatch latch = latches.get(name); if (latch != null) { latch.countDown(); latches.put(name, latch);//from w w w .j a v a 2 s . c o m } }
From source file:se.vgregion.pubsub.loadtesting.LoadtestingServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // find the ID in the feed content BufferedReader reader = req.getReader(); String line = reader.readLine(); while (line != null) { int start = line.indexOf("uuid:"); if (start > -1) { int end = line.indexOf("<", start); String id = line.substring(start + 5, end); UUID uuid = UUID.fromString(id); // found id, now try to count down latch CountDownLatch latch = publications.get(uuid); if (latch != null) { latch.countDown(); publications.remove(id); return; } else { throw new RuntimeException("Could not find latch"); }/*w w w . j a va 2 s . c o m*/ } line = reader.readLine(); } }
From source file:com.smartnsoft.hackathon.directenergie.ws.NetatmoServices.java
public List<Station> getDevicesList() throws InterruptedException { final CountDownLatch deviceWait = new CountDownLatch(1); deviceWait.countDown(); getDevicesList(new NetatmoResponseHandler(NetatmoServices.this, NetatmoResponseHandler.REQUEST_GET_DEVICES_LIST, null) { @Override//from w w w . java 2 s . c om public void onGetDevicesListResponse(final List<Station> devices) { devicesList = devices; try { deviceWait.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }); return devicesList; // synchronized (devicesList) // { // getDevicesList(new NetatmoResponseHandler(NetatmoServices.this, NetatmoResponseHandler.REQUEST_GET_DEVICES_LIST, null) // { // @Override // public void onGetDevicesListResponse(final List<Station> devices) // { // devicesList = devices; // } // }); // return devicesList; // } }
From source file:ch.cyberduck.core.io.ThreadedStreamCloser.java
@Override public void close(final InputStream in) throws ConnectionTimeoutException { final CountDownLatch signal = new CountDownLatch(1); threadFactory.newThread(new Runnable() { @Override/* w ww .j ava 2s. c om*/ public void run() { IOUtils.closeQuietly(in); signal.countDown(); } }).start(); try { if (!signal.await(preferences.getInteger("connection.timeout.seconds"), TimeUnit.SECONDS)) { throw new StreamCloseTimeoutException("Timeout closing input stream", null); } } catch (InterruptedException e) { throw new ConnectionTimeoutException(e.getMessage(), e); } }
From source file:ch.cyberduck.core.io.ThreadedStreamCloser.java
@Override public void close(final OutputStream out) throws ConnectionTimeoutException { final CountDownLatch signal = new CountDownLatch(1); threadFactory.newThread(new Runnable() { @Override/*from w w w . j a v a2 s . co m*/ public void run() { IOUtils.closeQuietly(out); signal.countDown(); } }).start(); try { if (!signal.await(preferences.getInteger("connection.timeout.seconds"), TimeUnit.SECONDS)) { throw new StreamCloseTimeoutException("Timeout closing output stream", null); } } catch (InterruptedException e) { throw new ConnectionTimeoutException(e.getMessage(), e); } }
From source file:org.springframework.cloud.stream.FluxTest.java
@Test public void testSimpleSubscriber() throws Exception { final CountDownLatch latch = new CountDownLatch(10); emitter.subscribe(s -> {// ww w . j ava 2 s. c o m System.out.println(s); latch.countDown(); }); latch.await(); }
From source file:com.ericsson.gerrit.plugins.highavailability.cache.CacheEvictionIT.java
@Test @UseLocalDisk/* www .ja v a 2 s .c o m*/ @GlobalPluginConfig(pluginName = "high-availability", name = "peerInfo.static.url", value = URL) @GlobalPluginConfig(pluginName = "high-availability", name = "http.retryInterval", value = "100") public void flushAndSendPost() throws Exception { final String flushRequest = "/plugins/high-availability/cache/" + Constants.PROJECTS; final CountDownLatch expectedRequestLatch = new CountDownLatch(1); wireMockRule.addMockServiceRequestListener((request, response) -> { if (request.getAbsoluteUrl().contains(flushRequest)) { expectedRequestLatch.countDown(); } }); adminSshSession.exec("gerrit flush-caches --cache " + Constants.PROJECTS); assertThat(expectedRequestLatch.await(5, TimeUnit.SECONDS)).isTrue(); verify(postRequestedFor(urlEqualTo(flushRequest))); }
From source file:com.ericsson.gerrit.plugins.highavailability.cache.ProjectListIT.java
@Test @UseLocalDisk/*from w w w . ja v a2s . c om*/ @GlobalPluginConfig(pluginName = "high-availability", name = "peerInfo.static.url", value = URL) @GlobalPluginConfig(pluginName = "high-availability", name = "http.retryInterval", value = "100") public void addToProjectListAreForwarded() throws Exception { String createdProjectEncoded = Url.encode("org-a/some-project"); String expectedRequest = "/plugins/high-availability/cache/" + Constants.PROJECT_LIST + "/" + createdProjectEncoded; CountDownLatch expectedRequestLatch = new CountDownLatch(1); wireMockRule.addMockServiceRequestListener((request, response) -> { if (request.getAbsoluteUrl().contains(expectedRequest)) { expectedRequestLatch.countDown(); } }); adminRestSession.put("/projects/" + createdProjectEncoded).assertCreated(); assertThat(expectedRequestLatch.await(5, TimeUnit.SECONDS)).isTrue(); verify(postRequestedFor(urlEqualTo(expectedRequest))); }