Search in sources :

Example 1 with DurableExecutorService

use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceSubmitTest method testSubmitRunnable_withExecutionCallback.

@Test
public void testSubmitRunnable_withExecutionCallback() {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submit(runnable).andThen(new ExecutionCallback() {

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

        public void onFailure(Throwable t) {
        }
    });
    IMap map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertEquals(1, map.size());
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.core.IMap) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with DurableExecutorService

use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceSubmitTest method submitCallablePartitionAware.

@Test
public void submitCallablePartitionAware() throws Exception {
    DurableExecutorService service = client.getDurableExecutorService(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 : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.core.IMap) 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)

Example 3 with DurableExecutorService

use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceSubmitTest method submitRunnable.

@Test
public void submitRunnable() {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    service.submit(runnable);
    IMap map = client.getMap(mapName);
    assertSizeEventually(1, map);
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.core.IMap) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with DurableExecutorService

use of com.hazelcast.durableexecutor.DurableExecutorService 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.executor.tasks.AppendCallable) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with DurableExecutorService

use of com.hazelcast.durableexecutor.DurableExecutorService in project hazelcast by hazelcast.

the class ClientDurableExecutorServiceSubmitTest method testSubmitRunnable_WithResult.

@Test
public void testSubmitRunnable_WithResult() throws Exception {
    DurableExecutorService service = client.getDurableExecutorService(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 : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.core.IMap) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) Future(java.util.concurrent.Future) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)41 ParallelTest (com.hazelcast.test.annotation.ParallelTest)39 QuickTest (com.hazelcast.test.annotation.QuickTest)39 Test (org.junit.Test)39 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)28 IMap (com.hazelcast.core.IMap)11 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)10 BasicTestCallable (com.hazelcast.executor.ExecutorServiceTestSupport.BasicTestCallable)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 SleepingTask (com.hazelcast.executor.ExecutorServiceTestSupport.SleepingTask)7 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)6 Member (com.hazelcast.core.Member)6 AppendCallable (com.hazelcast.client.executor.tasks.AppendCallable)5 AssertTask (com.hazelcast.test.AssertTask)5 Future (java.util.concurrent.Future)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 MapPutPartitionAwareCallable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable)4 ExecutionException (java.util.concurrent.ExecutionException)4 FailingCallable (com.hazelcast.client.executor.tasks.FailingCallable)3 ExecutionCallback (com.hazelcast.core.ExecutionCallback)3