Search in sources :

Example 1 with IMap

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

the class ClientXATest method testParallel.

@Test
public void testParallel() throws Exception {
    Hazelcast.newHazelcastInstance();
    final HazelcastInstance client = HazelcastClient.newHazelcastClient();
    // this is needed due to a racy bug in atomikos
    txn(client);
    int size = 100;
    ExecutorService executorService = Executors.newFixedThreadPool(5);
    final CountDownLatch latch = new CountDownLatch(size);
    for (int i = 0; i < size; i++) {
        executorService.execute(new Runnable() {

            public void run() {
                try {
                    txn(client);
                } catch (Exception e) {
                    logger.severe("Exception during txn", e);
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    assertOpenEventually(latch, 20);
    final IMap m = client.getMap("m");
    for (int i = 0; i < 10; i++) {
        assertFalse(m.isLocked(i));
    }
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 2 with IMap

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

the class ClientTxnMapTest method txn_map_containsKey_skips_server_side_near_cache.

@Test
public void txn_map_containsKey_skips_server_side_near_cache() {
    String mapName = "test";
    int keyInServerNearCache = 1;
    IMap serverMap = prepareServerAndGetServerMap(mapName, keyInServerNearCache);
    TransactionalMap clientTxnMap = getClientTransactionalMap(mapName);
    assertTrue(clientTxnMap.containsKey(keyInServerNearCache));
    assertEquals(0, serverMap.getLocalMapStats().getNearCacheStats().getHits());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with IMap

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

the class ClientTxnMapTest method txn_map_get_skips_server_side_near_cache.

@Test
public void txn_map_get_skips_server_side_near_cache() {
    String mapName = "test";
    int keyInServerNearCache = 1;
    IMap serverMap = prepareServerAndGetServerMap(mapName, keyInServerNearCache);
    TransactionalMap clientTxnMap = getClientTransactionalMap(mapName);
    assertNotNull(clientTxnMap.get(keyInServerNearCache));
    assertEquals(0, serverMap.getLocalMapStats().getNearCacheStats().getHits());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with IMap

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

the class ClientTxnMapTest method testTnxMapDelete.

@Test
public void testTnxMapDelete() throws Exception {
    final String mapName = randomString();
    final String key = "key1";
    final String value = "old1";
    IMap map = client.getMap(mapName);
    map.put(key, value);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    txMap.delete(key);
    context.commitTransaction();
    assertNull(map.get(key));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with IMap

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

the class ClientTxnMapTest method testKeysetAndValuesWithPredicates.

@Test
public void testKeysetAndValuesWithPredicates() throws Exception {
    final String mapName = randomString();
    IMap map = client.getMap(mapName);
    final SampleTestObjects.Employee emp1 = new SampleTestObjects.Employee("abc-123-xvz", 34, true, 10D);
    final SampleTestObjects.Employee emp2 = new SampleTestObjects.Employee("abc-123-xvz", 20, true, 10D);
    map.put(emp1, emp1);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalMap txMap = context.getMap(mapName);
    assertNull(txMap.put(emp2, emp2));
    assertEquals(2, txMap.size());
    assertEquals(2, txMap.keySet().size());
    assertEquals(0, txMap.keySet(Predicates.sql("age = 10")).size());
    assertEquals(0, txMap.values(Predicates.sql("age = 10")).size());
    assertEquals(2, txMap.keySet(Predicates.sql("age >= 10")).size());
    assertEquals(2, txMap.values(Predicates.sql("age >= 10")).size());
    context.commitTransaction();
    assertEquals(2, map.size());
    assertEquals(2, map.values().size());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) TransactionContext(com.hazelcast.transaction.TransactionContext) SampleTestObjects(com.hazelcast.query.SampleTestObjects) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) 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