Search in sources :

Example 11 with Sources

use of com.hazelcast.jet.pipeline.Sources in project zeppelin by apache.

the class HazelcastJetInterpreterUtilsTest method testDisplayNetworkFromDAGUtil.

@Test
public void testDisplayNetworkFromDAGUtil() {
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list("text")).flatMap(word -> traverseArray(word.toLowerCase().split("\\W+"))).setName("flat traversing").filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
    assertEquals(NETWORK_RESULT_1, HazelcastJetInterpreterUtils.displayNetworkFromDAG(p.toDag()));
}
Also used : PrintWriter(java.io.PrintWriter) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) AfterClass(org.junit.AfterClass) Properties(java.util.Properties) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) StringWriter(java.io.StringWriter) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Sources(com.hazelcast.jet.pipeline.Sources) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Assert.assertEquals(org.junit.Assert.assertEquals) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 12 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast by hazelcast.

the class JobSerializerTest method when_serializerIsRegistered_then_itIsAvailableForLocalMapSource.

@Test
public void when_serializerIsRegistered_then_itIsAvailableForLocalMapSource() {
    Map<Integer, Value> map = client().getMap(SOURCE_MAP_NAME);
    map.putAll(ImmutableMap.of(1, new Value(1), 2, new Value(2)));
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(Sources.<Integer, Value>map(SOURCE_MAP_NAME)).map(entry -> entry.getValue().value()).writeTo(AssertionSinks.assertAnyOrder(asList(1, 2)));
    client().getJet().newJob(pipeline, jobConfig()).join();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Observable(com.hazelcast.jet.Observable) CompletableFuture(java.util.concurrent.CompletableFuture) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Cache(javax.cache.Cache) ClientConfig(com.hazelcast.client.config.ClientConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nonnull(javax.annotation.Nonnull) SimpleEntry(java.util.AbstractMap.SimpleEntry) IList(com.hazelcast.collection.IList) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) Config(com.hazelcast.config.Config) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) ICache(com.hazelcast.cache.ICache) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast by hazelcast.

the class JobSerializerTest method when_serializerIsRegistered_then_itIsAvailableForLocalCacheSource.

@Test
public void when_serializerIsRegistered_then_itIsAvailableForLocalCacheSource() {
    Cache<Integer, Value> map = client().getCacheManager().getCache(SOURCE_CACHE_NAME);
    map.putAll(ImmutableMap.of(1, new Value(1), 2, new Value(2)));
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(Sources.<Integer, Value>cache(SOURCE_CACHE_NAME)).map(entry -> entry.getValue().value()).writeTo(AssertionSinks.assertAnyOrder(asList(1, 2)));
    client().getJet().newJob(pipeline, jobConfig()).join();
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Observable(com.hazelcast.jet.Observable) CompletableFuture(java.util.concurrent.CompletableFuture) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Cache(javax.cache.Cache) ClientConfig(com.hazelcast.client.config.ClientConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nonnull(javax.annotation.Nonnull) SimpleEntry(java.util.AbstractMap.SimpleEntry) IList(com.hazelcast.collection.IList) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) Config(com.hazelcast.config.Config) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IOException(java.io.IOException) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) ICache(com.hazelcast.cache.ICache) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast-jet by hazelcast.

the class WindowAggregateTransform_IntegrationTest method testSession.

@Test
public void testSession() {
    IMap<Long, String> map = instance.getMap("source");
    map.put(0L, "foo");
    map.put(3L, "bar");
    map.put(4L, "baz");
    map.put(10L, "flush-item");
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Long, String>mapJournal("source", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).window(WindowDefinition.session(2)).aggregate(toSet(), (winStart, winEnd, result) -> new WindowResult<>(winStart, winEnd, "", result)).drainTo(Sinks.list("sink"));
    instance.newJob(p);
    assertTrueEventually(() -> assertEquals(listToString(asList(new WindowResult<>(0, 2, "", set(entry(0L, "foo"))), new WindowResult<>(3, 6, "", set(entry(3L, "bar"), entry(4L, "baz"))))), listToString(instance.getHazelcastInstance().getList("sink"))), 5);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) GroupProperty(com.hazelcast.spi.properties.GroupProperty) WindowAggregateBuilder(com.hazelcast.jet.pipeline.WindowAggregateBuilder) RunWith(org.junit.runner.RunWith) EventJournalConfig(com.hazelcast.config.EventJournalConfig) TestUtil.set(com.hazelcast.jet.core.TestUtil.set) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) SlidingWindowDef(com.hazelcast.jet.pipeline.SlidingWindowDef) Util.entry(com.hazelcast.jet.Util.entry) Arrays.asList(java.util.Arrays.asList) Before(org.junit.Before) AggregateOperations.toThreeBags(com.hazelcast.jet.aggregate.AggregateOperations.toThreeBags) JetConfig(com.hazelcast.jet.config.JetConfig) StreamStage(com.hazelcast.jet.pipeline.StreamStage) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) AggregateOperations.toTwoBags(com.hazelcast.jet.aggregate.AggregateOperations.toTwoBags) AggregateOperations.toSet(com.hazelcast.jet.aggregate.AggregateOperations.toSet) Tag(com.hazelcast.jet.datamodel.Tag) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) ParallelTest(com.hazelcast.test.annotation.ParallelTest) Category(org.junit.experimental.categories.Category) StageWithWindow(com.hazelcast.jet.pipeline.StageWithWindow) TimestampedItem(com.hazelcast.jet.datamodel.TimestampedItem) Sources(com.hazelcast.jet.pipeline.Sources) IMap(com.hazelcast.core.IMap) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) TwoBags(com.hazelcast.jet.datamodel.TwoBags) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) WindowResult(com.hazelcast.jet.datamodel.WindowResult) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast-jet by hazelcast.

