Search in sources :

Example 71 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class QueryCacheConfigTest method testDifferentQueryCacheInstancesObtained_whenIMapConfiguredWithWildCard.

@Test
public void testDifferentQueryCacheInstancesObtained_whenIMapConfiguredWithWildCard() {
    QueryCacheConfig cacheConfig = new QueryCacheConfig();
    cacheConfig.setName("cache");
    cacheConfig.getPredicateConfig().setSql("__key > 10");
    MapConfig mapConfig = new MapConfig();
    mapConfig.setName("test*");
    mapConfig.addQueryCacheConfig(cacheConfig);
    Config config = new Config();
    config.addMapConfig(mapConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Integer> map1 = getMap(node, "test1");
    IMap<Integer, Integer> map2 = getMap(node, "test2");
    QueryCache<Integer, Integer> queryCache1 = map1.getQueryCache("cache");
    QueryCache<Integer, Integer> queryCache2 = map2.getQueryCache("cache");
    for (int i = 0; i < 20; i++) {
        map1.put(i, i);
    }
    for (int i = 0; i < 30; i++) {
        map2.put(i, i);
    }
    assertQueryCacheSizeEventually(9, queryCache1);
    assertQueryCacheSizeEventually(19, queryCache2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 72 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class QueryCacheEventLostListenerTest method testListenerNotified_uponEventLoss.

@Test
public void testListenerNotified_uponEventLoss() {
    String mapName = randomString();
    String queryCacheName = randomString();
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
    Config config = new Config();
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(1111);
    queryCacheConfig.setDelaySeconds(3);
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    mapConfig.setBackupCount(0);
    HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
    HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
    setTestSequencer(node, 9);
    setTestSequencer(node2, 9);
    IMap<Integer, Integer> map = getMap(node, mapName);
    node2.getMap(mapName);
    // set test sequencer to all nodes
    int count = 30;
    // expecting one lost event per partition
    final CountDownLatch lossCount = new CountDownLatch(1);
    final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            lossCount.countDown();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    assertOpenEventually(lossCount);
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 73 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class QueryCacheGuaranteesTest method continuesToReceiveEvents_afterNodeJoins.

@Test
public void continuesToReceiveEvents_afterNodeJoins() {
    String mapName = randomString();
    String queryCacheName = randomString();
    TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
    Config config = new Config();
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "271");
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(100);
    queryCacheConfig.setDelaySeconds(3);
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.addQueryCacheConfig(queryCacheConfig);
    HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map = getMap(node, mapName);
    final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("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 = 100; i < 120; i++) {
        map2.put(i, i);
    }
    HazelcastInstance node3 = instanceFactory.newHazelcastInstance(config);
    IMap<Integer, Integer> map3 = node3.getMap(mapName);
    for (int i = 150; i < 157; i++) {
        map3.put(i, i);
    }
    assertTrueEventually(new AssertTask() {

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

Example 74 with MapConfig

use of com.hazelcast.config.MapConfig 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, new SqlPredicate("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) SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 75 with MapConfig

use of com.hazelcast.config.MapConfig in project hazelcast by hazelcast.

the class QueryCachePredicateConfigTest method test_whenClassNameIsSet.

@Test
public void test_whenClassNameIsSet() {
    String mapName = randomString();
    String cacheName = randomString();
    Config config = new Config();
    MapConfig mapConfig = config.getMapConfig(mapName);
    QueryCacheConfig cacheConfig = new QueryCacheConfig(cacheName);
    PredicateConfig predicateConfig = cacheConfig.getPredicateConfig();
    predicateConfig.setClassName("com.hazelcast.map.impl.querycache.TestPredicate");
    mapConfig.addQueryCacheConfig(cacheConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Employee> map = getMap(node, mapName);
    for (int i = 0; i < 15; i++) {
        map.put(i, new Employee(i));
    }
    QueryCache<Integer, Employee> cache = map.getQueryCache(cacheName);
    assertEquals(0, cache.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.mapreduce.helpers.Employee) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) PredicateConfig(com.hazelcast.config.PredicateConfig) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapConfig (com.hazelcast.config.MapConfig)182 Config (com.hazelcast.config.Config)125 HazelcastInstance (com.hazelcast.core.HazelcastInstance)78 Test (org.junit.Test)75 QuickTest (com.hazelcast.test.annotation.QuickTest)68 ParallelTest (com.hazelcast.test.annotation.ParallelTest)62 MapStoreConfig (com.hazelcast.config.MapStoreConfig)43 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)28 NearCacheConfig (com.hazelcast.config.NearCacheConfig)27 MapIndexConfig (com.hazelcast.config.MapIndexConfig)20 QuorumConfig (com.hazelcast.config.QuorumConfig)19 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)18 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 PartitionedCluster (com.hazelcast.quorum.PartitionedCluster)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 BeforeClass (org.junit.BeforeClass)10 AssertTask (com.hazelcast.test.AssertTask)9