@Test public void testAsyncWrongUri() throws Exception { assertEquals(-1, Main.runClient(new String[]{"req=1", "mode=async", "uri=http: }
static int runClient(final String[] args) { final Config config = Config.parse(args); System.out.println(String.format("\nStarting to execute %d requests:\n", config.requests)); final Client client = ClientBuilder.newClient(); final WebTarget echoResource = client.target(config.baseUri).path("long-running/{mode}/{echo}") .resolveTemplate("mode", (config.sync) ? "sync" : "async"); final CountDownLatch latch = new CountDownLatch(config.requests); final Queue<String> errors = new ConcurrentLinkedQueue<String>(); final AtomicInteger requestCounter = new AtomicInteger(0); final long tic = System.currentTimeMillis(); for (int i = 0; i < config.requests; i++) { final int reqId = i; echoResource.resolveTemplate("echo", reqId).request().async().get(new InvocationCallback<String>() { private final AtomicInteger retries = new AtomicInteger(0); @Override public void completed(String response) { final String requestId = Integer.toString(reqId); if (requestId.equals(response)) { System.out.print("*"); requestCounter.incrementAndGet(); } else { System.out.print("!"); errors.offer(String.format("Echo response '%s' not equal to request '%s'", response, requestId)); } latch.countDown(); } @Override public void failed(Throwable error) { if (error.getCause() instanceof IOException && retries.getAndIncrement() < 3) { echoResource.resolveTemplate("echo", reqId).request().async().get(this); } else { System.out.print("!"); errors.offer(String.format("Request '%d' has failed: %s", reqId, error.toString())); latch.countDown(); } } }); } try { if (!latch.await(60, TimeUnit.SECONDS)) { errors.offer("Waiting for requests to complete has timed out."); } } catch (InterruptedException e) { errors.offer("Waiting for requests to complete has been interrupted."); } final long toc = System.currentTimeMillis(); System.out.println(String.format("\n\nExecution finished in %d ms.\nSuccess rate: %6.2f %%", toc - tic, ((double) requestCounter.get() / config.requests) * 100)); if (errors.size() > 0) { System.out.println("Following errors occurred during the request execution"); for (String error : errors) { System.out.println("\t" + error); } } client.close(); return errors.size() > 0 ? -1 : 0; }
Main { static int runClient(final String[] args) { final Config config = Config.parse(args); System.out.println(String.format("\nStarting to execute %d requests:\n", config.requests)); final Client client = ClientBuilder.newClient(); final WebTarget echoResource = client.target(config.baseUri).path("long-running/{mode}/{echo}") .resolveTemplate("mode", (config.sync) ? "sync" : "async"); final CountDownLatch latch = new CountDownLatch(config.requests); final Queue<String> errors = new ConcurrentLinkedQueue<String>(); final AtomicInteger requestCounter = new AtomicInteger(0); final long tic = System.currentTimeMillis(); for (int i = 0; i < config.requests; i++) { final int reqId = i; echoResource.resolveTemplate("echo", reqId).request().async().get(new InvocationCallback<String>() { private final AtomicInteger retries = new AtomicInteger(0); @Override public void completed(String response) { final String requestId = Integer.toString(reqId); if (requestId.equals(response)) { System.out.print("*"); requestCounter.incrementAndGet(); } else { System.out.print("!"); errors.offer(String.format("Echo response '%s' not equal to request '%s'", response, requestId)); } latch.countDown(); } @Override public void failed(Throwable error) { if (error.getCause() instanceof IOException && retries.getAndIncrement() < 3) { echoResource.resolveTemplate("echo", reqId).request().async().get(this); } else { System.out.print("!"); errors.offer(String.format("Request '%d' has failed: %s", reqId, error.toString())); latch.countDown(); } } }); } try { if (!latch.await(60, TimeUnit.SECONDS)) { errors.offer("Waiting for requests to complete has timed out."); } } catch (InterruptedException e) { errors.offer("Waiting for requests to complete has been interrupted."); } final long toc = System.currentTimeMillis(); System.out.println(String.format("\n\nExecution finished in %d ms.\nSuccess rate: %6.2f %%", toc - tic, ((double) requestCounter.get() / config.requests) * 100)); if (errors.size() > 0) { System.out.println("Following errors occurred during the request execution"); for (String error : errors) { System.out.println("\t" + error); } } client.close(); return errors.size() > 0 ? -1 : 0; } }
Main { static int runClient(final String[] args) { final Config config = Config.parse(args); System.out.println(String.format("\nStarting to execute %d requests:\n", config.requests)); final Client client = ClientBuilder.newClient(); final WebTarget echoResource = client.target(config.baseUri).path("long-running/{mode}/{echo}") .resolveTemplate("mode", (config.sync) ? "sync" : "async"); final CountDownLatch latch = new CountDownLatch(config.requests); final Queue<String> errors = new ConcurrentLinkedQueue<String>(); final AtomicInteger requestCounter = new AtomicInteger(0); final long tic = System.currentTimeMillis(); for (int i = 0; i < config.requests; i++) { final int reqId = i; echoResource.resolveTemplate("echo", reqId).request().async().get(new InvocationCallback<String>() { private final AtomicInteger retries = new AtomicInteger(0); @Override public void completed(String response) { final String requestId = Integer.toString(reqId); if (requestId.equals(response)) { System.out.print("*"); requestCounter.incrementAndGet(); } else { System.out.print("!"); errors.offer(String.format("Echo response '%s' not equal to request '%s'", response, requestId)); } latch.countDown(); } @Override public void failed(Throwable error) { if (error.getCause() instanceof IOException && retries.getAndIncrement() < 3) { echoResource.resolveTemplate("echo", reqId).request().async().get(this); } else { System.out.print("!"); errors.offer(String.format("Request '%d' has failed: %s", reqId, error.toString())); latch.countDown(); } } }); } try { if (!latch.await(60, TimeUnit.SECONDS)) { errors.offer("Waiting for requests to complete has timed out."); } } catch (InterruptedException e) { errors.offer("Waiting for requests to complete has been interrupted."); } final long toc = System.currentTimeMillis(); System.out.println(String.format("\n\nExecution finished in %d ms.\nSuccess rate: %6.2f %%", toc - tic, ((double) requestCounter.get() / config.requests) * 100)); if (errors.size() > 0) { System.out.println("Following errors occurred during the request execution"); for (String error : errors) { System.out.println("\t" + error); } } client.close(); return errors.size() > 0 ? -1 : 0; }  }
Main { static int runClient(final String[] args) { final Config config = Config.parse(args); System.out.println(String.format("\nStarting to execute %d requests:\n", config.requests)); final Client client = ClientBuilder.newClient(); final WebTarget echoResource = client.target(config.baseUri).path("long-running/{mode}/{echo}") .resolveTemplate("mode", (config.sync) ? "sync" : "async"); final CountDownLatch latch = new CountDownLatch(config.requests); final Queue<String> errors = new ConcurrentLinkedQueue<String>(); final AtomicInteger requestCounter = new AtomicInteger(0); final long tic = System.currentTimeMillis(); for (int i = 0; i < config.requests; i++) { final int reqId = i; echoResource.resolveTemplate("echo", reqId).request().async().get(new InvocationCallback<String>() { private final AtomicInteger retries = new AtomicInteger(0); @Override public void completed(String response) { final String requestId = Integer.toString(reqId); if (requestId.equals(response)) { System.out.print("*"); requestCounter.incrementAndGet(); } else { System.out.print("!"); errors.offer(String.format("Echo response '%s' not equal to request '%s'", response, requestId)); } latch.countDown(); } @Override public void failed(Throwable error) { if (error.getCause() instanceof IOException && retries.getAndIncrement() < 3) { echoResource.resolveTemplate("echo", reqId).request().async().get(this); } else { System.out.print("!"); errors.offer(String.format("Request '%d' has failed: %s", reqId, error.toString())); latch.countDown(); } } }); } try { if (!latch.await(60, TimeUnit.SECONDS)) { errors.offer("Waiting for requests to complete has timed out."); } } catch (InterruptedException e) { errors.offer("Waiting for requests to complete has been interrupted."); } final long toc = System.currentTimeMillis(); System.out.println(String.format("\n\nExecution finished in %d ms.\nSuccess rate: %6.2f %%", toc - tic, ((double) requestCounter.get() / config.requests) * 100)); if (errors.size() > 0) { System.out.println("Following errors occurred during the request execution"); for (String error : errors) { System.out.println("\t" + error); } } client.close(); return errors.size() > 0 ? -1 : 0; }  static void main(String[] args); }
Main { static int runClient(final String[] args) { final Config config = Config.parse(args); System.out.println(String.format("\nStarting to execute %d requests:\n", config.requests)); final Client client = ClientBuilder.newClient(); final WebTarget echoResource = client.target(config.baseUri).path("long-running/{mode}/{echo}") .resolveTemplate("mode", (config.sync) ? "sync" : "async"); final CountDownLatch latch = new CountDownLatch(config.requests); final Queue<String> errors = new ConcurrentLinkedQueue<String>(); final AtomicInteger requestCounter = new AtomicInteger(0); final long tic = System.currentTimeMillis(); for (int i = 0; i < config.requests; i++) { final int reqId = i; echoResource.resolveTemplate("echo", reqId).request().async().get(new InvocationCallback<String>() { private final AtomicInteger retries = new AtomicInteger(0); @Override public void completed(String response) { final String requestId = Integer.toString(reqId); if (requestId.equals(response)) { System.out.print("*"); requestCounter.incrementAndGet(); } else { System.out.print("!"); errors.offer(String.format("Echo response '%s' not equal to request '%s'", response, requestId)); } latch.countDown(); } @Override public void failed(Throwable error) { if (error.getCause() instanceof IOException && retries.getAndIncrement() < 3) { echoResource.resolveTemplate("echo", reqId).request().async().get(this); } else { System.out.print("!"); errors.offer(String.format("Request '%d' has failed: %s", reqId, error.toString())); latch.countDown(); } } }); } try { if (!latch.await(60, TimeUnit.SECONDS)) { errors.offer("Waiting for requests to complete has timed out."); } } catch (InterruptedException e) { errors.offer("Waiting for requests to complete has been interrupted."); } final long toc = System.currentTimeMillis(); System.out.println(String.format("\n\nExecution finished in %d ms.\nSuccess rate: %6.2f %%", toc - tic, ((double) requestCounter.get() / config.requests) * 100)); if (errors.size() > 0) { System.out.println("Following errors occurred during the request execution"); for (String error : errors) { System.out.println("\t" + error); } } client.close(); return errors.size() > 0 ? -1 : 0; }  static void main(String[] args);  }