Search in sources :

Example 1 with ICompletableFuture

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICompletableFuture(com.hazelcast.core.ICompletableFuture) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with ICompletableFuture

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with ICompletableFuture

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);
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ICompletableFuture

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());
    }
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with ICompletableFuture

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());
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ICompletableFuture (com.hazelcast.core.ICompletableFuture)21 Test (org.junit.Test)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 IExecutorService (com.hazelcast.core.IExecutorService)4 Data (com.hazelcast.nio.serialization.Data)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Operation (com.hazelcast.spi.Operation)2 ExecutionException (java.util.concurrent.ExecutionException)2 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)1 IAtomicLong (com.hazelcast.core.IAtomicLong)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1