Search in sources :

Example 96 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class ClientExecutorServiceExecuteTest method testExecute.

@Test
public void testExecute() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    service.execute(new MapPutRunnable(mapName));
    IMap map = client.getMap(mapName);
    assertSizeEventually(1, map);
}
Also used : IMap(com.hazelcast.map.IMap) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 97 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class ClientExecutorServiceSubmitTest method submitCallablePartitionAware_WithExecutionCallback.

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

        public void onResponse(UUID 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.map.IMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) MapPutPartitionAwareCallable(com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable) UUID(java.util.UUID) 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 98 with IMap

use of com.hazelcast.map.IMap 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 99 with IMap

use of com.hazelcast.map.IMap 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.map.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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 100 with IMap

use of com.hazelcast.map.IMap 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)

Aggregations

IMap (com.hazelcast.map.IMap)292 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)73 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32