Search in sources :

Example 1 with AppendCallable

use of com.hazelcast.client.test.executor.tasks.AppendCallable in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceSubmitTest method testSubmitCallable_withExecutionCallback.

@Test
public void testSubmitCallable_withExecutionCallback() {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    final AtomicReference<String> result = new AtomicReference<String>();
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submit(callable).thenAccept((response) -> {
        result.set(response);
        responseLatch.countDown();
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertEquals(msg + AppendCallable.APPENDAGE, result.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) AtomicReference(java.util.concurrent.atomic.AtomicReference) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with AppendCallable

use of com.hazelcast.client.test.executor.tasks.AppendCallable in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceSubmitTest method submitCallableToKeyOwner.

@Test
public void submitCallableToKeyOwner() throws Exception {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    Future<String> result = service.submitToKeyOwner(callable, "key");
    assertEquals(msg + AppendCallable.APPENDAGE, result.get());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with AppendCallable

use of com.hazelcast.client.test.executor.tasks.AppendCallable in project hazelcast by hazelcast.

the class ClientExecutorServiceInvokeTest method testInvokeAll_withTimeOut.

@Test(expected = UnsupportedOperationException.class)
public void testInvokeAll_withTimeOut() throws Throwable {
    IExecutorService service = client.getExecutorService(randomString());
    Collection<Callable<String>> collection = new ArrayList<Callable<String>>();
    collection.add(new AppendCallable());
    collection.add(new AppendCallable());
    service.invokeAll(collection, 1, TimeUnit.MINUTES);
}
Also used : AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) ArrayList(java.util.ArrayList) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) Callable(java.util.concurrent.Callable) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with AppendCallable

use of com.hazelcast.client.test.executor.tasks.AppendCallable in project hazelcast by hazelcast.

the class ClientExecutorServiceSubmitTest method submitCallableToMember_withMultiExecutionCallback.

@Test
public void submitCallableToMember_withMultiExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(CLUSTER_SIZE);
    final String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    Collection<Member> collection = server.getCluster().getMembers();
    service.submitToMembers(callable, collection, new MultiExecutionCallback() {

        public void onResponse(Member member, Object value) {
            if (value.equals(msg + AppendCallable.APPENDAGE)) {
                responseLatch.countDown();
            }
        }

        public void onComplete(Map<Member, Object> values) {
            for (Member member : values.keySet()) {
                Object value = values.get(member);
                if (value.equals(msg + AppendCallable.APPENDAGE)) {
                    completeLatch.countDown();
                }
            }
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertOpenEventually("completeLatch", completeLatch);
}
Also used : MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with AppendCallable

use of com.hazelcast.client.test.executor.tasks.AppendCallable in project hazelcast by hazelcast.

the class ClientExecutorServiceSubmitTest method submitCallableToKeyOwner_withExecutionCallback.

@Test
public void submitCallableToKeyOwner_withExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    final CountDownLatch responseLatch = new CountDownLatch(1);
    final AtomicReference<String> result = new AtomicReference<String>();
    service.submitToKeyOwner(callable, "key", new ExecutionCallback<String>() {

        public void onResponse(String response) {
            result.set(response);
            responseLatch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertEquals(msg + AppendCallable.APPENDAGE, result.get());
}
Also used : AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

AppendCallable (com.hazelcast.client.test.executor.tasks.AppendCallable)18 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)18 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Test (org.junit.Test)18 IExecutorService (com.hazelcast.core.IExecutorService)14 Callable (java.util.concurrent.Callable)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 MapPutPartitionAwareCallable (com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 NullCallable (com.hazelcast.client.test.executor.tasks.NullCallable)4 Member (com.hazelcast.cluster.Member)4 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)4 DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)4 ArrayList (java.util.ArrayList)4 Future (java.util.concurrent.Future)4 SelectAllMembers (com.hazelcast.client.test.executor.tasks.SelectAllMembers)3 MemberSelector (com.hazelcast.cluster.MemberSelector)3 ExecutionCallback (com.hazelcast.core.ExecutionCallback)1