Search in sources :

Example 1 with MapPutPartitionAwareCallable

use of com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable 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 2 with MapPutPartitionAwareCallable

use of com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable 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 3 with MapPutPartitionAwareCallable

use of com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable 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)

Example 4 with MapPutPartitionAwareCallable

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

the class ClientDurableExecutorServiceSubmitTest method submitCallablePartitionAware_WithExecutionCallback.

@Test
public void submitCallablePartitionAware_WithExecutionCallback() {
    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> runnable = new MapPutPartitionAwareCallable<String, String>(mapName, key);
    final AtomicReference<String> result = new AtomicReference<String>();
    final CountDownLatch responseLatch = new CountDownLatch(1);
    service.submit(runnable).andThen(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 : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.core.IMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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)

Aggregations

MapPutPartitionAwareCallable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareCallable)4 IMap (com.hazelcast.core.IMap)4 Member (com.hazelcast.core.Member)4 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 IExecutorService (com.hazelcast.core.IExecutorService)2 DurableExecutorService (com.hazelcast.durableexecutor.DurableExecutorService)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2