use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask 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());
}
use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceTest method testFullRingBuffer_WithExecutionCallback.
public void testFullRingBuffer_WithExecutionCallback() throws InterruptedException {
String key = randomString();
DurableExecutorService service = client.getDurableExecutorService(SINGLE_TASK + randomString());
service.submitToKeyOwner(new SleepingTask(100), key);
DurableExecutorServiceFuture<String> future = service.submitToKeyOwner(new BasicTestCallable(), key);
final CountDownLatch latch = new CountDownLatch(1);
future.andThen(new ExecutionCallback<String>() {
@Override
public void onResponse(String response) {
}
@Override
public void onFailure(Throwable t) {
if (t.getCause() instanceof RejectedExecutionException) {
latch.countDown();
}
}
});
assertOpenEventually(latch);
assertTrue(future.isDone());
assertFalse(future.cancel(true));
assertFalse(future.isCancelled());
}
use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.
the class ClientDurableRetrieveResultTest method testRetrieve_WhenSubmitterMemberDown.
@Test
public void testRetrieve_WhenSubmitterMemberDown() throws Exception {
String name = randomString();
DurableExecutorService executorService = client.getDurableExecutorService(name);
SleepingTask task = new SleepingTask(4);
long taskId = executorService.submit(task).getTaskId();
client.shutdown();
client = hazelcastFactory.newHazelcastClient();
executorService = client.getDurableExecutorService(name);
Future<Boolean> future = executorService.retrieveResult(taskId);
assertTrue(future.get());
}
use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.
the class ClientDurableRetrieveResultTest method testRetrieveAndDispose_WhenOwnerMemberDown.
@Test
public void testRetrieveAndDispose_WhenOwnerMemberDown() throws Exception {
String name = randomString();
String key = generateKeyOwnedBy(instance2);
DurableExecutorService executorService = client.getDurableExecutorService(name);
SleepingTask task = new SleepingTask(4);
long taskId = executorService.submitToKeyOwner(task, key).getTaskId();
instance2.shutdown();
Future<Boolean> future = executorService.retrieveAndDisposeResult(taskId);
assertTrue(future.get());
Future<Boolean> resultFuture = executorService.retrieveResult(taskId);
assertNull(resultFuture.get());
}
use of com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask in project hazelcast by hazelcast.
the class ClientDurableRetrieveResultTest method testRetrieveAndDispose_WhenClientDown.
@Test
public void testRetrieveAndDispose_WhenClientDown() throws Exception {
String name = randomString();
DurableExecutorService executorService = client.getDurableExecutorService(name);
SleepingTask task = new SleepingTask(4);
long taskId = executorService.submit(task).getTaskId();
client.shutdown();
client = hazelcastFactory.newHazelcastClient();
executorService = client.getDurableExecutorService(name);
Future<Boolean> future = executorService.retrieveAndDisposeResult(taskId);
assertTrue(future.get());
Future<Object> resultFuture = executorService.retrieveResult(taskId);
assertNull(resultFuture.get());
}
Aggregations