Source:
private void runManagementCallFromAnotherClient(ClientIdentifier targetClientIdentifier) throws Exception { try (Connection managementConsole = ConnectionFactory.connect(URI.create("passthrough://server-1:9510/cluster-1"), new Properties())) { ManagementAgentService agent = new ManagementAgentService(new ManagementAgentEntityFactory(managementConsole).retrieveOrCreate(new ManagementAgentConfig())); assertThat(agent.getManageableClients().size(), equalTo(2)); assertThat(agent.getManageableClients(), hasItem(targetClientIdentifier)); assertThat(agent.getManageableClients(), hasItem(agent.getClientIdentifier())); AtomicReference<String> managementCallId = new AtomicReference<>(); BlockingQueue<ContextualReturn<?>> returns = new LinkedBlockingQueue<>(); agent.setContextualReturnListener((from, id, aReturn) -> { assertEquals(targetClientIdentifier, from); assertEquals(managementCallId.get(), id); returns.offer(aReturn); }); managementCallId.set(agent.call( targetClientIdentifier, Context.empty() .with("cacheManagerName", "myCacheManagerName") .with("cacheName", "myCacheName1"), "TheActionProvider", "incr", int.class, new Parameter(Integer.MAX_VALUE, "int"))); ContextualReturn<?> ret = returns.take(); assertThat(ret.hasExecuted(), is(true)); try { ret.getValue(); fail(); } catch (Exception e) { assertThat(e, instanceOf(ExecutionException.class)); assertThat(e.getCause(), instanceOf(IllegalArgumentException.class)); } managementCallId.set(agent.call( targetClientIdentifier, Context.empty() .with("cacheManagerName", "myCacheManagerName") .with("cacheName", "myCacheName1"), "TheActionProvider", "incr", int.class, new Parameter(1, "int"))); ret = returns.take(); assertThat(ret.hasExecuted(), is(true)); assertThat(ret.getValue(), equalTo(2)); } }

Target:
private void runManagementCallFromAnotherClient(ClientIdentifier targetClientIdentifier) throws Exception { try (Connection managementConnection = ConnectionFactory.connect(URI.create("passthrough://server-1:9510/cluster-1"), new Properties())) { ManagementAgentService agent = new ManagementAgentService(new ManagementAgentEntityFactory(managementConnection).retrieveOrCreate(new ManagementAgentConfig())); assertThat(agent.getManageableClients().size(), equalTo(2)); assertThat(agent.getManageableClients(), hasItem(targetClientIdentifier)); assertThat(agent.getManageableClients(), hasItem(agent.getClientIdentifier())); AtomicReference<String> managementCallId = new AtomicReference<>(); BlockingQueue<ContextualReturn<?>> returns = new LinkedBlockingQueue<>(); agent.setContextualReturnListener((from, id, aReturn) -> { assertEquals(targetClientIdentifier, from); assertEquals(managementCallId.get(), id); returns.offer(aReturn); }); managementCallId.set(agent.call( targetClientIdentifier, Context.empty() .with("cacheManagerName", "myCacheManagerName") .with("cacheName", "myCacheName1"), "TheActionProvider", "incr", int.class, new Parameter(Integer.MAX_VALUE, "int"))); ContextualReturn<?> ret = returns.take(); assertThat(ret.hasExecuted(), is(true)); try { ret.getValue(); fail(); } catch (Exception e) { assertThat(e, instanceOf(ExecutionException.class)); assertThat(e.getCause(), instanceOf(IllegalArgumentException.class)); } managementCallId.set(agent.call( targetClientIdentifier, Context.empty() .with("cacheManagerName", "myCacheManagerName") .with("cacheName", "myCacheName1"), "TheActionProvider", "incr", int.class, new Parameter(1, "int"))); ret = returns.take(); assertThat(ret.hasExecuted(), is(true)); assertThat(ret.getValue(), equalTo(2)); } }