Search in sources :

Example 1 with DelegatingCompletableFuture

use of com.hazelcast.spi.impl.DelegatingCompletableFuture in project hazelcast by hazelcast.

the class DelegatingCompletableFutureConstructorTest method test.

@Test
public void test() {
    CompletableFuture<Integer> delegate = new CompletableFuture<>();
    DelegatingCompletableFuture delegatingCompletableFuture = new DelegatingCompletableFuture(new DefaultSerializationServiceBuilder().build(), delegate);
    DelegatingCompletableFutureConstructor constructor = new DelegatingCompletableFutureConstructor(delegatingCompletableFuture.getClass());
    DelegatingCompletableFuture<Integer> cloned = (DelegatingCompletableFuture<Integer>) constructor.createNew(delegatingCompletableFuture);
    delegate.complete(42);
    assertTrue(cloned.isDone());
    assertEquals(42, cloned.join().intValue());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) DelegatingCompletableFuture(com.hazelcast.spi.impl.DelegatingCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) DelegatingCompletableFutureConstructor(com.hazelcast.test.starter.constructor.DelegatingCompletableFutureConstructor) DelegatingCompletableFuture(com.hazelcast.spi.impl.DelegatingCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with DelegatingCompletableFuture

use of com.hazelcast.spi.impl.DelegatingCompletableFuture in project hazelcast by hazelcast.

the class CancellableDelegatingFutureTest method testInnerFutureThrowsCancellationExceptionWhenOuterFutureIsCancelled.

@Test
public void testInnerFutureThrowsCancellationExceptionWhenOuterFutureIsCancelled() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final HazelcastInstance instance = factory.newHazelcastInstance();
    IExecutorService executorService = instance.getExecutorService(randomString());
    final CompletesOnInterruptionCallable callable = new CompletesOnInterruptionCallable();
    final DelegatingCompletableFuture<Boolean> future = (DelegatingCompletableFuture<Boolean>) executorService.submit(callable);
    if (future.cancel(true)) {
        expected.expect(CancellationException.class);
        future.getDelegate().get();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) DelegatingCompletableFuture(com.hazelcast.spi.impl.DelegatingCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with DelegatingCompletableFuture

use of com.hazelcast.spi.impl.DelegatingCompletableFuture in project hazelcast by hazelcast.

the class CancellableDelegatingFutureTest method testCancellationOfDoneFutureDoesNothing.

@Test
public void testCancellationOfDoneFutureDoesNothing() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final HazelcastInstance instance = factory.newHazelcastInstance();
    IExecutorService executorService = instance.getExecutorService(randomString());
    final DummyCancellationCallable callable = new DummyCancellationCallable();
    final DelegatingCompletableFuture<Void> future = (DelegatingCompletableFuture<Void>) executorService.submit(callable);
    future.get();
    future.cancel(true);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) DelegatingCompletableFuture(com.hazelcast.spi.impl.DelegatingCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DelegatingCompletableFuture (com.hazelcast.spi.impl.DelegatingCompletableFuture)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 IExecutorService (com.hazelcast.core.IExecutorService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 DelegatingCompletableFutureConstructor (com.hazelcast.test.starter.constructor.DelegatingCompletableFutureConstructor)1 CompletableFuture (java.util.concurrent.CompletableFuture)1