Search in sources :

Example 26 with IMap

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

the class ClientExecutorServiceExecuteTest method testExecuteOnKeyOwner.

@Test
public void testExecuteOnKeyOwner() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    Member member = server1.getCluster().getLocalMember();
    final String targetUuid = member.getUuid();
    String key = generateKeyOwnedBy(server1);
    service.executeOnKeyOwner(new MapPutRunnable(mapName), key);
    final IMap map = client.getMap(mapName);
    assertTrueEventually(new AssertTask() {

        public void run() throws Exception {
            assertTrue(map.containsKey(targetUuid));
        }
    });
}
Also used : IMap(com.hazelcast.core.IMap) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) AssertTask(com.hazelcast.test.AssertTask) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with IMap

use of com.hazelcast.core.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.core.IMap) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 28 with IMap

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

the class ExecutorServiceLiteMemberTest method test_executeRunnable_onLiteMember.

@Test
public void test_executeRunnable_onLiteMember() {
    final HazelcastInstance lite1 = factory.newHazelcastInstance(liteConfig);
    final HazelcastInstance lite2 = factory.newHazelcastInstance(liteConfig);
    factory.newHazelcastInstance();
    final HazelcastInstance client = factory.newHazelcastClient();
    final String name = randomString();
    final IExecutorService executor = client.getExecutorService(name);
    executor.execute(new ResultSettingRunnable(name), LITE_MEMBER_SELECTOR);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final IMap<Object, Object> results = lite1.getMap(name);
            assertEquals(1, results.size());
            final boolean executedOnLite1 = results.containsKey(lite1.getCluster().getLocalMember());
            final boolean executedOnLite2 = results.containsKey(lite2.getCluster().getLocalMember());
            assertTrue(executedOnLite1 || executedOnLite2);
        }
    });
}
Also used : ResultSettingRunnable(com.hazelcast.executor.ExecutorServiceTestSupport.ResultSettingRunnable) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) ExecutorServiceTestSupport.randomString(com.hazelcast.executor.ExecutorServiceTestSupport.randomString) IExecutorService(com.hazelcast.core.IExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with IMap

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

the class ClientDurableExecutorServiceExecuteTest method testExecuteOnKeyOwner.

@Test
public void testExecuteOnKeyOwner() {
    DurableExecutorService service = client.getDurableExecutorService(randomString());
    String mapName = randomString();
    Member member = server.getCluster().getLocalMember();
    final String targetUuid = member.getUuid();
    String key = generateKeyOwnedBy(server);
    service.executeOnKeyOwner(new MapPutRunnable(mapName), key);
    final IMap map = client.getMap(mapName);
    assertTrueEventually(new AssertTask() {

        public void run() throws Exception {
            assertTrue(map.containsKey(targetUuid));
        }
    });
}
Also used : DurableExecutorService(com.hazelcast.durableexecutor.DurableExecutorService) IMap(com.hazelcast.core.IMap) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) AssertTask(com.hazelcast.test.AssertTask) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with IMap

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

the class ClientMapBasicTest method testEntrySet_withPredicate.

@Test
public void testEntrySet_withPredicate() {
    int max = 44;
    IMap<Integer, String> map = client.getMap(randomString());
    for (int key = 0; key < max; key++) {
        String value = key + "value";
        map.put(key, value);
    }
    Set<Map.Entry<Integer, String>> entrySet = map.entrySet(new SqlPredicate("this == 1value"));
    assertEquals(1, entrySet.size());
    Map.Entry<Integer, String> entry = entrySet.iterator().next();
    assertEquals(1, (int) entry.getKey());
    assertEquals("1value", entry.getValue());
}
Also used : SqlPredicate(com.hazelcast.query.SqlPredicate) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

IMap (com.hazelcast.core.IMap)258 Test (org.junit.Test)241 QuickTest (com.hazelcast.test.annotation.QuickTest)218 ParallelTest (com.hazelcast.test.annotation.ParallelTest)211 HazelcastInstance (com.hazelcast.core.HazelcastInstance)140 Config (com.hazelcast.config.Config)80 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)80 Map (java.util.Map)65 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)62 HashMap (java.util.HashMap)53 CountDownLatch (java.util.concurrent.CountDownLatch)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)39 AssertTask (com.hazelcast.test.AssertTask)36 MapStoreConfig (com.hazelcast.config.MapStoreConfig)34 MapConfig (com.hazelcast.config.MapConfig)31 TransactionalMap (com.hazelcast.core.TransactionalMap)29 IExecutorService (com.hazelcast.core.IExecutorService)28 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)27 TransactionContext (com.hazelcast.transaction.TransactionContext)21 TransactionException (com.hazelcast.transaction.TransactionException)21