Search in sources :

Example 41 with IMap

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

the class MapTransactionTest method testTxnReplace2.

@Test
public void testTxnReplace2() throws TransactionException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap map2 = h2.getMap("default");
    map2.put("1", "value2");
    boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap("default");
            assertEquals("value2", txMap.replace("1", "value3"));
            assertEquals("value3", txMap.get("1"));
            assertNull(map2.get("2"));
            return true;
        }
    });
    assertTrue(b);
    IMap map1 = h1.getMap("default");
    assertEquals("value3", map1.get("1"));
    assertEquals("value3", map2.get("1"));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 42 with IMap

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

the class QueryCacheNoEventLossTest method newQueryCacheOnNewNode.

private IMap newQueryCacheOnNewNode(final AtomicInteger eventLostCounter) {
    HazelcastInstance node = factory.newHazelcastInstance(newConfig());
    waitClusterForSafeState(node);
    IMap map = node.getMap(MAP_NAME);
    addEventLostListenerToQueryCache(map, eventLostCounter);
    return map;
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance)

Example 43 with IMap

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

the class QueryCacheGuaranteesTest method continuesToReceiveEvents_afterNodeShutdown.

@Test
public void continuesToReceiveEvents_afterNodeShutdown() {
    String mapName = randomString();
    String queryCacheName = randomString();
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
    Config config = new Config();
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(100);
    queryCacheConfig.setDelaySeconds(6);
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = (IMap<Integer, Integer>) node.<Integer, Integer>getMap(mapName);
    final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
    for (int i = 0; i < 30; i++) {
        map.put(i, i);
    }
    HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map2 = node2.getMap(mapName);
    for (int i = 200; i < 220; i++) {
        map2.put(i, i);
    }
    HazelcastInstance node3 = instanceFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map3 = node3.getMap(mapName);
    for (int i = 350; i < 357; i++) {
        map3.put(i, i);
    }
    node3.shutdown();
    for (int i = 220; i < 227; i++) {
        map2.put(i, i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(43, queryCache.size());
        }
    });
}
Also used : QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with IMap

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

the class QueryCacheMethodsWithPredicateTest method testKeySetIsNotBackedByQueryCache_nonIndexedAttribute.

@Test
public void testKeySetIsNotBackedByQueryCache_nonIndexedAttribute() {
    Assume.assumeTrue(inMemoryFormat != OBJECT);
    int count = 111;
    IMap<Employee, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    for (int i = 0; i < count; i++) {
        map.put(new Employee(i), new Employee(i));
    }
    Predicate<Employee, Employee> predicate = Predicates.lessThan("salary", Employee.MAX_SALARY);
    QueryCache<Employee, Employee> cache = map.getQueryCache(cacheName);
    cache.addIndex(IndexType.SORTED, "id");
    for (Map.Entry<Employee, Employee> entry : cache.entrySet(predicate)) {
        entry.getValue().setAge(Employee.MAX_AGE + 1);
    }
    for (Map.Entry<Employee, Employee> entry : cache.entrySet(predicate)) {
        assertNotEquals(Employee.MAX_AGE + 1, entry.getValue().getAge());
    }
}
Also used : Employee(com.hazelcast.map.impl.querycache.utils.Employee) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with IMap

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

the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.

@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
    final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
    final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
    populateMap(map, 1000);
    IFunction clear = (ignored) -> {
        map.clear();
        return null;
    };
    assertQueryCacheSizeEventually(0, clear, queryCache);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AttributeConfig(com.hazelcast.config.AttributeConfig) IFunction(com.hazelcast.core.IFunction) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HashSet(java.util.HashSet) PredicateConfig(com.hazelcast.config.PredicateConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueExtractor(com.hazelcast.query.extractor.ValueExtractor) ValueCollector(com.hazelcast.query.extractor.ValueCollector) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Predicate(com.hazelcast.query.Predicate) EntryEvent(com.hazelcast.core.EntryEvent) Config(com.hazelcast.config.Config) Set(java.util.Set) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Employee(com.hazelcast.map.impl.querycache.utils.Employee) Predicates(com.hazelcast.query.Predicates) QueryCache(com.hazelcast.map.QueryCache) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) EntryAdapter(com.hazelcast.core.EntryAdapter) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Employee(com.hazelcast.map.impl.querycache.utils.Employee) IFunction(com.hazelcast.core.IFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IMap (com.hazelcast.map.IMap)294 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)75 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