use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.
the class ClientMapIssueTest method testFutureGetCalledInCallback.
@Test
public void testFutureGetCalledInCallback() {
hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
IMap<Integer, Integer> map = client.getMap("map");
final ICompletableFuture<Integer> future = (ICompletableFuture<Integer>) map.getAsync(1);
final CountDownLatch latch = new CountDownLatch(1);
future.andThen(new ExecutionCallback<Integer>() {
public void onResponse(Integer response) {
try {
future.get();
latch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
public void onFailure(Throwable t) {
}
});
assertOpenEventually(latch, 10);
}
use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.
the class ExecutorServiceTest method test_registerCallback_afterFutureIsCompletedOnOtherNode.
@Test
public void test_registerCallback_afterFutureIsCompletedOnOtherNode() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance();
HazelcastInstance instance2 = factory.newHazelcastInstance();
String name = randomString();
IExecutorService executorService = instance2.getExecutorService(name);
BasicTestCallable task = new BasicTestCallable();
String key = generateKeyOwnedBy(instance1);
ICompletableFuture<String> future = (ICompletableFuture<String>) executorService.submitToKeyOwner(task, key);
assertEquals(BasicTestCallable.RESULT, future.get());
CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<String>(1);
future.andThen(callback);
assertOpenEventually(callback.getLatch(), 10);
}
use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.
the class SmallClusterTest method executionCallback_notified.
@Test
public void executionCallback_notified() throws Exception {
IExecutorService executorService = instances[1].getExecutorService(randomString());
BasicTestCallable task = new BasicTestCallable();
String key = generateKeyOwnedBy(instances[0]);
ICompletableFuture<String> future = (ICompletableFuture<String>) executorService.submitToKeyOwner(task, key);
CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<String>(1);
future.andThen(callback);
future.get();
assertOpenEventually(callback.getLatch(), 10);
}
use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.
the class RingbufferAbstractTest method readManyAsync_whenReadingBeyondTail.
// ==================== asyncReadOrWait ==============================
@Test
public void readManyAsync_whenReadingBeyondTail() throws ExecutionException, InterruptedException {
ringbuffer.add("1");
ringbuffer.add("2");
long seq = ringbuffer.tailSequence() + 2;
ICompletableFuture f = ringbuffer.readManyAsync(seq, 1, 1, null);
try {
f.get();
fail();
} catch (ExecutionException e) {
assertInstanceOf(IllegalArgumentException.class, e.getCause());
}
}
use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.
the class InvocationFuture_CancelTest method whenCallCancel_thenCancelled.
@Test
public void whenCallCancel_thenCancelled() throws Exception {
// Given
ICompletableFuture future = invoke();
// When
boolean result = future.cancel(true);
// Then
assertTrue(result);
assertTrue(future.isCancelled());
assertTrue(future.isDone());
}
Aggregations