@Test public void testJMX() throws Exception { prepare(new TestHandler()); LoadGenerator loadGenerator = new LoadGenerator.Builder() .port(connector.getLocalPort()) .httpClientTransportBuilder(clientTransportBuilder) .iterationsPerThread(0) .resourceRate(5) .build(); MBeanContainer mbeanContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); loadGenerator.addBean(mbeanContainer); ObjectName pattern = new ObjectName(LoadGenerator.class.getPackage().getName() + ":*"); Set<ObjectName> objectNames = mbeanContainer.getMBeanServer().queryNames(pattern, null); Assert.assertTrue(objectNames.size() > 0); Optional<ObjectName> objectNameOpt = objectNames.stream() .filter(o -> o.getKeyProperty("type").equalsIgnoreCase(LoadGenerator.class.getSimpleName())) .findAny(); Assert.assertTrue(objectNameOpt.isPresent()); ObjectName objectName = objectNameOpt.get(); CompletableFuture<Void> cf = loadGenerator.begin(); Thread.sleep(1000); mbeanContainer.getMBeanServer().invoke(objectName, "interrupt", null, new String[]{}); cf.handle((r, x) -> { Throwable cause = x.getCause(); if (cause instanceof InterruptedException) { return null; } else { throw new CompletionException(cause); } }).get(5, TimeUnit.SECONDS); }
public CompletableFuture<Void> begin() { if (logger.isDebugEnabled()) { logger.debug("generating load, {}", config); } return proceed().thenCompose(x -> { CompletableFuture[] futures = new CompletableFuture[config.getThreads()]; for (int i = 0; i < futures.length; ++i) { futures[i] = CompletableFuture.supplyAsync(this::process, executorService).thenCompose(Function.identity()); } return CompletableFuture.allOf(futures); }).thenComposeAsync(x -> halt(), executorService); }
LoadGenerator extends ContainerLifeCycle { public CompletableFuture<Void> begin() { if (logger.isDebugEnabled()) { logger.debug("generating load, {}", config); } return proceed().thenCompose(x -> { CompletableFuture[] futures = new CompletableFuture[config.getThreads()]; for (int i = 0; i < futures.length; ++i) { futures[i] = CompletableFuture.supplyAsync(this::process, executorService).thenCompose(Function.identity()); } return CompletableFuture.allOf(futures); }).thenComposeAsync(x -> halt(), executorService); } }
LoadGenerator extends ContainerLifeCycle { public CompletableFuture<Void> begin() { if (logger.isDebugEnabled()) { logger.debug("generating load, {}", config); } return proceed().thenCompose(x -> { CompletableFuture[] futures = new CompletableFuture[config.getThreads()]; for (int i = 0; i < futures.length; ++i) { futures[i] = CompletableFuture.supplyAsync(this::process, executorService).thenCompose(Function.identity()); } return CompletableFuture.allOf(futures); }).thenComposeAsync(x -> halt(), executorService); } private  LoadGenerator(Config config); }
LoadGenerator extends ContainerLifeCycle { public CompletableFuture<Void> begin() { if (logger.isDebugEnabled()) { logger.debug("generating load, {}", config); } return proceed().thenCompose(x -> { CompletableFuture[] futures = new CompletableFuture[config.getThreads()]; for (int i = 0; i < futures.length; ++i) { futures[i] = CompletableFuture.supplyAsync(this::process, executorService).thenCompose(Function.identity()); } return CompletableFuture.allOf(futures); }).thenComposeAsync(x -> halt(), executorService); } private  LoadGenerator(Config config); Config getConfig(); CompletableFuture<Void> begin(); @ManagedOperation(value = "Interrupts this LoadGenerator", impact = "ACTION") void interrupt(); }
LoadGenerator extends ContainerLifeCycle { public CompletableFuture<Void> begin() { if (logger.isDebugEnabled()) { logger.debug("generating load, {}", config); } return proceed().thenCompose(x -> { CompletableFuture[] futures = new CompletableFuture[config.getThreads()]; for (int i = 0; i < futures.length; ++i) { futures[i] = CompletableFuture.supplyAsync(this::process, executorService).thenCompose(Function.identity()); } return CompletableFuture.allOf(futures); }).thenComposeAsync(x -> halt(), executorService); } private  LoadGenerator(Config config); Config getConfig(); CompletableFuture<Void> begin(); @ManagedOperation(value = "Interrupts this LoadGenerator", impact = "ACTION") void interrupt();  }