Search in sources :

Example 1 with ExecutionCallback

use of com.hazelcast.core.ExecutionCallback 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 ExecutionCallback

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

the class ClientDurableExecutorServiceSubmitTest method submitRunnableToKeyOwner.

@Test
public void submitRunnableToKeyOwner() {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submitToKeyOwner(runnable, "key").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 3 with ExecutionCallback

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

the class ClientDurableExecutorServiceSubmitTest method submitRunnablePartitionAware_withExecutionCallback.

@Test
public void submitRunnablePartitionAware_withExecutionCallback() {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String mapName = randomString();
    String key = HazelcastTestSupport.generateKeyOwnedBy(server);
    Member member = server.getCluster().getLocalMember();
    Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submit(runnable).andThen(new ExecutionCallback() {

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

        @Override
        public void onFailure(Throwable t) {
        }
    });
    IMap map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertTrue(map.containsKey(member.getUuid()));
}
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) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ExecutionCallback

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

the class ClientExecutorServiceSubmitTest method testSubmitRunnable_withExecutionCallback.

@Test
public void testSubmitRunnable_withExecutionCallback() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    Runnable runnable = new MapPutRunnable(mapName);
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submit(runnable, 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 : 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) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) 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 5 with ExecutionCallback

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

the class ClientExecutorServiceSubmitTest method submitRunnablePartitionAware_withExecutionCallback.

@Test
public void submitRunnablePartitionAware_withExecutionCallback() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    String key = HazelcastTestSupport.generateKeyOwnedBy(server);
    Member member = server.getCluster().getLocalMember();
    Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submit(runnable, new ExecutionCallback() {

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

        @Override
        public void onFailure(Throwable t) {
        }
    });
    IMap map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertTrue(map.containsKey(member.getUuid()));
}
Also used : IMap(com.hazelcast.core.IMap) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) 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)

Aggregations

ExecutionCallback (com.hazelcast.core.ExecutionCallback)44 QuickTest (com.hazelcast.test.annotation.QuickTest)39 Test (org.junit.Test)39 ParallelTest (com.hazelcast.test.annotation.ParallelTest)37 CountDownLatch (java.util.concurrent.CountDownLatch)24 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)11 IMap (com.hazelcast.core.IMap)10 IExecutorService (com.hazelcast.core.IExecutorService)9 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)9 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)8 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Member (com.hazelcast.core.Member)7 AssertTask (com.hazelcast.test.AssertTask)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 MemberLeftException (com.hazelcast.core.MemberLeftException)4 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Config (com.hazelcast.config.Config)3 DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)3