Search in sources :

Example 16 with ICompletableFuture

use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.

the class NearCachedClientMapProxy method submitToKeyInternal.

@Override
public ICompletableFuture submitToKeyInternal(Data keyData, EntryProcessor entryProcessor) {
    ICompletableFuture future = super.submitToKeyInternal(keyData, entryProcessor);
    invalidateNearCache(keyData);
    return future;
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture)

Example 17 with ICompletableFuture

use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.

the class ExecutorServiceTest method test_registerCallback_multipleTimes_futureIsCompletedOnOtherNode.

@Test
public void test_registerCallback_multipleTimes_futureIsCompletedOnOtherNode() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    assertTrue(instance1.getCountDownLatch("latch").trySetCount(1));
    String name = randomString();
    IExecutorService executorService = instance2.getExecutorService(name);
    ICountDownLatchAwaitCallable task = new ICountDownLatchAwaitCallable("latch");
    String key = generateKeyOwnedBy(instance1);
    ICompletableFuture<Boolean> future = (ICompletableFuture<Boolean>) executorService.submitToKeyOwner(task, key);
    CountDownLatch latch = new CountDownLatch(2);
    CountingDownExecutionCallback<Boolean> callback = new CountingDownExecutionCallback<Boolean>(latch);
    future.andThen(callback);
    future.andThen(callback);
    instance1.getCountDownLatch("latch").countDown();
    assertTrue(future.get());
    assertOpenEventually(latch, 10);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with ICompletableFuture

use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.

the class ExecutorServiceTest method test_registerCallback_beforeFutureIsCompletedOnOtherNode.

@Test
public void test_registerCallback_beforeFutureIsCompletedOnOtherNode() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    assertTrue(instance1.getCountDownLatch("latch").trySetCount(1));
    String name = randomString();
    IExecutorService executorService = instance2.getExecutorService(name);
    ICountDownLatchAwaitCallable task = new ICountDownLatchAwaitCallable("latch");
    String key = generateKeyOwnedBy(instance1);
    ICompletableFuture<Boolean> future = (ICompletableFuture<Boolean>) executorService.submitToKeyOwner(task, key);
    CountingDownExecutionCallback<Boolean> callback = new CountingDownExecutionCallback<Boolean>(1);
    future.andThen(callback);
    instance1.getCountDownLatch("latch").countDown();
    assertTrue(future.get());
    assertOpenEventually(callback.getLatch());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICompletableFuture(com.hazelcast.core.ICompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with ICompletableFuture

use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.

the class ClientCancellableDelegatingFuture method waitForRequestToBeSend.

protected void waitForRequestToBeSend() throws InterruptedException {
    ICompletableFuture future = getFuture();
    ClientInvocationFuture clientCallFuture = (ClientInvocationFuture) future;
    clientCallFuture.getInvocation().getSendConnectionOrWait();
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture)

Example 20 with ICompletableFuture

use of com.hazelcast.core.ICompletableFuture in project hazelcast by hazelcast.

the class DelegatingFutureTest method test_andThen_Object.

@Test
public void test_andThen_Object() {
    Object value = "value";
    ICompletableFuture future = new DelegatingFuture(new FakeCompletableFuture(value), null);
    TestExecutionCallback callback = new TestExecutionCallback();
    future.andThen(callback, new CallerRunsExecutor());
    assertEquals(value, callback.value);
}
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