use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceSubmitTest method testSubmitCallable_withExecutionCallback.
@Test
public void testSubmitCallable_withExecutionCallback() {
DurableExecutorService service = client.getDurableExecutorService(randomString());
String msg = randomString();
Callable<String> callable = new AppendCallable(msg);
final AtomicReference<String> result = new AtomicReference<String>();
final CountDownLatch responseLatch = new CountDownLatch(1);
service.submit(callable).andThen(new ExecutionCallback<String>() {
public void onResponse(String response) {
result.set(response);
responseLatch.countDown();
}
public void onFailure(Throwable t) {
}
});
assertOpenEventually("responseLatch", responseLatch);
assertEquals(msg + AppendCallable.APPENDAGE, result.get());
}
use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceSubmitTest method submitRunnableToKeyOwner.
@Test
public void submitRunnableToKeyOwner() {
DurableExecutorService service = client.getDurableExecutorService(randomString());
String mapName = randomString();
Runnable runnable = new MapPutRunnable(mapName);
final CountDownLatch responseLatch = new CountDownLatch(1);
service.submitToKeyOwner(runnable, "key").andThen(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.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceSubmitTest method submitRunnablePartitionAware_withExecutionCallback.
@Test
public void submitRunnablePartitionAware_withExecutionCallback() {
DurableExecutorService service = client.getDurableExecutorService(randomString());
String mapName = randomString();
String key = HazelcastTestSupport.generateKeyOwnedBy(server);
Member member = server.getCluster().getLocalMember();
Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
final CountDownLatch responseLatch = new CountDownLatch(1);
service.submit(runnable).andThen(new ExecutionCallback() {
@Override
public void onResponse(Object response) {
responseLatch.countDown();
}
@Override
public void onFailure(Throwable t) {
}
});
IMap map = client.getMap(mapName);
assertOpenEventually("responseLatch", responseLatch);
assertTrue(map.containsKey(member.getUuid()));
}
use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceTest method testSubmitFailingCallableException_withExecutionCallback.
@Test
public void testSubmitFailingCallableException_withExecutionCallback() throws Exception {
DurableExecutorService service = client.getDurableExecutorService(randomString());
final CountDownLatch latch = new CountDownLatch(1);
service.submit(new FailingCallable()).andThen(new ExecutionCallback<String>() {
@Override
public void onResponse(String response) {
}
@Override
public void onFailure(Throwable t) {
latch.countDown();
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceTest method test_whenRingBufferIsFull_thenClientDurableExecutorServiceCompletedFutureIsReturned.
@Test
public void test_whenRingBufferIsFull_thenClientDurableExecutorServiceCompletedFutureIsReturned() throws Exception {
final AtomicBoolean onResponse = new AtomicBoolean();
final CountDownLatch onFailureLatch = new CountDownLatch(1);
String key = randomString();
DurableExecutorService service = client.getDurableExecutorService(SINGLE_TASK + randomString());
service.submitToKeyOwner(new SleepingTask(100), key);
DurableExecutorServiceFuture<String> future = service.submitToKeyOwner(new BasicTestCallable(), key);
future.andThen(new ExecutionCallback<String>() {
@Override
public void onResponse(String response) {
onResponse.set(true);
}
@Override
public void onFailure(Throwable t) {
onFailureLatch.countDown();
}
});
try {
future.get(1, TimeUnit.HOURS);
fail("We expected that future.get() throws an ExecutionException!");
} catch (ExecutionException ignored) {
}
// assert TaskId
try {
future.getTaskId();
fail("We expected that future.getTaskId() throws an IllegalStateException!");
} catch (IllegalStateException ignored) {
}
// assert states of ClientDurableExecutorServiceCompletedFuture
assertFalse(future.cancel(false));
assertFalse(future.cancel(true));
assertFalse(future.isCancelled());
assertTrue(future.isDone());
// assert that onFailure() has been called and not onResponse()
onFailureLatch.await();
assertFalse(onResponse.get());
}
Aggregations