Search in sources :

Example 16 with IExecutorService

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

the class ClientExecutorServiceSubmitTest method testSubmitCallable_withMemberSelector.

@Test
public void testSubmitCallable_withMemberSelector() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    MemberSelector selectAll = new SelectAllMembers();
    Future<String> f = service.submit(callable, selectAll);
    assertEquals(msg + AppendCallable.APPENDAGE, f.get());
}
Also used : MemberSelector(com.hazelcast.core.MemberSelector) AppendCallable(com.hazelcast.client.executor.tasks.AppendCallable) SelectAllMembers(com.hazelcast.client.executor.tasks.SelectAllMembers) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with IExecutorService

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

the class ClientExecutorServiceSubmitTest method submitCallableToAllMembers.

@Test
public void submitCallableToAllMembers() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String msg = randomString();
    Callable<String> callable = new AppendCallable(msg);
    Map<Member, Future<String>> map = service.submitToAllMembers(callable);
    for (Member member : map.keySet()) {
        Future<String> result = map.get(member);
        assertEquals(msg + AppendCallable.APPENDAGE, result.get());
    }
}
Also used : AppendCallable(com.hazelcast.client.executor.tasks.AppendCallable) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with IExecutorService

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

the class ClientExecutorServiceSubmitTest method testSubmitRunnable_WithResult.

@Test
public void testSubmitRunnable_WithResult() throws ExecutionException, InterruptedException {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    Object givenResult = "givenResult";
    Future future = service.submit(new MapPutRunnable(mapName), givenResult);
    Object result = future.get();
    IMap map = client.getMap(mapName);
    assertEquals(givenResult, result);
    assertEquals(1, map.size());
}
Also used : IMap(com.hazelcast.core.IMap) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with IExecutorService

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

the class ClientExecutorServiceSubmitTest method submitCallablePartitionAware_WithExecutionCallback.

@Test
public void submitCallablePartitionAware_WithExecutionCallback() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    IMap map = client.getMap(mapName);
    String key = HazelcastTestSupport.generateKeyOwnedBy(server);
    Member member = server.getCluster().getLocalMember();
    Callable<String> runnable = new MapPutPartitionAwareCallable<String, String>(mapName, key);
    final AtomicReference<String> result = new AtomicReference<String>();
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submit(runnable, new ExecutionCallback<String>() {

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

        public void onFailure(Throwable t) {
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertEquals(member.getUuid(), result.get());
    assertTrue(map.containsKey(member.getUuid()));
}
Also used : IMap(com.hazelcast.core.IMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareCallable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with IExecutorService

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

the class ClientExecutorServiceSubmitTest method submitCallablePartitionAware.

@Test
public void submitCallablePartitionAware() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    IMap map = client.getMap(mapName);
    String key = HazelcastTestSupport.generateKeyOwnedBy(server);
    Member member = server.getCluster().getLocalMember();
    Callable<String> callable = new MapPutPartitionAwareCallable<String, String>(mapName, key);
    Future<String> result = service.submit(callable);
    assertEquals(member.getUuid(), result.get());
    assertTrue(map.containsKey(member.getUuid()));
}
Also used : IMap(com.hazelcast.core.IMap) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareCallable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

IExecutorService (com.hazelcast.core.IExecutorService)152 QuickTest (com.hazelcast.test.annotation.QuickTest)138 Test (org.junit.Test)138 ParallelTest (com.hazelcast.test.annotation.ParallelTest)137 HazelcastInstance (com.hazelcast.core.HazelcastInstance)66 Member (com.hazelcast.core.Member)57 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)46 Future (java.util.concurrent.Future)36 IMap (com.hazelcast.core.IMap)32 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)28 CountDownLatch (java.util.concurrent.CountDownLatch)28 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)25 ExecutorConfig (com.hazelcast.config.ExecutorConfig)20 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)20 Config (com.hazelcast.config.Config)19 ExecutionException (java.util.concurrent.ExecutionException)18 AppendCallable (com.hazelcast.client.executor.tasks.AppendCallable)16 AssertTask (com.hazelcast.test.AssertTask)16 ICompletableFuture (com.hazelcast.core.ICompletableFuture)13 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)11