Search in sources :

Example 1 with IListJet

use of com.hazelcast.jet.IListJet in project hazelcast-jet by hazelcast.

the class ReadHdfsPTest method testJus.

@Test
public void testJus() {
    IListJet sink = DistributedStream.fromSource(instance, HdfsSources.hdfs(jobConf, mapperType.mapper), false).collect(DistributedCollectors.toIList("sink"));
    assertEquals(expectedSinkSize(), sink.size());
}
Also used : IListJet(com.hazelcast.jet.IListJet) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with IListJet

use of com.hazelcast.jet.IListJet in project hazelcast-jet by hazelcast.

the class SourcesTest method testFile.

@Test
public void testFile() throws IOException {
    File dir = createTempFile();
    IListJet<String> sink = DistributedStream.fromSource(getInstance(), Sources.files(dir.getAbsolutePath()), false).flatMap(line -> Arrays.stream(line.split(" "))).collect(DistributedCollectors.toIList(dir.getName()));
    assertEquals(10, sink.size());
    deleteTempFile(dir);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Processor(com.hazelcast.jet.core.Processor) Arrays.asList(java.util.Arrays.asList) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) PrintWriter(java.io.PrintWriter) BatchSource(com.hazelcast.jet.pipeline.BatchSource) Files(java.nio.file.Files) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Collection(java.util.Collection) FileOutputStream(java.io.FileOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) IListJet(com.hazelcast.jet.IListJet) AbstractStreamTest(com.hazelcast.jet.stream.AbstractStreamTest) Collectors(java.util.stream.Collectors) File(java.io.File) Sources(com.hazelcast.jet.pipeline.Sources) DistributedCollectors(com.hazelcast.jet.stream.DistributedCollectors) ListSource(com.hazelcast.jet.core.TestProcessors.ListSource) DistributedStream(com.hazelcast.jet.stream.DistributedStream) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) Assert.assertEquals(org.junit.Assert.assertEquals) File(java.io.File) Test(org.junit.Test) AbstractStreamTest(com.hazelcast.jet.stream.AbstractStreamTest)

Example 3 with IListJet

use of com.hazelcast.jet.IListJet in project hazelcast-jet by hazelcast.

the class AggregateTransform_IntegrationTest method test_aggregate3_with_aggBuilder.

@Test
public void test_aggregate3_with_aggBuilder() {
    // Given
    JetInstance instance = createJetMember();
    IListJet<Integer> list = instance.getList("list");
    list.add(1);
    list.add(2);
    list.add(3);
    IListJet<String> list1 = instance.getList("list1");
    list1.add("a");
    list1.add("b");
    list1.add("c");
    IListJet<Double> list2 = instance.getList("list2");
    list2.add(6.0d);
    list2.add(7.0d);
    list2.add(8.0d);
    // When
    Pipeline p = Pipeline.create();
    BatchStage<Integer> stage0 = p.drawFrom(Sources.list("list"));
    BatchStage<String> stage1 = p.drawFrom(Sources.list("list1"));
    BatchStage<Double> stage2 = p.drawFrom(Sources.list("list2"));
    AggregateBuilder<Integer> builder = stage0.aggregateBuilder();
    Tag<Integer> tag0 = builder.tag0();
    Tag<String> tag1 = builder.add(stage1);
    Tag<Double> tag2 = builder.add(stage2);
    BatchStage<ThreeBags> resultStage = builder.build(AggregateOperation.withCreate(ThreeBags::threeBags).andAccumulate(tag0, (acc, item0) -> acc.bag0().add(item0)).andAccumulate(tag1, (acc, item1) -> acc.bag1().add(item1)).andAccumulate(tag2, (acc, item2) -> acc.bag2().add(item2)).andCombine(ThreeBags::combineWith).andDeduct(ThreeBags::deduct).andFinish(ThreeBags::finish));
    resultStage.drainTo(Sinks.list("sink"));
    instance.newJob(p).join();
    // Then
    ThreeBags threeBags = (ThreeBags) instance.getHazelcastInstance().getList("sink").iterator().next();
    assertNotNull(threeBags);
    sort(threeBags);
    assertEquals(threeBags(list, list1, list2), threeBags);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) RunWith(org.junit.runner.RunWith) ThreeBags.threeBags(com.hazelcast.jet.datamodel.ThreeBags.threeBags) TestUtil.set(com.hazelcast.jet.core.TestUtil.set) Collections.singletonList(java.util.Collections.singletonList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) Util.entry(com.hazelcast.jet.Util.entry) AggregateOperations.toThreeBags(com.hazelcast.jet.aggregate.AggregateOperations.toThreeBags) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) AggregateOperations.toTwoBags(com.hazelcast.jet.aggregate.AggregateOperations.toTwoBags) Assert.assertNotNull(org.junit.Assert.assertNotNull) AggregateOperations.toSet(com.hazelcast.jet.aggregate.AggregateOperations.toSet) Tag(com.hazelcast.jet.datamodel.Tag) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) IListJet(com.hazelcast.jet.IListJet) AggregateBuilder(com.hazelcast.jet.pipeline.AggregateBuilder) ParallelTest(com.hazelcast.test.annotation.ParallelTest) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) List(java.util.List) IMap(com.hazelcast.core.IMap) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) TwoBags(com.hazelcast.jet.datamodel.TwoBags) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) JetInstance(com.hazelcast.jet.JetInstance) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) AggregateOperations.toThreeBags(com.hazelcast.jet.aggregate.AggregateOperations.toThreeBags) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with IListJet

