Source:
<code>private void remotelyUpdateCollectedStatistics() throws Exception { try (Connection managementConsole = ConnectionFactory.connect(URI.create("passthrough://server-1:9510/"), new Properties())) { ManagementAgentService agent = new ManagementAgentService(new ManagementAgentEntityFactory(managementConsole).retrieveOrCreate(new ManagementAgentConfig())); assertThat(agent.getManageableClients().size(), equalTo(2)); ClientIdentifier me = agent.getClientIdentifier(); ClientIdentifier client = null; for (ClientIdentifier clientIdentifier : agent.getManageableClients()) { if (!clientIdentifier.equals(me)) { client = clientIdentifier; break; } } assertThat(client, is(notNullValue())); final ClientIdentifier ehcacheClientIdentifier = client; CountDownLatch callCompleted = new CountDownLatch(1); AtomicReference<String> managementCallId = new AtomicReference<>(); BlockingQueue<ContextualReturn<?>> returns = new LinkedBlockingQueue<>(); agent.setContextualReturnListener(new ContextualReturnListener() { @Override public void onContextualReturn(ClientIdentifier from, String id, ContextualReturn<?> aReturn) { <START> try { <END> assertEquals(ehcacheClientIdentifier, from); callCompleted.await(); assertEquals(managementCallId.get(), id); returns.offer(aReturn); } catch (InterruptedException e) { throw new RuntimeException(e); } } }); managementCallId.set(agent.call( ehcacheClientIdentifier, Context.create("cacheManagerName", "my-super-cache-manager"), "StatisticCollectorCapability", "updateCollectedStatistics", Collection.class, new Parameter("StatisticsCapability"), new Parameter(asList("PutCounter", "InexistingRate"), Collection.class.getName()))); callCompleted.countDown(); returns.take(); } }</code><technical_language>this need catch InterruptedException? I recall this type of construct in 4.x tests a latch</technical_language>

Target:
private void remotelyUpdateCollectedStatistics() throws Exception { try (Connection managementConsole = ConnectionFactory.connect(URI.create("passthrough://server-1:9510/"), new Properties())) { ManagementAgentService agent = new ManagementAgentService(new ManagementAgentEntityFactory(managementConsole).retrieveOrCreate(new ManagementAgentConfig())); assertThat(agent.getManageableClients().size(), equalTo(2)); ClientIdentifier me = agent.getClientIdentifier(); ClientIdentifier client = null; for (ClientIdentifier clientIdentifier : agent.getManageableClients()) { if (!clientIdentifier.equals(me)) { client = clientIdentifier; break; } } assertThat(client, is(notNullValue())); final ClientIdentifier ehcacheClientIdentifier = client; CountDownLatch callCompleted = new CountDownLatch(1); AtomicReference<String> managementCallId = new AtomicReference<>(); BlockingQueue<ContextualReturn<?>> returns = new LinkedBlockingQueue<>(); agent.setContextualReturnListener(new ContextualReturnListener() { @Override public void onContextualReturn(ClientIdentifier from, String id, ContextualReturn<?> aReturn) { try { assertEquals(ehcacheClientIdentifier, from); callCompleted.await(10, TimeUnit.SECONDS); assertEquals(managementCallId.get(), id); returns.offer(aReturn); } catch (InterruptedException e) { throw new RuntimeException(e); } } }); managementCallId.set(agent.call( ehcacheClientIdentifier, Context.create("cacheManagerName", "my-super-cache-manager"), "StatisticCollectorCapability", "updateCollectedStatistics", Collection.class, new Parameter("StatisticsCapability"), new Parameter(asList("PutCounter", "InexistingRate"), Collection.class.getName()))); callCompleted.countDown(); returns.take(); } }