Search in sources :

Example 1 with SupplierStreamlet

use of org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet in project heron by twitter.

the class StreamletImplTest method testStreamletNameIfDuplicateNameIsSet.

@Test(expected = RuntimeException.class)
public void testStreamletNameIfDuplicateNameIsSet() {
    // create SupplierStreamlet
    Streamlet<String> baseStreamlet = builder.newSource(() -> "This is test content");
    SupplierStreamlet<String> supplierStreamlet = (SupplierStreamlet<String>) baseStreamlet;
    // set duplicate streamlet name and expect thrown exception
    supplierStreamlet.map((content) -> content.toUpperCase()).setName("MyMapStreamlet").map((content) -> content + "_test_suffix").setName("MyMapStreamlet");
    // build SupplierStreamlet
    assertFalse(supplierStreamlet.isBuilt());
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet.build(topologyBuilder, stageNames);
}
Also used : Arrays(java.util.Arrays) SpoutStreamlet(org.apache.heron.streamlet.impl.streamlets.SpoutStreamlet) WindowConfig(org.apache.heron.streamlet.WindowConfig) ShuffleStreamGrouping(org.apache.heron.api.grouping.ShuffleStreamGrouping) Builder(org.apache.heron.streamlet.Builder) CountByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.CountByKeyStreamlet) JoinStreamlet(org.apache.heron.streamlet.impl.streamlets.JoinStreamlet) Map(java.util.Map) Utils(org.apache.heron.api.utils.Utils) Assert.fail(org.junit.Assert.fail) StreamletReducers(org.apache.heron.streamlet.StreamletReducers) TestSpout(org.apache.heron.resource.TestSpout) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) TestBasicBolt(org.apache.heron.resource.TestBasicBolt) ReduceByKeyAndWindowStreamlet(org.apache.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) IStreamletWindowOperator(org.apache.heron.streamlet.IStreamletWindowOperator) KeyByStreamlet(org.apache.heron.streamlet.impl.streamlets.KeyByStreamlet) SourceStreamlet(org.apache.heron.streamlet.impl.streamlets.SourceStreamlet) KeyedWindow(org.apache.heron.streamlet.KeyedWindow) Collection(java.util.Collection) Set(java.util.Set) Context(org.apache.heron.streamlet.Context) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) SerializableTransformer(org.apache.heron.streamlet.SerializableTransformer) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) KVStreamlet(org.apache.heron.streamlet.KVStreamlet) SerializablePredicate(org.apache.heron.streamlet.SerializablePredicate) CountByKeyAndWindowStreamlet(org.apache.heron.streamlet.impl.streamlets.CountByKeyAndWindowStreamlet) HashMap(java.util.HashMap) Function(java.util.function.Function) ConsumerStreamlet(org.apache.heron.streamlet.impl.streamlets.ConsumerStreamlet) HashSet(java.util.HashSet) UnionStreamlet(org.apache.heron.streamlet.impl.streamlets.UnionStreamlet) KVStreamletShadow(org.apache.heron.streamlet.impl.streamlets.KVStreamletShadow) FlatMapStreamlet(org.apache.heron.streamlet.impl.streamlets.FlatMapStreamlet) ReduceByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.ReduceByKeyStreamlet) MapStreamlet(org.apache.heron.streamlet.impl.streamlets.MapStreamlet) ByteAmount(org.apache.heron.common.basics.ByteAmount) Source(org.apache.heron.streamlet.Source) TransformStreamlet(org.apache.heron.streamlet.impl.streamlets.TransformStreamlet) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestBolt(org.apache.heron.resource.TestBolt) Config(org.apache.heron.streamlet.Config) Streamlet(org.apache.heron.streamlet.Streamlet) Consumer(java.util.function.Consumer) IStreamletRichOperator(org.apache.heron.streamlet.IStreamletRichOperator) CustomStreamlet(org.apache.heron.streamlet.impl.streamlets.CustomStreamlet) IStreamletBasicOperator(org.apache.heron.streamlet.IStreamletBasicOperator) TestWindowBolt(org.apache.heron.resource.TestWindowBolt) SerializableConsumer(org.apache.heron.streamlet.SerializableConsumer) GeneralReduceByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.GeneralReduceByKeyStreamlet) FilterStreamlet(org.apache.heron.streamlet.impl.streamlets.FilterStreamlet) Assert.assertEquals(org.junit.Assert.assertEquals) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with SupplierStreamlet

