Search in sources :

Example 46 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture 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]);
    InternalCompletableFuture<String> future = (InternalCompletableFuture<String>) executorService.submitToKeyOwner(task, key);
    CountingDownExecutionCallback<String> callback = new CountingDownExecutionCallback<>(1);
    future.whenCompleteAsync(callback);
    future.get();
    assertOpenEventually(callback.getLatch(), 10);
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with InternalCompletableFuture

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

the class ChainingFutureTest method testTopologyChangesExceptionsAreIgnored.

@Test
public void testTopologyChangesExceptionsAreIgnored() {
    InternalCompletableFuture<Object> future1 = newFuture();
    InternalCompletableFuture<Object> future2 = newFuture();
    InternalCompletableFuture<Object> future3 = newFuture();
    CountingIterator<InternalCompletableFuture<Object>> iterator = toIterator(future1, future2, future3);
    ChainingFuture.ExceptionHandler handler = repairingIterator;
    ChainingFuture<Object> future = new ChainingFuture<>(iterator, handler);
    assertEquals(1, iterator.getHasNextCounter());
    assertEquals(1, iterator.getNextCounter());
    assertFalse(future.isDone());
    future1.complete(new MemberLeftException("this should be ignored"));
    assertEquals(2, iterator.getHasNextCounter());
    assertEquals(2, iterator.getNextCounter());
    assertFalse(future.isDone());
    future2.complete(new TargetNotMemberException("this should be ignored"));
    assertEquals(3, iterator.getHasNextCounter());
    assertEquals(3, iterator.getNextCounter());
    assertFalse(future.isDone());
    future3.complete("foo");
    assertTrue(future.isDone());
    assertEquals(4, iterator.getHasNextCounter());
    assertEquals(3, iterator.getNextCounter());
}
Also used : TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MemberLeftException(com.hazelcast.core.MemberLeftException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with InternalCompletableFuture

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

the class ClientSessionManagerTest method testClientSessionManagerShutdown.

@Test
public void testClientSessionManagerShutdown() throws ExecutionException, InterruptedException {
    AbstractProxySessionManager sessionManager = getSessionManager();
    SessionProxyImpl proxy = new SessionProxyImpl(sessionManager, groupId);
    proxy.createSession();
    Map<RaftGroupId, InternalCompletableFuture<Object>> futures = sessionManager.shutdown();
    assertEquals(1, futures.size());
    Entry<RaftGroupId, InternalCompletableFuture<Object>> e = futures.entrySet().iterator().next();
    assertEquals(groupId, e.getKey());
    e.getValue().get();
    exception.expect(IllegalStateException.class);
    proxy.createSession();
}
Also used : AbstractProxySessionManager(com.hazelcast.cp.internal.session.AbstractProxySessionManager) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) AbstractProxySessionManagerTest(com.hazelcast.cp.internal.session.AbstractProxySessionManagerTest)

Example 49 with InternalCompletableFuture

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

the class ClientInvocation_ExceptionTest method test.

@Test
public void test() throws Exception {
    IExecutorService executorService = client.getExecutorService("test");
    InternalCompletableFuture f = (InternalCompletableFuture) executorService.submit(new ExceptionThrowingCallable(exception));
    assertCompletesEventually(f);
    expected.expect(expectedExceptionClass);
    expected.expectCause(exceptionCauseMatcher);
    waitForFuture(f, futureSyncMethod);
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) IExecutorService(com.hazelcast.core.IExecutorService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with InternalCompletableFuture

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

the class ClientCacheProxySupport method callPutAsync.

protected CompletableFuture callPutAsync(K key, Data keyData, V value, Data valueData, Data expiryPolicyData, boolean isGet, boolean withCompletionEvent, BiConsumer<V, Throwable> statsCallback) {
    ClientInvocationFuture invocationFuture = putInternal(keyData, valueData, expiryPolicyData, isGet, withCompletionEvent);
    InternalCompletableFuture future = newDelegatingFuture(invocationFuture, CachePutCodec::decodeResponse);
    return addCallback(future, statsCallback);
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) CachePutCodec(com.hazelcast.client.impl.protocol.codec.CachePutCodec) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)90 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)47 QuickTest (com.hazelcast.test.annotation.QuickTest)47 Test (org.junit.Test)47 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)15 Data (com.hazelcast.internal.serialization.Data)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 UUID (java.util.UUID)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Member (com.hazelcast.cluster.Member)7 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)7 Future (java.util.concurrent.Future)7 Address (com.hazelcast.cluster.Address)6 List (java.util.List)6 BiConsumer (java.util.function.BiConsumer)6 Nonnull (javax.annotation.Nonnull)6