Search in sources :

Example 1 with MapPutPartitionAwareRunnable

use of com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable 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).thenRun(() -> responseLatch.countDown());
    IMap map = client.getMap(mapName);
    assertOpenEventually("responseLatch", responseLatch);
    assertTrue(map.containsKey(member.getUuid()));
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.map.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.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with MapPutPartitionAwareRunnable

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

the class ClientExecutorServiceSubmitTest method submitRunnablePartitionAware_withExecutionCallback.

@Test
public void submitRunnablePartitionAware_withExecutionCallback() {
    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.map.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.cluster.Member) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MapPutPartitionAwareRunnable

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

the class ClientExecutorServiceSubmitTest method submitRunnablePartitionAware.

@Test
public void submitRunnablePartitionAware() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    String key = HazelcastTestSupport.generateKeyOwnedBy(server);
    final Member member = server.getCluster().getLocalMember();
    // this task should execute on a node owning the given key argument,
    // the action is to put the UUid of the executing node into a map with the given name
    Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
    service.submit(runnable);
    final IMap map = client.getMap(mapName);
    assertTrueEventually(new AssertTask() {

        public void run() {
            assertTrue(map.containsKey(member.getUuid()));
        }
    });
}
Also used : IMap(com.hazelcast.map.IMap) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MapPutPartitionAwareRunnable

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

the class ClientExecutorServiceSubmitTest method submitRunnablePartitionAware_withResult.

@Test
public void submitRunnablePartitionAware_withResult() throws Exception {
    IExecutorService service = client.getExecutorService(randomString());
    String expectedResult = "result";
    String mapName = randomString();
    String key = HazelcastTestSupport.generateKeyOwnedBy(server);
    final Member member = server.getCluster().getLocalMember();
    Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
    Future result = service.submit(runnable, expectedResult);
    final IMap map = client.getMap(mapName);
    assertEquals(expectedResult, result.get());
    assertTrueEventually(new AssertTask() {

        public void run() {
            assertTrue(map.containsKey(member.getUuid()));
        }
    });
}
Also used : IMap(com.hazelcast.map.IMap) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with MapPutPartitionAwareRunnable

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

the class ClientDurableExecutorServiceSubmitTest method submitRunnablePartitionAware_withResult.

@Test
public void submitRunnablePartitionAware_withResult() throws Exception {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String expectedResult = "result";
    String mapName = randomString();
    String key = HazelcastTestSupport.generateKeyOwnedBy(server);
    final Member member = server.getCluster().getLocalMember();
    Runnable runnable = new MapPutPartitionAwareRunnable<String>(mapName, key);
    Future result = service.submit(runnable, expectedResult);
    final IMap map = client.getMap(mapName);
    assertEquals(expectedResult, result.get());
    assertTrueEventually(new AssertTask() {

        public void run() {
            assertTrue(map.containsKey(member.getUuid()));
        }
    });
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.map.IMap) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareRunnable(com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)6 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)6 Member (com.hazelcast.cluster.Member)6 IMap (com.hazelcast.map.IMap)6 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 AssertTask (com.hazelcast.test.AssertTask)4 IExecutorService (com.hazelcast.core.IExecutorService)3 DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Future (java.util.concurrent.Future)2 ExecutionCallback (com.hazelcast.core.ExecutionCallback)1 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)1