use of org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet in project heron by twitter.

the class StreamletImplTest method testCustomStreamletWithGrouperFromBolt.

@Test
@SuppressWarnings("unchecked")
public void testCustomStreamletWithGrouperFromBolt() throws Exception {
    Streamlet<Double> baseStreamlet = builder.newSource(() -> Math.random());
    Streamlet<Double> streamlet = baseStreamlet.setNumPartitions(20).applyOperator(new MyBoltOperator(), new ShuffleStreamGrouping());
    assertTrue(streamlet instanceof CustomStreamlet);
    CustomStreamlet<Double, Double> mStreamlet = (CustomStreamlet<Double, Double>) streamlet;
    assertEquals(20, mStreamlet.getNumPartitions());
    SupplierStreamlet<Double> supplierStreamlet = (SupplierStreamlet<Double>) baseStreamlet;
    assertEquals(supplierStreamlet.getChildren().size(), 1);
    assertEquals(supplierStreamlet.getChildren().get(0), streamlet);
}
Also used : ShuffleStreamGrouping(org.apache.heron.api.grouping.ShuffleStreamGrouping) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) CustomStreamlet(org.apache.heron.streamlet.impl.streamlets.CustomStreamlet) Test(org.junit.Test)

Example 3 with SupplierStreamlet

use of org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet in project heron by twitter.

the class StreamletImplTest method testCalculatedDefaultStageNames.

