List of usage examples for java.util.concurrent CountDownLatch await
public void await() throws InterruptedException
From source file:com.brienwheeler.apps.main.ContextMainTest.java
@Test public void testShutdownCommand() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); TestContextMain main = new TestContextMain(new String[] { N, C, TestDataConstants.RMAP_CTX_CLASSPATH }, latch);/*from www . j av a 2 s . c om*/ TestRunner testRunner = new TestRunner(main); testRunner.start(); latch.await(); assertLaunchCount(main, 1); main.shutdown(); testRunner.join(); }
From source file:com.brienwheeler.apps.main.ContextMainTest.java
@Test public void testShutdownInternal() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); TestContextMain main = new TestContextMain(new String[] { N, C, TestDataConstants.RMAP_CTX_CLASSPATH }, latch);//from ww w.ja v a 2 s . co m TestRunner testRunner = new TestRunner(main); testRunner.start(); latch.await(); assertLaunchCount(main, 1); getLaunchedContext(main, 0).close(); testRunner.join(); }
From source file:com.google.code.fqueue.memcached.TestFqueueServer.java
public void mutiThreadGet() throws InterruptedException, TimeoutException, MemcachedException { int threadCount = 8; ExecutorService pool = Executors.newFixedThreadPool(threadCount); CountDownLatch latch = new CountDownLatch(threadCount); // MemcachedBenchJob.test = tester; MemcachedTestGet[] muti = new MemcachedTestGet[threadCount]; for (int i = 0; i < threadCount; i++) { muti[i] = new MemcachedTestGet(latch); }//w w w. ja va 2 s .c o m log.info("start"); long start = System.currentTimeMillis(); for (int i = 0; i < threadCount; i++) { pool.execute(muti[i]); } latch.await(); long spend = System.currentTimeMillis() - start; log.info(threadCount + "threads ?:" + threadCount * 10000); assertEquals(0, getSize()); }
From source file:ufo.remote.calls.benchmark.client.caller.vertx.VertxClusterTester.java
@Override protected void startTest(final TesterResult result) { EventBus bus = vertx.eventBus();/*from ww w . ja va2 s . c o m*/ CountDownLatch latch = new CountDownLatch(result.totalCalls); AtomicInteger failures = new AtomicInteger(0); for (int i = 0; i < result.totalCalls; i++) { bus.send("echo", result.message, (AsyncResult<Message<String>> response) -> { if (response.failed()) { failures.incrementAndGet(); } if (logger.isDebugEnabled()) { logger.debug("Received [{}]", response.result().body()); } latch.countDown(); }); } try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:com.brienwheeler.apps.main.ContextMainTest.java
@Test public void testContextWithProps() throws InterruptedException { PropertiesTestUtils.clearAllTestSystemProperties(); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); CountDownLatch latch = new CountDownLatch(1); TestContextMain main = new TestContextMain(new String[] { C, TestDataConstants.RMAP_CTX_WITH_PROPS }, latch);//from w w w .j a va 2 s.c o m TestRunner testRunner = new TestRunner(main); testRunner.start(); latch.await(); assertLaunchCount(main, 1); getLaunchedContext(main, 0).close(); testRunner.join(); Assert.assertEquals(TestDataConstants.PROPS_FILE1_VALUE, System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertEquals(TestDataConstants.PROPS_FILE2_VALUE, System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); }
From source file:info.archinnov.achilles.it.TestAsyncCRUDSimpleEntity.java
@Test public void should_delete_instance_async() throws Exception { //Given//from w w w .jav a2s. c o m final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); final Date date = buildDateKey(); final SimpleEntity entity = new SimpleEntity(id, date, "value"); scriptExecutor.executeScriptTemplate("SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple")); final CountDownLatch latch = new CountDownLatch(1); final CassandraLogAsserter logAsserter = new CassandraLogAsserter(); logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n"); //When final CompletableFuture<ExecutionInfo> future = manager.crud().delete(entity) .withResultSetAsyncListener(rs -> { LOGGER.info(CALLED); latch.countDown(); return rs; }).executeAsyncWithStats(); //Then latch.await(); logAsserter.assertContains("Called"); final List<Row> rows = session.execute("SELECT * FROM simple WHERE id = " + id).all(); assertThat(rows).isEmpty(); final ExecutionInfo executionInfo = future.get(); assertThat(executionInfo.getQueriedHost().isUp()).isTrue(); }
From source file:com.brienwheeler.apps.main.ContextMainTest.java
@Test public void testContextWithProps2() throws InterruptedException { PropertiesTestUtils.clearAllTestSystemProperties(); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); CountDownLatch latch = new CountDownLatch(1); TestContextMain main = new TestContextMain(new String[] { C, TestDataConstants.RMAP_CTX_WITH_PROPS2 }, latch);//www . j av a 2 s . c o m TestRunner testRunner = new TestRunner(main); testRunner.start(); latch.await(); assertLaunchCount(main, 2); main.shutdown(); testRunner.join(); Assert.assertEquals(TestDataConstants.PROPS_FILE1_VALUE, System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertEquals(TestDataConstants.PROPS_FILE2_VALUE, System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); }
From source file:com.brienwheeler.apps.main.ContextMainTest.java
@Test public void testContextWithProps3() throws InterruptedException { PropertiesTestUtils.clearAllTestSystemProperties(); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); CountDownLatch latch = new CountDownLatch(1); TestContextMain main = new TestContextMain(new String[] { C, TestDataConstants.RMAP_CTX_WITH_PROPS3 }, latch);/*from w w w.j a v a2s.com*/ TestRunner testRunner = new TestRunner(main); testRunner.start(); latch.await(); assertLaunchCount(main, 2); main.shutdown(); testRunner.join(); Assert.assertEquals(TestDataConstants.PROPS_FILE1_VALUE, System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertEquals(TestDataConstants.PROPS_FILE2_VALUE, System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); }
From source file:com.brienwheeler.apps.main.ContextMainTest.java
@Test public void testContextWithProps4() throws InterruptedException { PropertiesTestUtils.clearAllTestSystemProperties(); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); CountDownLatch latch = new CountDownLatch(1); TestContextMain main = new TestContextMain(new String[] { C, TestDataConstants.RMAP_CTX_WITH_PROPS4 }, latch);//from w w w . ja v a 2 s .c o m TestRunner testRunner = new TestRunner(main); testRunner.start(); latch.await(); assertLaunchCount(main, 1); main.shutdown(); testRunner.join(); Assert.assertEquals(TestDataConstants.PROPS_FILE1_VALUE, System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); Assert.assertEquals(TestDataConstants.PROPS_FILE2_VALUE, System.getProperty(TestDataConstants.PROPS_FILE2_PROP)); }
From source file:com.github.notizklotz.derbunddownloader.download.IssueDownloadService.java
@ServiceAction public void downloadIssue(int day, int month, int year) { Log.i(LOG_TAG, "Handling download intent"); try {/*from w ww .jav a 2 s. co m*/ boolean connected; final boolean wifiOnly = Settings.isWifiOnly(getApplicationContext()); if (wifiOnly) { connected = waitForWifiConnection(); if (!connected) { notifyUser(getText(R.string.download_wifi_connection_failed), getText(R.string.download_wifi_connection_failed_text), R.drawable.ic_stat_newspaper); } } else { NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); connected = activeNetworkInfo != null && activeNetworkInfo.isConnected(); if (!connected) { notifyUser(getText(R.string.download_connection_failed), getText(R.string.download_connection_failed_text), R.drawable.ic_stat_newspaper); } } if (connected) { if (!checkUserAccount()) { notifyUser(getText(R.string.download_login_failed), getText(R.string.download_login_failed_text), R.drawable.ic_stat_newspaper); } else { final LocalDate issueDate = new LocalDate(day, month, year); fetchThumbnail(issueDate); final CountDownLatch downloadDoneSignal = new CountDownLatch(1); receiver = new DownloadCompletedBroadcastReceiver(downloadDoneSignal); registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); try { String title = startDownload(issueDate, wifiOnly); downloadDoneSignal.await(); notifyUser(title, getString(R.string.download_completed), R.drawable.ic_stat_newspaper); } catch (InterruptedException e) { Log.wtf(LOG_TAG, "Interrupted while waiting for the downloadDoneSignal"); } } } } catch (Exception e) { notifyUser(getText(R.string.download_service_error), getText(R.string.download_service_error_text) + " " + e.getMessage(), R.drawable.ic_stat_newspaper); } finally { cleanup(); } }