Search in sources :

Example 76 with IMap

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

the class HazelcastConnectorTest method when_readMap_withPredicateAndFunction.

@Test
public void when_readMap_withPredicateAndFunction() {
    IMap<Integer, Integer> sourceMap = instance().getMap(sourceName);
    range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, i));
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", readMapP(sourceName, e -> !e.getKey().equals(0), Map.Entry::getKey));
    Vertex sink = dag.newVertex("sink", writeListP(sinkName));
    dag.edge(between(source, sink));
    instance().getJet().newJob(dag).join();
    IList<Object> list = instance().getList(sinkName);
    assertEquals(ENTRY_COUNT - 1, list.size());
    assertFalse(list.contains(0));
    assertTrue(list.contains(1));
}
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) 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 77 with IMap

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

the class HazelcastConnectorTest method when_streamMap_withFilterAndProjection.

@Test
public void when_streamMap_withFilterAndProjection() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", SourceProcessors.<Integer, Integer, Integer>streamMapP(streamSourceName, event -> event.getKey() != 0, EventJournalMapEvent::getKey, START_FROM_OLDEST, eventTimePolicy(i -> i, limitingLag(0), 1, 0, 10_000)));
    Vertex sink = dag.newVertex("sink", writeListP(streamSinkName));
    dag.edge(between(source, sink));
    Job job = instance().getJet().newJob(dag);
    IMap<Integer, Integer> sourceMap = instance().getMap(streamSourceName);
    range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, i));
    assertSizeEventually(ENTRY_COUNT - 1, instance().getList(streamSinkName));
    assertFalse(instance().getList(streamSinkName).contains(0));
    assertTrue(instance().getList(streamSinkName).contains(1));
    job.cancel();
}
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) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 78 with IMap

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

the class ReadMapOrCacheP_ConsistencyTest method test_addingItems.

private void test_addingItems(IMap<Integer, Integer> map, ClientConfig clientConfig) {
    // use low initial item count to force resizing
    int initialItemCount = 1024;
    for (int i = 0; i < initialItemCount; i++) {
        map.put(i, i);
    }
    Pipeline p = Pipeline.create();
    p.readFrom(mapSource(clientConfig)).map(o -> {
        proceedLatch.await();
        // apply some gentle backpressure
        if (processedCount.incrementAndGet() % 128 == 0) {
            Thread.sleep(10);
        }
        return o.getKey();
    }).setLocalParallelism(1).writeTo(AssertionSinks.assertCollected(list -> {
        // check no duplicates
        Set<Integer> collected = new HashSet<>(list);
        assertEquals("there were duplicates", list.size(), collected.size());
        // check all initial items before iteration started
        for (int i = 0; i < initialItemCount; i++) {
            assertTrue("key " + i + " was missing", collected.contains(i));
        }
    }));
    Job job = hz.getJet().newJob(p);
    proceedLatch.countDown();
    // put some additional items
    for (int i = initialItemCount; i < initialItemCount + NUM_ITEMS; i++) {
        map.put(i, i);
    }
    job.join();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) IntStream(java.util.stream.IntStream) Address(com.hazelcast.cluster.Address) Member(com.hazelcast.cluster.Member) Sources.remoteMap(com.hazelcast.jet.pipeline.Sources.remoteMap) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Map(java.util.Map) UuidUtil(com.hazelcast.internal.util.UuidUtil) ClientConfig(com.hazelcast.client.config.ClientConfig) Job(com.hazelcast.jet.Job) Before(org.junit.Before) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Sources.map(com.hazelcast.jet.pipeline.Sources.map) Hazelcast(com.hazelcast.core.Hazelcast) Entry(java.util.Map.Entry) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HashSet(java.util.HashSet) Set(java.util.Set) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 79 with IMap

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

the class BatchStageTest method mapUsingIMap_when_functionThrows_then_jobFails.

@Test
public void mapUsingIMap_when_functionThrows_then_jobFails() {
    // Given
    IMap<Integer, String> map = member.getMap(randomMapName());
    map.put(1, "1");
    // When
    BatchStage<Entry<Integer, String>> stage = batchStageFromList(singletonList(1)).groupingKey(i -> i).mapUsingIMap(map, (k, v) -> {
        throw new RuntimeException("mock error");
    });
    // Then
    stage.writeTo(sink);
    Job job = hz().getJet().newJob(p);
    assertThatThrownBy(() -> job.join()).hasMessageContaining("mock error");
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Arrays(java.util.Arrays) ServiceFactories.sharedService(com.hazelcast.jet.pipeline.ServiceFactories.sharedService) QuickTest(com.hazelcast.test.annotation.QuickTest) QuadFunction(com.hazelcast.jet.function.QuadFunction) Collections.singletonList(java.util.Collections.singletonList) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Arrays.asList(java.util.Arrays.asList) DAG(com.hazelcast.jet.core.DAG) PredicateEx(com.hazelcast.function.PredicateEx) FunctionEx(com.hazelcast.function.FunctionEx) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) Collections.emptyList(java.util.Collections.emptyList) Tag(com.hazelcast.jet.datamodel.Tag) Set(java.util.Set) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Tuple3.tuple3(com.hazelcast.jet.datamodel.Tuple3.tuple3) List(java.util.List) Stream(java.util.stream.Stream) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) IntStream(java.util.stream.IntStream) Processors(com.hazelcast.jet.core.processor.Processors) CompletableFuture(java.util.concurrent.CompletableFuture) ServiceFactories.nonSharedService(com.hazelcast.jet.pipeline.ServiceFactories.nonSharedService) Function(java.util.function.Function) JoinClause.joinMapEntries(com.hazelcast.jet.pipeline.JoinClause.joinMapEntries) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AssertionSinks.assertAnyOrder(com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AssertionSinks.assertOrdered(com.hazelcast.jet.pipeline.test.AssertionSinks.assertOrdered) Util.entry(com.hazelcast.jet.Util.entry) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Tuple2(com.hazelcast.jet.datamodel.Tuple2) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job) Tuple3(com.hazelcast.jet.datamodel.Tuple3) HazelcastInstance(com.hazelcast.core.HazelcastInstance) LongStream(java.util.stream.LongStream) AbstractStage.transformOf(com.hazelcast.jet.impl.pipeline.AbstractStage.transformOf) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Vertex(com.hazelcast.jet.core.Vertex) TestSources(com.hazelcast.jet.pipeline.test.TestSources) Collectors.toList(java.util.stream.Collectors.toList) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) TriFunction(com.hazelcast.jet.function.TriFunction) Collections(java.util.Collections) Util(com.hazelcast.jet.Util) Tuple4.tuple4(com.hazelcast.jet.datamodel.Tuple4.tuple4) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Entry(java.util.Map.Entry) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 80 with IMap

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

the class HazelcastXATest method testParallel.

@Test
public void testParallel() throws Exception {
    final HazelcastInstance instance = createHazelcastInstance();
    // this is needed due to a racy bug in atomikos
    txn(instance);
    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(instance);
                } catch (Exception e) {
                    LOGGER.severe("Exception during txn", e);
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    assertOpenEventually(latch, 20);
    final IMap map = instance.getMap("m");
    for (int i = 0; i < 10; i++) {
        assertFalse(map.isLocked(i));
    }
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) 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