@Test
@SuppressWarnings("unchecked")
public void testCalculatedDefaultStageNames() {
    // create SupplierStreamlet
    Streamlet<String> baseStreamlet = builder.newSource(() -> "This is test content");
    SupplierStreamlet<String> supplierStreamlet = (SupplierStreamlet<String>) baseStreamlet;
    assertEquals(supplierStreamlet.getChildren().size(), 0);
    // apply the consumer function
    baseStreamlet.consume((SerializableConsumer<String>) s -> {
    });
    // build SupplierStreamlet
    assertFalse(supplierStreamlet.isBuilt());
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet.build(topologyBuilder, stageNames);
    // verify SupplierStreamlet
    assertTrue(supplierStreamlet.isFullyBuilt());
    assertEquals(1, supplierStreamlet.getChildren().size());
    assertTrue(supplierStreamlet.getChildren().get(0) instanceof ConsumerStreamlet);
    assertEquals("consumer1", supplierStreamlet.getChildren().get(0).getName());
    // verify stageNames
    assertEquals(2, stageNames.size());
    List<String> expectedStageNames = Arrays.asList("consumer1", "supplier1");
    assertTrue(stageNames.containsAll(expectedStageNames));
    // verify ConsumerStreamlet
    ConsumerStreamlet<String> consumerStreamlet = (ConsumerStreamlet<String>) supplierStreamlet.getChildren().get(0);
    assertEquals(0, consumerStreamlet.getChildren().size());
}
Also used : Arrays(java.util.Arrays) SpoutStreamlet(org.apache.heron.streamlet.impl.streamlets.SpoutStreamlet) WindowConfig(org.apache.heron.streamlet.WindowConfig) ShuffleStreamGrouping(org.apache.heron.api.grouping.ShuffleStreamGrouping) Builder(org.apache.heron.streamlet.Builder) CountByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.CountByKeyStreamlet) JoinStreamlet(org.apache.heron.streamlet.impl.streamlets.JoinStreamlet) Map(java.util.Map) Utils(org.apache.heron.api.utils.Utils) Assert.fail(org.junit.Assert.fail) StreamletReducers(org.apache.heron.streamlet.StreamletReducers) TestSpout(org.apache.heron.resource.TestSpout) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) TestBasicBolt(org.apache.heron.resource.TestBasicBolt) ReduceByKeyAndWindowStreamlet(org.apache.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) IStreamletWindowOperator(org.apache.heron.streamlet.IStreamletWindowOperator) KeyByStreamlet(org.apache.heron.streamlet.impl.streamlets.KeyByStreamlet) SourceStreamlet(org.apache.heron.streamlet.impl.streamlets.SourceStreamlet) KeyedWindow(org.apache.heron.streamlet.KeyedWindow) Collection(java.util.Collection) Set(java.util.Set) Context(org.apache.heron.streamlet.Context) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) SerializableTransformer(org.apache.heron.streamlet.SerializableTransformer) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) KVStreamlet(org.apache.heron.streamlet.KVStreamlet) SerializablePredicate(org.apache.heron.streamlet.SerializablePredicate) CountByKeyAndWindowStreamlet(org.apache.heron.streamlet.impl.streamlets.CountByKeyAndWindowStreamlet) HashMap(java.util.HashMap) Function(java.util.function.Function) ConsumerStreamlet(org.apache.heron.streamlet.impl.streamlets.ConsumerStreamlet) HashSet(java.util.HashSet) UnionStreamlet(org.apache.heron.streamlet.impl.streamlets.UnionStreamlet) KVStreamletShadow(org.apache.heron.streamlet.impl.streamlets.KVStreamletShadow) FlatMapStreamlet(org.apache.heron.streamlet.impl.streamlets.FlatMapStreamlet) ReduceByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.ReduceByKeyStreamlet) MapStreamlet(org.apache.heron.streamlet.impl.streamlets.MapStreamlet) ByteAmount(org.apache.heron.common.basics.ByteAmount) Source(org.apache.heron.streamlet.Source) TransformStreamlet(org.apache.heron.streamlet.impl.streamlets.TransformStreamlet) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestBolt(org.apache.heron.resource.TestBolt) Config(org.apache.heron.streamlet.Config) Streamlet(org.apache.heron.streamlet.Streamlet) Consumer(java.util.function.Consumer) IStreamletRichOperator(org.apache.heron.streamlet.IStreamletRichOperator) CustomStreamlet(org.apache.heron.streamlet.impl.streamlets.CustomStreamlet) IStreamletBasicOperator(org.apache.heron.streamlet.IStreamletBasicOperator) TestWindowBolt(org.apache.heron.resource.TestWindowBolt) SerializableConsumer(org.apache.heron.streamlet.SerializableConsumer) GeneralReduceByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.GeneralReduceByKeyStreamlet) FilterStreamlet(org.apache.heron.streamlet.impl.streamlets.FilterStreamlet) Assert.assertEquals(org.junit.Assert.assertEquals) ConsumerStreamlet(org.apache.heron.streamlet.impl.streamlets.ConsumerStreamlet) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SupplierStreamlet

use of org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet in project heron by twitter.

the class StreamletImplTest method testComplexBuild.

