Search in sources :

Example 16 with AppendCallable

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

the class ClientExecutorServiceSubmitTest method submitCallable_withExecutionCallback.

@Test
public void submitCallable_withExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(1);
    String msg = randomString();
    Callable runnable = new AppendCallable(msg);
    MemberSelector selector = new SelectAllMembers();
    final AtomicReference<Object> result = new AtomicReference<Object>();
    service.submit(runnable, selector, new ExecutionCallback() {

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

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

Example 17 with AppendCallable

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

the class ClientExecutorServiceSubmitTest method submitCallableToAllMembers_withMultiExecutionCallback.

@Test
public void submitCallableToAllMembers_withMultiExecutionCallback() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(CLUSTER_SIZE);
    final CountDownLatch completeLatch = new CountDownLatch(CLUSTER_SIZE);
    final String msg = randomString();
    Callable callable = new AppendCallable(msg);
    service.submitToAllMembers(callable, 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.executor.tasks.AppendCallable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) NullCallable(com.hazelcast.client.executor.tasks.NullCallable) Callable(java.util.concurrent.Callable) MapPutPartitionAwareCallable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable) AppendCallable(com.hazelcast.client.executor.tasks.AppendCallable) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with AppendCallable

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

the class ClientExecutorServiceSubmitTest method testSubmitCallable_withExecutionCallback.

@Test
public void testSubmitCallable_withExecutionCallback() throws Exception {
    IExecutorService service = client.getExecutorService(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, 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.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) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

AppendCallable (com.hazelcast.client.executor.tasks.AppendCallable)18 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)18 ParallelTest (com.hazelcast.test.annotation.ParallelTest)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.executor.tasks.MapPutPartitionAwareCallable)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 NullCallable (com.hazelcast.client.executor.tasks.NullCallable)4 Member (com.hazelcast.core.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.executor.tasks.SelectAllMembers)3 MemberSelector (com.hazelcast.core.MemberSelector)3 ExecutionCallback (com.hazelcast.core.ExecutionCallback)1