List of usage examples for java.util.concurrent CountDownLatch CountDownLatch
public CountDownLatch(int count)
From source file:com.fusesource.forge.jmstest.frontend.CommandLineClientTest.java
@Test public void testRunWithRelativeConfigLocation() throws InterruptedException { File benchmarkDir = JmsTesterUtils.getResourceAsFile("/simple"); assertTrue(benchmarkDir.isDirectory()); final CountDownLatch testPassedLatch = new CountDownLatch(1); SimpleTestExecutionContainer container = new SimpleTestExecutionContainer() { @Override//from w w w. j av a 2 s. c om protected BenchmarkCommandHandler createTestHandler() { return new DefaultCommandHandler() { public boolean handleCommand(BenchmarkCommand command) { if (command.getCommandType() == CommandTypes.SUBMIT_BENCHMARK) { testPassedLatch.countDown(); return true; } return false; } }; } }; container.start(); // exercise unit note the relative path commandLineClient.run(new String[] { "-command", "submit:src/test/resources/simple" }); assertTrue("CommandLineClient did not send a SUBMIT_BENCHMARK command", testPassedLatch.await(1, TimeUnit.SECONDS)); container.stop(); }
From source file:oz.hadoop.yarn.api.net.ApplicationContainerServerImpl.java
/** * Constructs this ClientServer with specified 'address'. * The 'expectedClientContainers' represents the amount of expected * {@link ApplicationContainerClientImpl}s to be connected * with this ClientServer. /* w w w .j a va 2 s . c om*/ * * @param address * the address to bind to * @param expectedClientContainers * expected Application Containers * @param finite * whether the YARN application using finite or reusable Application Containers * @param onDisconnectProcess * additional process implemented as {@link Runnable} to be executed during disconnect */ public ApplicationContainerServerImpl(InetSocketAddress address, int expectedClientContainers, boolean finite, Runnable onDisconnectTask) { super(address, true, onDisconnectTask); Assert.isTrue(expectedClientContainers > 0, "'expectedClientContainers' must be > 0"); this.expectedClientContainers = expectedClientContainers; this.replyCallbackMap = new ConcurrentHashMap<SelectionKey, ReplyPostProcessor>(); this.expectedClientContainersMonitor = new CountDownLatch(expectedClientContainers + 1); this.containerDelegates = new HashMap<SelectionKey, ContainerDelegate>(); this.finite = finite; }
From source file:edu.umn.msi.tropix.proteomics.cagrid.IntegrationTestBase.java
protected boolean pollJob(Job job) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); class Listener implements JobUpdateListener { private boolean finishedProperly = false; public void jobComplete(final Ticket ticket, final boolean finishedProperly, final Status finalStatus) { this.finishedProperly = finishedProperly; latch.countDown();/*ww w. j a v a 2 s. c om*/ } public void update(final Ticket ticket, final Status status) { final QueueStage stage = QueueStage.fromStatusUpdateList(status); LOG.info("Queue stage is " + stage.getStageEnumerationValue().getValue()); } } final Listener listener = new Listener(); dListener.setJobUpdateListener(listener); jobPoller.pollJob(job); latch.await(); return listener.finishedProperly; }
From source file:com.networknt.security.JwtVerifyHandlerTest.java
@Test public void testWithRightScopeInIdToken() throws Exception { final Http2Client client = Http2Client.getInstance(); final CountDownLatch latch = new CountDownLatch(1); final ClientConnection connection; try {//w ww .java 2s. c o m connection = client.connect(new URI("http://localhost:8080"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.EMPTY).get(); } catch (Exception e) { throw new ClientException(e); } final AtomicReference<ClientResponse> reference = new AtomicReference<>(); try { ClientRequest request = new ClientRequest().setPath("/v2/pet/111").setMethod(Methods.GET); request.getRequestHeaders().put(Headers.AUTHORIZATION, "Bearer eyJraWQiOiIxMDAiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ1cm46Y29tOm5ldHdvcmtudDpvYXV0aDI6djEiLCJhdWQiOiJ1cm46Y29tLm5ldHdvcmtudCIsImV4cCI6MTgwNTEzNjU1MSwianRpIjoiV0Z1VVZneE83dmxKUm5XUlllMjE1dyIsImlhdCI6MTQ4OTc3NjU1MSwibmJmIjoxNDg5Nzc2NDMxLCJ2ZXJzaW9uIjoiMS4wIiwidXNlcl9pZCI6InN0ZXZlIiwidXNlcl90eXBlIjoiRU1QTE9ZRUUiLCJjbGllbnRfaWQiOiJmN2Q0MjM0OC1jNjQ3LTRlZmItYTUyZC00YzU3ODc0MjFlNzIiLCJzY29wZSI6WyJ3cml0ZTpwZXRzIiwicmVhZDpwZXRzIl19.ZDlD_JbtHMqfx8EWOlOXI0zFGjB_pJ6yXWpxoE03o2yQnCUq1zypaDTJWSiy-BPIiQAxwDV09L3SN7RsOcgJ3y2LLFhgqIXhcHoePxoz52LPOeeiihG2kcrgBm-_VMq0uUykLrD-ljSmmSm1Hai_dx0WiYGAEJf-TiD1mgzIUTlhogYrjFKlp2NaYHxr7yjzEGefKv4DWdjtlEMmX_cXkqPgxra_omzyxeWE-n0b7f_r7Hr5HkxnmZ23gkZcvFXfVWKEp2t0_dYmNCbSVDavAjNanvmWsNThYNglFRvF0lm8kl7jkfMO1pTa0WLcBLvOO2y_jRWjieFCrc0ksbIrXA"); connection.sendRequest(request, client.createClientCallback(reference, latch)); latch.await(); } catch (Exception e) { logger.error("Exception: ", e); throw new ClientException(e); } finally { IoUtils.safeClose(connection); } int statusCode = reference.get().getResponseCode(); Assert.assertEquals(200, statusCode); if (statusCode == 200) { Assert.assertNotNull(reference.get().getAttachment(Http2Client.RESPONSE_BODY)); } }
From source file:com.navercorp.pinpoint.profiler.sender.NioUdpDataSenderTest.java
private boolean sendMessage_getLimit(TBase tbase, long waitTimeMillis) throws InterruptedException { final AtomicBoolean limitCounter = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); NioUDPDataSender sender = newNioUdpDataSender(); try {/*from w w w .java 2 s . c om*/ sender.send(tbase); latch.await(waitTimeMillis, TimeUnit.MILLISECONDS); } finally { sender.stop(); } return limitCounter.get(); }
From source file:de.fun2code.google.cloudprint.push.PushReceiver.java
/** * Constructor//from www . jav a 2 s . com * * @param resourceName Descriptive name of the ressource. */ public PushReceiver(String resourceName) { this.resourceName = resourceName != null ? resourceName : ""; latch = new CountDownLatch(1); listeners = new ArrayList<PushListener>(); }
From source file:ca.cmput301w14t09.elasticSearch.ElasticSearchOperations.java
/** * pullThreads returns the list of top comments. * Tested and verified.//from w w w. j a v a2s .co m * @return list of names of Threads. * @throws InterruptedException */ public static ArrayList<Comment> pullThreads() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final ArrayList<Comment> commentList = new ArrayList<Comment>(); if (GSON == null) constructGson(); Thread thread = new Thread() { @Override public void run() { HttpClient client = new DefaultHttpClient(); try { HttpPost searchRequest = new HttpPost(searchAddress); String query = "{\"query\" : {\"query_string\" : {\"default_field\" : \"topComment\",\"query\" : \"true\"}}}"; StringEntity stringentity = new StringEntity(query); searchRequest.setEntity(stringentity); HttpResponse response = client.execute(searchRequest); String json = getEntityContent(response); Type elasticSearchSearchResponseType = new TypeToken<ElasticSearchSearchResponse<Comment>>() { }.getType(); ElasticSearchSearchResponse<Comment> esResponse = GSON.fromJson(json, elasticSearchSearchResponseType); for (ElasticSearchResponse<Comment> r : esResponse.getHits()) { Comment topComment = r.getSource(); commentList.add(topComment); } // Sort by latest dated element. Collections.sort(commentList); Collections.reverse(commentList); latch.countDown(); } catch (Exception e) { e.printStackTrace(); } } }; thread.start(); latch.await(); return commentList; }
From source file:com.mgmtp.perfload.core.daemon.LtDaemon.java
public static void shutdownDaemon(final int port) { final CountDownLatch latch = new CountDownLatch(1); Client client = new DefaultClient("shutdownClient", "localhost", port); client.addClientMessageListener(new ClientMessageListener() { @Override/*w w w. j ava2 s. c om*/ public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) { final Payload payload = (Payload) e.getMessage(); if (payload.getPayloadType() == PayloadType.SHUTDOWN_DAEMON) { log().info("Successfully requested shutdown."); latch.countDown(); } } }); log().info("Connecting to daemon at port {}...", port); client.connect(); if (client.isConnected()) { client.sendMessage(new Payload(PayloadType.SHUTDOWN_DAEMON)); client.disconnect(); } else { log().info("Could not connect to daemon. Daemon probably not running."); } log().info("Good bye."); }
From source file:com.auditbucket.test.functional.TestForceDeadlock.java
@Test public void tagsUnderLoad() throws Exception { cleanUpGraph(); // No transaction so need to clear down the graph String monowai = "Monowai"; regService.registerSystemUser(new RegistrationBean(monowai, mike, "bah")); SecurityContextHolder.getContext().setAuthentication(authMike); Fortress fortress = fortressService.registerFortress("auditTest" + System.currentTimeMillis()); CountDownLatch latch = new CountDownLatch(4); List<TagInputBean> tags = getTags(10); Map<Integer, TagRunner> runners = new HashMap<>(); int threadMax = 3; boolean worked = true; for (int i = 0; i < threadMax; i++) { runners.put(i, addTagRunner(fortress, 5, tags, latch)); }// w w w. j a v a 2s. co m //latch.await(); for (int i = 0; i < threadMax; i++) { while (runners.get(i) == null || !runners.get(i).isDone()) { Thread.yield(); } assertEquals("Error occurred creating tags under load", true, runners.get(i).isWorked()); } assertEquals(true, worked); }
From source file:com.qualys.jserf.SerfClientIT.java
@Test(timeout = 10000) public void testMembers() throws Exception { while (!client.isConnected()) { Thread.sleep(500);/*from www . j a v a 2 s.co m*/ } final boolean[] callbackInvoked = { false }; final CountDownLatch latch = new CountDownLatch(1); SerfResponseCallBack<MembersResponseBody> callBack = new SerfResponseCallBack<MembersResponseBody>() { @Override public void call(SerfResponse<MembersResponseBody> response) { log.debug("Received call back with sequence {}", response.getHeader().getSeq()); callbackInvoked[0] = true; assertNotNull(response.getHeader()); assertEquals(StringUtils.EMPTY, response.getHeader().getError()); assertEquals(MembersResponseBody.class, response.getBody().getClass()); assertNotNull(response.getBody()); MembersResponseBody body = response.getBody(); log.debug("body={}", body); assertNotNull(body.getMembers()); assertTrue(body.getMembers().size() > 0); //don't count down unless all the asserts pass latch.countDown(); } }; SerfRequest request = SerfRequests.members(callBack); client.makeRpc(request); latch.await(); assertTrue(callbackInvoked[0]); }