the class WindowGroupTransform_IntegrationTest method testSliding_windowFirst_aggregate2.

@Test
public void testSliding_windowFirst_aggregate2() {
    IMap<Long, String> map = instance.getMap("source");
    // key is timestamp
    map.put(0L, "foo");
    map.put(2L, "taz");
    map.put(10L, "flush-item");
    IMap<Long, String> map2 = instance.getMap("source1");
    // key is timestamp
    map2.put(0L, "faa");
    map2.put(2L, "tuu");
    map2.put(10L, "flush-item");
    Pipeline p = Pipeline.create();
    StreamStageWithGrouping<Entry<Long, String>, Character> stage1 = p.drawFrom(Sources.<Long, String>mapJournal("source1", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).groupingKey(entry -> entry.getValue().charAt(0));
    p.drawFrom(Sources.<Long, String>mapJournal("source", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).window(WindowDefinition.tumbling(2)).groupingKey(entry -> entry.getValue().charAt(0)).aggregate2(stage1, toTwoBags()).peek().drainTo(Sinks.list("sink"));
    instance.newJob(p);
    assertTrueEventually(() -> {
        assertEquals(listToString(asList(new TimestampedEntry<>(2, 'f', TwoBags.twoBags(asList(entry(0L, "foo")), asList(entry(0L, "faa")))), new TimestampedEntry<>(4, 't', TwoBags.twoBags(asList(entry(2L, "taz")), asList(entry(2L, "tuu")))))), listToString(instance.getHazelcastInstance().getList("sink")));
    }, 5);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) GroupProperty(com.hazelcast.spi.properties.GroupProperty) RunWith(org.junit.runner.RunWith) EventJournalConfig(com.hazelcast.config.EventJournalConfig) TestUtil.set(com.hazelcast.jet.core.TestUtil.set) HashSet(java.util.HashSet) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) SlidingWindowDef(com.hazelcast.jet.pipeline.SlidingWindowDef) Util.entry(com.hazelcast.jet.Util.entry) Arrays.asList(java.util.Arrays.asList) WindowGroupAggregateBuilder(com.hazelcast.jet.pipeline.WindowGroupAggregateBuilder) StageWithGroupingAndWindow(com.hazelcast.jet.pipeline.StageWithGroupingAndWindow) IList(com.hazelcast.core.IList) Before(org.junit.Before) AggregateOperations.toThreeBags(com.hazelcast.jet.aggregate.AggregateOperations.toThreeBags) JetConfig(com.hazelcast.jet.config.JetConfig) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) AggregateOperations.toTwoBags(com.hazelcast.jet.aggregate.AggregateOperations.toTwoBags) AggregateOperations.toSet(com.hazelcast.jet.aggregate.AggregateOperations.toSet) Tag(com.hazelcast.jet.datamodel.Tag) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) ParallelTest(com.hazelcast.test.annotation.ParallelTest) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) IMap(com.hazelcast.core.IMap) JournalInitialPosition(com.hazelcast.jet.pipeline.JournalInitialPosition) StreamStageWithGrouping(com.hazelcast.jet.pipeline.StreamStageWithGrouping) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) TwoBags(com.hazelcast.jet.datamodel.TwoBags) Assert.assertEquals(org.junit.Assert.assertEquals) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) WindowResult(com.hazelcast.jet.datamodel.WindowResult) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) Entry(java.util.Map.Entry) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)24 Sources (com.hazelcast.jet.pipeline.Sources)24 Sinks (com.hazelcast.jet.pipeline.Sinks)23 JetInstance (com.hazelcast.jet.JetInstance)18 Entry (java.util.Map.Entry)18 JetConfig (com.hazelcast.jet.config.JetConfig)15 Test (org.junit.Test)14 IList (com.hazelcast.core.IList)12 Arrays.asList (java.util.Arrays.asList)12 Assert.assertEquals (org.junit.Assert.assertEquals)12 AggregateOperation (com.hazelcast.jet.aggregate.AggregateOperation)11 Tag (com.hazelcast.jet.datamodel.Tag)11 Before (org.junit.Before)11 Category (org.junit.experimental.categories.Category)11 RunWith (org.junit.runner.RunWith)11 Util.entry (com.hazelcast.jet.Util.entry)10 JetTestSupport (com.hazelcast.jet.core.JetTestSupport)10 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)10 EventJournalConfig (com.hazelcast.config.EventJournalConfig)9 IMap (com.hazelcast.core.IMap)9