Search in sources :

Example 71 with IMap

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

the class MapLoaderFuturesTest method zero_remaining_loading_future_after_multiple_loadAll.

@Test
public void zero_remaining_loading_future_after_multiple_loadAll() {
    String mapName = "load-futures";
    int keyCountToLoad = 10;
    MapStoreConfig mapStoreConfig = new MapStoreConfig().setImplementation(new SimpleMapLoader(keyCountToLoad, false));
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setMapStoreConfig(mapStoreConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap map = node.getMap(mapName);
    for (int i = 0; i < 3; i++) {
        map.loadAll(true);
    }
    assertEquals(keyCountToLoad, map.size());
    assertEquals(0, loadingFutureCount(mapName, node));
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with IMap

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

the class MapStoreWithPredicateTest method testKeySetWithPredicate_checksMapStoreLoad.

@Test
public void testKeySetWithPredicate_checksMapStoreLoad() {
    EventBasedMapStore<String, Integer> testMapStore = new EventBasedMapStore<String, Integer>();
    Map<String, Integer> mapForStore = new HashMap<String, Integer>();
    mapForStore.put("key1", 17);
    mapForStore.put("key2", 37);
    mapForStore.put("key3", 47);
    testMapStore.getStore().putAll(mapForStore);
    Config config = newConfig(testMapStore, 0);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IMap map = instance.getMap("default");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            Set expected = map.keySet(Predicates.greaterThan("value", 1));
            assertEquals(3, expected.size());
            assertContains(expected, "key1");
            assertContains(expected, "key2");
            assertContains(expected, "key3");
        }
    });
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Set(java.util.Set) HashMap(java.util.HashMap) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 73 with IMap

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

the class MapStoreWithPredicateTest method testValuesWithPredicate_checksMapStoreLoad.

@Test
public void testValuesWithPredicate_checksMapStoreLoad() {
    EventBasedMapStore<String, Integer> testMapStore = new EventBasedMapStore<String, Integer>();
    Map<String, Integer> mapForStore = new HashMap<String, Integer>();
    mapForStore.put("key1", 17);
    mapForStore.put("key2", 37);
    mapForStore.put("key3", 47);
    testMapStore.getStore().putAll(mapForStore);
    Config config = newConfig(testMapStore, 0);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IMap map = instance.getMap("default");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            final Collection values = map.values(Predicates.greaterThan("value", 1));
            assertEquals(3, values.size());
            assertContains(values, 17);
            assertContains(values, 37);
            assertContains(values, 47);
        }
    });
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashMap(java.util.HashMap) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with IMap

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

the class PartitionIndexingTest method assertPartitionsIndexedCorrectly.

private static void assertPartitionsIndexedCorrectly(int expectedPartitions, IMap... maps) {
    Map<String, BitSet> indexToPartitions = new HashMap<String, BitSet>();
    for (IMap map : maps) {
        for (Indexes indexes : getAllIndexes(map)) {
            for (InternalIndex index : indexes.getIndexes()) {
                String indexName = index.getName();
                BitSet indexPartitions = indexToPartitions.get(indexName);
                if (indexPartitions == null) {
                    indexPartitions = new BitSet();
                    indexToPartitions.put(indexName, indexPartitions);
                }
                for (int partition = 0; partition < expectedPartitions; ++partition) {
                    if (index.hasPartitionIndexed(partition)) {
                        assertFalse("partition #" + partition + " is already indexed by " + indexName, indexPartitions.get(partition));
                        indexPartitions.set(partition);
                    }
                }
            }
        }
    }
    for (Map.Entry<String, BitSet> indexEntry : indexToPartitions.entrySet()) {
        String indexName = indexEntry.getKey();
        BitSet indexPartitions = indexEntry.getValue();
        int actualPartitions = indexPartitions.cardinality();
        assertEquals(indexName + " is missing " + (expectedPartitions - actualPartitions) + " partitions", expectedPartitions, actualPartitions);
    }
}
Also used : IMap(com.hazelcast.map.IMap) HashMap(java.util.HashMap) BitSet(java.util.BitSet) Accessors.getAllIndexes(com.hazelcast.test.Accessors.getAllIndexes) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 75 with IMap

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

the class HazelcastConnectorTest method test_writeMapWithNearCache.

@Test
public void test_writeMapWithNearCache() {
    List<Integer> items = range(0, ENTRY_COUNT).boxed().collect(toList());
    sinkName = "nearCache-" + randomName();
    DAG dag = new DAG();
    Vertex src = dag.newVertex("src", () -> new TestProcessors.ListSource(items)).localParallelism(1);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP(sinkName, i -> i, i -> i));
    dag.edge(between(src, sink));
    instance().getJet().newJob(dag).join();
    IMap<Object, Object> sinkMap = instance().getMap(sinkName);
    assertInstanceOf(NearCachedMapProxyImpl.class, sinkMap);
    assertEquals(ENTRY_COUNT, sinkMap.size());
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) IntStream.range(java.util.stream.IntStream.range) QuickTest(com.hazelcast.test.annotation.QuickTest) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) SourceProcessors.readListP(com.hazelcast.jet.core.processor.SourceProcessors.readListP) SourceProcessors.streamCacheP(com.hazelcast.jet.core.processor.SourceProcessors.streamCacheP) EventJournalCacheEvent(com.hazelcast.cache.EventJournalCacheEvent) TruePredicate(com.hazelcast.query.impl.predicates.TruePredicate) Map(java.util.Map) SinkProcessors.writeCacheP(com.hazelcast.jet.core.processor.SinkProcessors.writeCacheP) DAG(com.hazelcast.jet.core.DAG) ICacheManager(com.hazelcast.core.ICacheManager) Projections(com.hazelcast.projection.Projections) SourceProcessors.readCacheP(com.hazelcast.jet.core.processor.SourceProcessors.readCacheP) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) EventTimePolicy.noEventTime(com.hazelcast.jet.core.EventTimePolicy.noEventTime) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Category(org.junit.experimental.categories.Category) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) NearCacheConfig(com.hazelcast.config.NearCacheConfig) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) Assert.assertFalse(org.junit.Assert.assertFalse) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) Entry(java.util.Map.Entry) SinkProcessors.writeMapP(com.hazelcast.jet.core.processor.SinkProcessors.writeMapP) IntStream(java.util.stream.IntStream) NearCachedMapProxyImpl(com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl) BeforeClass(org.junit.BeforeClass) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) TestProcessors(com.hazelcast.jet.core.TestProcessors) Util.entry(com.hazelcast.jet.Util.entry) Job(com.hazelcast.jet.Job) Before(org.junit.Before) IList(com.hazelcast.collection.IList) Config(com.hazelcast.config.Config) SourceProcessors.streamMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamMapP) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) WatermarkPolicy.limitingLag(com.hazelcast.jet.core.WatermarkPolicy.limitingLag) Vertex(com.hazelcast.jet.core.Vertex) Collectors.toList(java.util.stream.Collectors.toList) Predicates(com.hazelcast.query.Predicates) ICache(com.hazelcast.cache.ICache) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) Util.mapPutEvents(com.hazelcast.jet.Util.mapPutEvents) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Edge.between(com.hazelcast.jet.core.Edge.between) SinkProcessors.writeListP(com.hazelcast.jet.core.processor.SinkProcessors.writeListP) Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) 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