use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientOwnershipTest method test_clientOwnedByAlreadyConnectedSecondMember_afterFirstOwnerDies.
@Test
public void test_clientOwnedByAlreadyConnectedSecondMember_afterFirstOwnerDies() {
final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
// make sure client connected to all nodes
IExecutorService exec = client.getExecutorService("exec");
exec.submitToAllMembers(new DummySerializableCallable());
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, instance1.getClientService().getConnectedClients().size());
assertEquals(1, instance2.getClientService().getConnectedClients().size());
}
});
instance1.shutdown();
final String instance2Uuid = instance2.getLocalEndpoint().getUuid();
final String clientUuid = client.getLocalEndpoint().getUuid();
final ClientEngineImpl clientEngine = getClientEngineImpl(instance2);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(instance2Uuid, clientEngine.getOwnerUuid(clientUuid));
}
});
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method testSubmitRunnable_withExecutionCallback.
@Test
public void testSubmitRunnable_withExecutionCallback() throws Exception {
IExecutorService service = client.getExecutorService(randomString());
String mapName = randomString();
Runnable runnable = new MapPutRunnable(mapName);
final CountDownLatch responseLatch = new CountDownLatch(1);
service.submit(runnable, new ExecutionCallback() {
public void onResponse(Object response) {
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
});
IMap map = client.getMap(mapName);
assertOpenEventually("responseLatch", responseLatch);
assertEquals(1, map.size());
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitRunnable.
@Test
public void submitRunnable() {
IExecutorService service = client.getExecutorService(randomString());
String mapName = randomString();
Runnable runnable = new MapPutRunnable(mapName);
service.submit(runnable);
IMap map = client.getMap(mapName);
assertSizeEventually(1, map);
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitRunnablePartitionAware.
@Test
public void submitRunnablePartitionAware() throws Exception {
IExecutorService service = client.getExecutorService(randomString());
String mapName = randomString();
String key = HazelcastTestSupport.generateKeyOwnedBy(server);
final Member member = server.getCluster().getLocalMember();
//this task should execute on a node owning the given key argument,
//the action is to put the UUid of the executing node into a map with the given name
Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
service.submit(runnable);
final IMap map = client.getMap(mapName);
assertTrueEventually(new AssertTask() {
public void run() throws Exception {
assertTrue(map.containsKey(member.getUuid()));
}
});
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientExecutorServiceSubmitTest method submitRunnablePartitionAware_withResult.
@Test
public void submitRunnablePartitionAware_withResult() throws Exception {
IExecutorService service = client.getExecutorService(randomString());
String expectedResult = "result";
String mapName = randomString();
String key = HazelcastTestSupport.generateKeyOwnedBy(server);
final Member member = server.getCluster().getLocalMember();
Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
Future result = service.submit(runnable, expectedResult);
final IMap map = client.getMap(mapName);
assertEquals(expectedResult, result.get());
assertTrueEventually(new AssertTask() {
public void run() throws Exception {
assertTrue(map.containsKey(member.getUuid()));
}
});
}
Aggregations