Search in sources :

Example 81 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class HazelcastConnectorTest method when_readMap_withProjectionToNull_then_nullsSkipped.

@Test
public void when_readMap_withProjectionToNull_then_nullsSkipped() {
    IMap<Integer, Entry<Integer, String>> sourceMap = instance().getMap(sourceName);
    range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, entry(i, i % 2 == 0 ? null : String.valueOf(i))));
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", readMapP(sourceName, new TruePredicate<>(), Projections.singleAttribute("value")));
    Vertex sink = dag.newVertex("sink", writeListP(sinkName));
    dag.edge(between(source, sink));
    instance().getJet().newJob(dag).join();
    checkContents_projectedToNull(sinkName);
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Entry(java.util.Map.Entry) TruePredicate(com.hazelcast.query.impl.predicates.TruePredicate) DAG(com.hazelcast.jet.core.DAG) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 82 with Vertex

use of com.hazelcast.jet.core.Vertex 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 83 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class HazelcastConnectorTest method test_defaultFilter_cacheJournal.

@Test
public void test_defaultFilter_cacheJournal() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", streamCacheP(streamSourceName, START_FROM_OLDEST, eventTimePolicy(Entry<Integer, Integer>::getValue, limitingLag(0), 1, 0, 10_000)));
    Vertex sink = dag.newVertex("sink", writeListP(streamSinkName));
    dag.edge(between(source, sink));
    Job job = instance().getJet().newJob(dag);
    ICache<Object, Object> sourceCache = instance().getCacheManager().getCache(streamSourceName);
    // ADDED
    sourceCache.put(1, 1);
    // REMOVED - filtered out
    sourceCache.remove(1);
    // UPDATED
    sourceCache.put(1, 2);
    IList<Entry<Integer, Integer>> sinkList = instance().getList(streamSinkName);
    assertTrueEventually(() -> {
        assertEquals(2, sinkList.size());
        Entry<Integer, Integer> e = sinkList.get(0);
        assertEquals(Integer.valueOf(1), e.getKey());
        assertEquals(Integer.valueOf(1), e.getValue());
        e = sinkList.get(1);
        assertEquals(Integer.valueOf(1), e.getKey());
        assertEquals(Integer.valueOf(2), e.getValue());
    });
    job.cancel();
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Entry(java.util.Map.Entry) 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 84 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class HazelcastConnectorTest method when_streamCache.

@Test
public void when_streamCache() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", streamCacheP(streamSourceName, START_FROM_OLDEST, eventTimePolicy(Entry<Integer, Integer>::getValue, limitingLag(0), 1, 0, 10_000)));
    Vertex sink = dag.newVertex("sink", writeListP(streamSinkName));
    dag.edge(between(source, sink));
    Job job = instance().getJet().newJob(dag);
    ICache<Integer, Integer> sourceCache = instance().getCacheManager().getCache(streamSourceName);
    range(0, ENTRY_COUNT).forEach(i -> sourceCache.put(i, i));
    assertSizeEventually(ENTRY_COUNT, instance().getList(streamSinkName));
    job.cancel();
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Entry(java.util.Map.Entry) 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 85 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast by hazelcast.

the class HazelcastConnectorTest method when_readMap_and_writeMap.

@Test
public void when_readMap_and_writeMap() {
    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));
    Vertex sink = dag.newVertex("sink", writeMapP(sinkName));
    dag.edge(between(source, sink));
    instance().getJet().newJob(dag).join();
    assertEquals(ENTRY_COUNT, instance().getMap(sinkName).size());
}
Also used : 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

Vertex (com.hazelcast.jet.core.Vertex)189 DAG (com.hazelcast.jet.core.DAG)130 Test (org.junit.Test)95 QuickTest (com.hazelcast.test.annotation.QuickTest)57 Job (com.hazelcast.jet.Job)53 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)48 Entry (java.util.Map.Entry)41 List (java.util.List)28 Edge.between (com.hazelcast.jet.core.Edge.between)26 Map (java.util.Map)26 Assert.assertEquals (org.junit.Assert.assertEquals)23 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)21 IntStream (java.util.stream.IntStream)21 Assert.assertTrue (org.junit.Assert.assertTrue)19 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)18 Category (org.junit.experimental.categories.Category)18 Collectors.toList (java.util.stream.Collectors.toList)17 Nonnull (javax.annotation.Nonnull)17 FunctionEx (com.hazelcast.function.FunctionEx)15 Edge (com.hazelcast.jet.core.Edge)15