Search in sources :

Example 11 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)

Example 12 with ICompletableFuture

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

the class CompletedFutureTest method test_andThen_Data.

@Test
public void test_andThen_Data() {
    Object value = "value";
    Data data = serializationService.toData(value);
    ICompletableFuture future = new CompletedFuture(serializationService, data, null);
    TestExecutionCallback callback = new TestExecutionCallback();
    future.andThen(callback, new CallerRunsExecutor());
    assertEquals(value, callback.value);
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with ICompletableFuture

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

the class InvocationFuture_CancelTest method whenCancelled_thenGetThrowsCancelled.

@Test
public void whenCancelled_thenGetThrowsCancelled() throws Exception {
    // Given
    ICompletableFuture future = invoke();
    // When
    future.cancel(true);
    // Then
    exceptionRule.expect(CancellationException.class);
    future.get();
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with ICompletableFuture

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

the class InvocationFuture_CancelTest method whenCancelled_thenCantCancelAgain.

@Test
public void whenCancelled_thenCantCancelAgain() throws Exception {
    // Given
    ICompletableFuture future = invoke();
    // When
    future.cancel(true);
    // Then
    assertFalse(future.cancel(true));
}
Also used : ICompletableFuture(com.hazelcast.core.ICompletableFuture) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 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)

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