use of com.hazelcast.jet.IListJet in project hazelcast-jet by hazelcast.

the class HazelcastConnectorTest method when_readMap_withPredicateAndDistributedFunction.

@Test
public void when_readMap_withPredicateAndDistributedFunction() {
    IMapJet<Integer, Integer> sourceMap = jetInstance.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));
    jetInstance.newJob(dag).join();
    IListJet<Object> list = jetInstance.getList(sinkName);
    assertEquals(ENTRY_COUNT - 1, list.size());
    assertFalse(list.contains(0));
    assertTrue(list.contains(1));
}
Also used : WatermarkPolicies.limitingLag(com.hazelcast.jet.core.WatermarkPolicies.limitingLag) IntStream.range(java.util.stream.IntStream.range) EventJournalConfig(com.hazelcast.config.EventJournalConfig) IMapJet(com.hazelcast.jet.IMapJet) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) SourceProcessors.readListP(com.hazelcast.jet.core.processor.SourceProcessors.readListP) SourceProcessors.streamCacheP(com.hazelcast.jet.core.processor.SourceProcessors.streamCacheP) ICacheJet(com.hazelcast.jet.ICacheJet) Map(java.util.Map) WatermarkEmissionPolicy.noThrottling(com.hazelcast.jet.core.WatermarkEmissionPolicy.noThrottling) SinkProcessors.writeCacheP(com.hazelcast.jet.core.processor.SinkProcessors.writeCacheP) DAG(com.hazelcast.jet.core.DAG) WatermarkGenerationParams.noWatermarks(com.hazelcast.jet.core.WatermarkGenerationParams.noWatermarks) Projections(com.hazelcast.projection.Projections) WatermarkGenerationParams.wmGenParams(com.hazelcast.jet.core.WatermarkGenerationParams.wmGenParams) SourceProcessors.readCacheP(com.hazelcast.jet.core.processor.SourceProcessors.readCacheP) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Collectors.joining(java.util.stream.Collectors.joining) PredicateTestUtils.entry(com.hazelcast.query.impl.predicates.PredicateTestUtils.entry) JetCacheManager(com.hazelcast.jet.JetCacheManager) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) SinkProcessors.writeMapP(com.hazelcast.jet.core.processor.SinkProcessors.writeMapP) IntStream(java.util.stream.IntStream) JetInstance(com.hazelcast.jet.JetInstance) SourceProcessors(com.hazelcast.jet.core.processor.SourceProcessors) RunWith(org.junit.runner.RunWith) Job(com.hazelcast.jet.Job) Before(org.junit.Before) EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) Config(com.hazelcast.config.Config) JetConfig(com.hazelcast.jet.config.JetConfig) SourceProcessors.streamMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamMapP) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IListJet(com.hazelcast.jet.IListJet) Vertex(com.hazelcast.jet.core.Vertex) TruePredicate(com.hazelcast.query.TruePredicate) Collectors.toList(java.util.stream.Collectors.toList) Predicates(com.hazelcast.query.Predicates) ICache(com.hazelcast.cache.ICache) Util.mapPutEvents(com.hazelcast.jet.Util.mapPutEvents) Assert.assertEquals(org.junit.Assert.assertEquals) 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) Test(org.junit.Test)

Aggregations

IListJet (com.hazelcast.jet.IListJet)4 Test (org.junit.Test)4 Assert.assertEquals (org.junit.Assert.assertEquals)3 JetInstance (com.hazelcast.jet.JetInstance)2 JetTestSupport (com.hazelcast.jet.core.JetTestSupport)2 Sources (com.hazelcast.jet.pipeline.Sources)2 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 IntStream (java.util.stream.IntStream)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 RunWith (org.junit.runner.RunWith)2 ICache (com.hazelcast.cache.ICache)1 EventJournalCacheEvent (com.hazelcast.cache.journal.EventJournalCacheEvent)1 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)1 Config (com.hazelcast.config.Config)1 EventJournalConfig (com.hazelcast.config.EventJournalConfig)1 IMap (com.hazelcast.core.IMap)1 ICacheJet (com.hazelcast.jet.ICacheJet)1 IMapJet (com.hazelcast.jet.IMapJet)1 JetCacheManager (com.hazelcast.jet.JetCacheManager)1