use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class AbstractInvocationFuture_AndThenTest method whenMultipleCallbacks.
@Test
public void whenMultipleCallbacks() throws ExecutionException, InterruptedException {
List<ExecutionCallback> callbacks = new LinkedList<ExecutionCallback>();
for (int k = 0; k < 10; k++) {
ExecutionCallback callback = mock(ExecutionCallback.class);
future.andThen(callback);
}
sleepSeconds(5);
future.complete(value);
for (ExecutionCallback callback : callbacks) {
verify(callback).onResponse(value);
}
assertSame(value, future.getState());
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class AbstractInvocationFuture_AndThenTest method whenResponseAlreadyAvailable.
@Test
public void whenResponseAlreadyAvailable() {
future.complete(value);
final ExecutionCallback callback = mock(ExecutionCallback.class);
future.andThen(callback);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
verify(callback).onResponse(value);
}
});
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class AbstractInvocationFuture_AndThenTest method whenDefaultExecutor.
@Test
public void whenDefaultExecutor() {
Executor defaultExecutor = mock(Executor.class);
TestFuture future = new TestFuture(defaultExecutor, logger);
final ExecutionCallback callback = mock(ExecutionCallback.class);
future.andThen(callback);
future.complete(value);
verify(defaultExecutor).execute(any(Runnable.class));
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class AbstractInvocationFuture_AndThenTest method whenExceptionalResponseAvailableAfterSomeWaiting.
@Test
public void whenExceptionalResponseAvailableAfterSomeWaiting() {
final ExecutionCallback callback = mock(ExecutionCallback.class);
future.andThen(callback);
sleepSeconds(5);
verifyZeroInteractions(callback);
final ExpectedRuntimeException ex = new ExpectedRuntimeException();
future.complete(ex);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
verify(callback).onFailure(ex);
}
});
}
use of com.hazelcast.core.ExecutionCallback in project hazelcast by hazelcast.
the class AbstractInvocationFuture_ClosedExecutorTest method whenCompleteAfterShutdown_thenCallback.
@Test
public void whenCompleteAfterShutdown_thenCallback() {
ExecutorService executorService = Executors.newSingleThreadExecutor();
TestFuture future = new TestFuture(executorService, logger);
executorService.shutdown();
future.complete(new Object());
final AtomicBoolean onFailure = new AtomicBoolean();
future.andThen(new ExecutionCallback() {
@Override
public void onResponse(Object response) {
}
@Override
public void onFailure(Throwable t) {
if (t instanceof RejectedExecutionException) {
onFailure.set(true);
}
}
});
assertTrue(onFailure.get());
}
Aggregations