@Test
@SuppressWarnings("unchecked")
public void testComplexBuild() {
    // First source
    Streamlet<String> baseStreamlet1 = builder.newSource(() -> "sa re ga ma");
    Streamlet<String> leftStream = baseStreamlet1.flatMap(x -> Arrays.asList(x.split(" ")));
    // Second source
    Streamlet<String> baseStreamlet2 = builder.newSource(() -> "I Love You");
    Streamlet<String> rightStream = baseStreamlet2.flatMap(x -> Arrays.asList(x.split(" ")));
    // join
    leftStream.join(rightStream, x -> x, x -> x, WindowConfig.TumblingCountWindow(10), (x, y) -> x + y);
    SupplierStreamlet<String> supplierStreamlet1 = (SupplierStreamlet<String>) baseStreamlet1;
    SupplierStreamlet<String> supplierStreamlet2 = (SupplierStreamlet<String>) baseStreamlet2;
    assertFalse(supplierStreamlet1.isBuilt());
    assertFalse(supplierStreamlet2.isBuilt());
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet1.build(topologyBuilder, stageNames);
    assertTrue(supplierStreamlet1.isBuilt());
    assertFalse(supplierStreamlet1.isFullyBuilt());
    supplierStreamlet2.build(topologyBuilder, stageNames);
    assertTrue(supplierStreamlet1.isFullyBuilt());
    assertTrue(supplierStreamlet2.isFullyBuilt());
    // go over all stuff
    assertEquals(supplierStreamlet1.getChildren().size(), 1);
    assertTrue(supplierStreamlet1.getChildren().get(0) instanceof FlatMapStreamlet);
    FlatMapStreamlet<String, String> fStreamlet = (FlatMapStreamlet<String, String>) supplierStreamlet1.getChildren().get(0);
    assertEquals(fStreamlet.getChildren().size(), 1);
    assertTrue(fStreamlet.getChildren().get(0) instanceof JoinStreamlet);
    JoinStreamlet<String, String, String, String> jStreamlet = (JoinStreamlet<String, String, String, String>) fStreamlet.getChildren().get(0);
    assertEquals(jStreamlet.getChildren().size(), 0);
    assertEquals(supplierStreamlet2.getChildren().size(), 1);
    assertTrue(supplierStreamlet2.getChildren().get(0) instanceof FlatMapStreamlet);
    fStreamlet = (FlatMapStreamlet<String, String>) supplierStreamlet2.getChildren().get(0);
    assertEquals(fStreamlet.getChildren().size(), 1);
    assertTrue(fStreamlet.getChildren().get(0) instanceof JoinStreamlet);
    jStreamlet = (JoinStreamlet<String, String, String, String>) fStreamlet.getChildren().get(0);
    assertEquals(jStreamlet.getChildren().size(), 0);
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) JoinStreamlet(org.apache.heron.streamlet.impl.streamlets.JoinStreamlet) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) FlatMapStreamlet(org.apache.heron.streamlet.impl.streamlets.FlatMapStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with SupplierStreamlet

use of org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet in project heron by twitter.

the class StreamletImplTest method testSimpleBuild.

@Test
@SuppressWarnings("unchecked")
public void testSimpleBuild() throws Exception {
    Streamlet<String> baseStreamlet = builder.newSource(() -> "sa re ga ma");
    baseStreamlet.flatMap(x -> Arrays.asList(x.split(" "))).reduceByKeyAndWindow(x -> x, x -> 1, WindowConfig.TumblingCountWindow(10), (x, y) -> x + y);
    SupplierStreamlet<String> supplierStreamlet = (SupplierStreamlet<String>) baseStreamlet;
    assertFalse(supplierStreamlet.isBuilt());
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet.build(topologyBuilder, stageNames);
    assertTrue(supplierStreamlet.isFullyBuilt());
    assertEquals(supplierStreamlet.getChildren().size(), 1);
    assertTrue(supplierStreamlet.getChildren().get(0) instanceof FlatMapStreamlet);
    FlatMapStreamlet<String, String> fStreamlet = (FlatMapStreamlet<String, String>) supplierStreamlet.getChildren().get(0);
    assertEquals(fStreamlet.getChildren().size(), 1);
    assertTrue(fStreamlet.getChildren().get(0) instanceof ReduceByKeyAndWindowStreamlet);
    ReduceByKeyAndWindowStreamlet<String, Integer, Integer> rStreamlet = (ReduceByKeyAndWindowStreamlet<String, Integer, Integer>) fStreamlet.getChildren().get(0);
    assertEquals(rStreamlet.getChildren().size(), 0);
}
Also used : Arrays(java.util.Arrays) SpoutStreamlet(org.apache.heron.streamlet.impl.streamlets.SpoutStreamlet) WindowConfig(org.apache.heron.streamlet.WindowConfig) ShuffleStreamGrouping(org.apache.heron.api.grouping.ShuffleStreamGrouping) Builder(org.apache.heron.streamlet.Builder) CountByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.CountByKeyStreamlet) JoinStreamlet(org.apache.heron.streamlet.impl.streamlets.JoinStreamlet) Map(java.util.Map) Utils(org.apache.heron.api.utils.Utils) Assert.fail(org.junit.Assert.fail) StreamletReducers(org.apache.heron.streamlet.StreamletReducers) TestSpout(org.apache.heron.resource.TestSpout) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) TestBasicBolt(org.apache.heron.resource.TestBasicBolt) ReduceByKeyAndWindowStreamlet(org.apache.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) IStreamletWindowOperator(org.apache.heron.streamlet.IStreamletWindowOperator) KeyByStreamlet(org.apache.heron.streamlet.impl.streamlets.KeyByStreamlet) SourceStreamlet(org.apache.heron.streamlet.impl.streamlets.SourceStreamlet) KeyedWindow(org.apache.heron.streamlet.KeyedWindow) Collection(java.util.Collection) Set(java.util.Set) Context(org.apache.heron.streamlet.Context) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) SerializableTransformer(org.apache.heron.streamlet.SerializableTransformer) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) KVStreamlet(org.apache.heron.streamlet.KVStreamlet) SerializablePredicate(org.apache.heron.streamlet.SerializablePredicate) CountByKeyAndWindowStreamlet(org.apache.heron.streamlet.impl.streamlets.CountByKeyAndWindowStreamlet) HashMap(java.util.HashMap) Function(java.util.function.Function) ConsumerStreamlet(org.apache.heron.streamlet.impl.streamlets.ConsumerStreamlet) HashSet(java.util.HashSet) UnionStreamlet(org.apache.heron.streamlet.impl.streamlets.UnionStreamlet) KVStreamletShadow(org.apache.heron.streamlet.impl.streamlets.KVStreamletShadow) FlatMapStreamlet(org.apache.heron.streamlet.impl.streamlets.FlatMapStreamlet) ReduceByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.ReduceByKeyStreamlet) MapStreamlet(org.apache.heron.streamlet.impl.streamlets.MapStreamlet) ByteAmount(org.apache.heron.common.basics.ByteAmount) Source(org.apache.heron.streamlet.Source) TransformStreamlet(org.apache.heron.streamlet.impl.streamlets.TransformStreamlet) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestBolt(org.apache.heron.resource.TestBolt) Config(org.apache.heron.streamlet.Config) Streamlet(org.apache.heron.streamlet.Streamlet) Consumer(java.util.function.Consumer) IStreamletRichOperator(org.apache.heron.streamlet.IStreamletRichOperator) CustomStreamlet(org.apache.heron.streamlet.impl.streamlets.CustomStreamlet) IStreamletBasicOperator(org.apache.heron.streamlet.IStreamletBasicOperator) TestWindowBolt(org.apache.heron.resource.TestWindowBolt) SerializableConsumer(org.apache.heron.streamlet.SerializableConsumer) GeneralReduceByKeyStreamlet(org.apache.heron.streamlet.impl.streamlets.GeneralReduceByKeyStreamlet) FilterStreamlet(org.apache.heron.streamlet.impl.streamlets.FilterStreamlet) Assert.assertEquals(org.junit.Assert.assertEquals) ReduceByKeyAndWindowStreamlet(org.apache.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) FlatMapStreamlet(org.apache.heron.streamlet.impl.streamlets.FlatMapStreamlet) SupplierStreamlet(org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SupplierStreamlet (org.apache.heron.streamlet.impl.streamlets.SupplierStreamlet)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 ShuffleStreamGrouping (org.apache.heron.api.grouping.ShuffleStreamGrouping)4 TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)4 CustomStreamlet (org.apache.heron.streamlet.impl.streamlets.CustomStreamlet)4 FlatMapStreamlet (org.apache.heron.streamlet.impl.streamlets.FlatMapStreamlet)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Consumer (java.util.function.Consumer)3 Function (java.util.function.Function)3 Utils (org.apache.heron.api.utils.Utils)3 ByteAmount (org.apache.heron.common.basics.ByteAmount)3 TestBasicBolt (org.apache.heron.resource.TestBasicBolt)3 TestBolt (org.apache.heron.resource.TestBolt)3 TestSpout (org.apache.heron.resource.TestSpout)3