use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable 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.BasicTestCallable 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.BasicTestCallable in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceTest method testInvokeAll_WithTimeout.
@Test
public void testInvokeAll_WithTimeout() throws Exception {
DurableExecutorService service = client.getDurableExecutorService(randomString());
List<BasicTestCallable> callables = Collections.emptyList();
expectedException.expect(UnsupportedOperationException.class);
service.invokeAll(callables, 1, TimeUnit.SECONDS);
}
use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable in project hazelcast by hazelcast.
the class ClientDurableRetrieveResultTest method testRetrieve_WhenResultOverwritten.
@Test
public void testRetrieve_WhenResultOverwritten() throws Exception {
String name = randomString();
DurableExecutorService executorService = client.getDurableExecutorService(name);
DurableExecutorServiceFuture<String> future = executorService.submitToKeyOwner(new BasicTestCallable(), name);
long taskId = future.getTaskId();
future.get();
for (int i = 0; i < DEFAULT_RING_BUFFER_CAPACITY; i++) {
executorService.submitToKeyOwner(new BasicTestCallable(), name);
}
Future<Object> resultFuture = executorService.retrieveResult(taskId);
try {
resultFuture.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof StaleTaskIdException);
}
}
use of com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable in project hazelcast by hazelcast.
the class ClientDurableRetrieveResultTest method testDisposeResult.
@Test
public void testDisposeResult() throws Exception {
String name = randomString();
String key = generateKeyOwnedBy(instance1);
DurableExecutorService executorService = client.getDurableExecutorService(name);
BasicTestCallable task = new BasicTestCallable();
DurableExecutorServiceFuture<String> future = executorService.submitToKeyOwner(task, key);
future.get();
executorService.disposeResult(future.getTaskId());
Future<Object> resultFuture = executorService.retrieveResult(future.getTaskId());
assertNull(resultFuture.get());
}
Aggregations