Search in sources :

Example 1 with SupplierStreamlet

use of com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet in project incubator-heron by apache.

the class StreamletImplTest method testCalculatedDefaultStageNames.

@Test
@SuppressWarnings("unchecked")
public void testCalculatedDefaultStageNames() {
    // create SupplierStreamlet
    Streamlet<String> baseStreamlet = StreamletImpl.createSupplierStreamlet(() -> "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 builder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet.build(builder, stageNames);
    // verify SupplierStreamlet
    assertTrue(supplierStreamlet.allBuilt());
    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 : ConsumerStreamlet(com.twitter.heron.streamlet.impl.streamlets.ConsumerStreamlet) Arrays(java.util.Arrays) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) SerializableConsumer(com.twitter.heron.streamlet.SerializableConsumer) Function(java.util.function.Function) JoinStreamlet(com.twitter.heron.streamlet.impl.streamlets.JoinStreamlet) SerializableTransformer(com.twitter.heron.streamlet.SerializableTransformer) HashSet(java.util.HashSet) Config(com.twitter.heron.streamlet.Config) FlatMapStreamlet(com.twitter.heron.streamlet.impl.streamlets.FlatMapStreamlet) ByteAmount(com.twitter.heron.common.basics.ByteAmount) Streamlet(com.twitter.heron.streamlet.Streamlet) WindowConfig(com.twitter.heron.streamlet.WindowConfig) FilterStreamlet(com.twitter.heron.streamlet.impl.streamlets.FilterStreamlet) UnionStreamlet(com.twitter.heron.streamlet.impl.streamlets.UnionStreamlet) Context(com.twitter.heron.streamlet.Context) TransformStreamlet(com.twitter.heron.streamlet.impl.streamlets.TransformStreamlet) ReduceByKeyAndWindowStreamlet(com.twitter.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) Set(java.util.Set) Test(org.junit.Test) Consumer(java.util.function.Consumer) List(java.util.List) MapStreamlet(com.twitter.heron.streamlet.impl.streamlets.MapStreamlet) SupplierStreamlet(com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet) Assert(org.junit.Assert) ConsumerStreamlet(com.twitter.heron.streamlet.impl.streamlets.ConsumerStreamlet) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) SupplierStreamlet(com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with SupplierStreamlet

use of com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet in project incubator-heron by apache.

the class StreamletImplTest method testSimpleBuild.

@Test
@SuppressWarnings("unchecked")
public void testSimpleBuild() throws Exception {
    Streamlet<String> baseStreamlet = StreamletImpl.createSupplierStreamlet(() -> "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 builder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet.build(builder, stageNames);
    assertTrue(supplierStreamlet.allBuilt());
    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 : ConsumerStreamlet(com.twitter.heron.streamlet.impl.streamlets.ConsumerStreamlet) Arrays(java.util.Arrays) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) SerializableConsumer(com.twitter.heron.streamlet.SerializableConsumer) Function(java.util.function.Function) JoinStreamlet(com.twitter.heron.streamlet.impl.streamlets.JoinStreamlet) SerializableTransformer(com.twitter.heron.streamlet.SerializableTransformer) HashSet(java.util.HashSet) Config(com.twitter.heron.streamlet.Config) FlatMapStreamlet(com.twitter.heron.streamlet.impl.streamlets.FlatMapStreamlet) ByteAmount(com.twitter.heron.common.basics.ByteAmount) Streamlet(com.twitter.heron.streamlet.Streamlet) WindowConfig(com.twitter.heron.streamlet.WindowConfig) FilterStreamlet(com.twitter.heron.streamlet.impl.streamlets.FilterStreamlet) UnionStreamlet(com.twitter.heron.streamlet.impl.streamlets.UnionStreamlet) Context(com.twitter.heron.streamlet.Context) TransformStreamlet(com.twitter.heron.streamlet.impl.streamlets.TransformStreamlet) ReduceByKeyAndWindowStreamlet(com.twitter.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) Set(java.util.Set) Test(org.junit.Test) Consumer(java.util.function.Consumer) List(java.util.List) MapStreamlet(com.twitter.heron.streamlet.impl.streamlets.MapStreamlet) SupplierStreamlet(com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet) Assert(org.junit.Assert) ReduceByKeyAndWindowStreamlet(com.twitter.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) FlatMapStreamlet(com.twitter.heron.streamlet.impl.streamlets.FlatMapStreamlet) SupplierStreamlet(com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with SupplierStreamlet

use of com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet in project incubator-heron by apache.

the class StreamletImplTest method testStreamletNameIfDuplicateNameIsSet.

@Test(expected = RuntimeException.class)
public void testStreamletNameIfDuplicateNameIsSet() {
    // create SupplierStreamlet
    Streamlet<String> baseStreamlet = StreamletImpl.createSupplierStreamlet(() -> "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 builder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet.build(builder, stageNames);
}
Also used : ConsumerStreamlet(com.twitter.heron.streamlet.impl.streamlets.ConsumerStreamlet) Arrays(java.util.Arrays) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) SerializableConsumer(com.twitter.heron.streamlet.SerializableConsumer) Function(java.util.function.Function) JoinStreamlet(com.twitter.heron.streamlet.impl.streamlets.JoinStreamlet) SerializableTransformer(com.twitter.heron.streamlet.SerializableTransformer) HashSet(java.util.HashSet) Config(com.twitter.heron.streamlet.Config) FlatMapStreamlet(com.twitter.heron.streamlet.impl.streamlets.FlatMapStreamlet) ByteAmount(com.twitter.heron.common.basics.ByteAmount) Streamlet(com.twitter.heron.streamlet.Streamlet) WindowConfig(com.twitter.heron.streamlet.WindowConfig) FilterStreamlet(com.twitter.heron.streamlet.impl.streamlets.FilterStreamlet) UnionStreamlet(com.twitter.heron.streamlet.impl.streamlets.UnionStreamlet) Context(com.twitter.heron.streamlet.Context) TransformStreamlet(com.twitter.heron.streamlet.impl.streamlets.TransformStreamlet) ReduceByKeyAndWindowStreamlet(com.twitter.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet) Set(java.util.Set) Test(org.junit.Test) Consumer(java.util.function.Consumer) List(java.util.List) MapStreamlet(com.twitter.heron.streamlet.impl.streamlets.MapStreamlet) SupplierStreamlet(com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet) Assert(org.junit.Assert) TopologyBuilder(com.twitter.heron.api.topology.TopologyBuilder) SupplierStreamlet(com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SupplierStreamlet

use of com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet in project incubator-heron by apache.

the class StreamletImplTest method testComplexBuild.

@Test
@SuppressWarnings("unchecked")
public void testComplexBuild() throws Exception {
    // First source
    Streamlet<String> baseStreamlet1 = StreamletImpl.createSupplierStreamlet(() -> "sa re ga ma");
    Streamlet<String> leftStream = baseStreamlet1.flatMap(x -> Arrays.asList(x.split(" ")));
    // Second source
    Streamlet<String> baseStreamlet2 = StreamletImpl.createSupplierStreamlet(() -> "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 builder = new TopologyBuilder();
    Set<String> stageNames = new HashSet<>();
    supplierStreamlet1.build(builder, stageNames);
    assertTrue(supplierStreamlet1.isBuilt());
    assertFalse(supplierStreamlet1.allBuilt());
    supplierStreamlet2.build(builder, stageNames);
    assertTrue(supplierStreamlet1.allBuilt());
    assertTrue(supplierStreamlet2.allBuilt());
    // 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(com.twitter.heron.api.topology.TopologyBuilder) JoinStreamlet(com.twitter.heron.streamlet.impl.streamlets.JoinStreamlet) SupplierStreamlet(com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet) FlatMapStreamlet(com.twitter.heron.streamlet.impl.streamlets.FlatMapStreamlet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

TopologyBuilder (com.twitter.heron.api.topology.TopologyBuilder)4 FlatMapStreamlet (com.twitter.heron.streamlet.impl.streamlets.FlatMapStreamlet)4 JoinStreamlet (com.twitter.heron.streamlet.impl.streamlets.JoinStreamlet)4 SupplierStreamlet (com.twitter.heron.streamlet.impl.streamlets.SupplierStreamlet)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 ByteAmount (com.twitter.heron.common.basics.ByteAmount)3 Config (com.twitter.heron.streamlet.Config)3 Context (com.twitter.heron.streamlet.Context)3 SerializableConsumer (com.twitter.heron.streamlet.SerializableConsumer)3 SerializableTransformer (com.twitter.heron.streamlet.SerializableTransformer)3 Streamlet (com.twitter.heron.streamlet.Streamlet)3 WindowConfig (com.twitter.heron.streamlet.WindowConfig)3 ConsumerStreamlet (com.twitter.heron.streamlet.impl.streamlets.ConsumerStreamlet)3 FilterStreamlet (com.twitter.heron.streamlet.impl.streamlets.FilterStreamlet)3 MapStreamlet (com.twitter.heron.streamlet.impl.streamlets.MapStreamlet)3 ReduceByKeyAndWindowStreamlet (com.twitter.heron.streamlet.impl.streamlets.ReduceByKeyAndWindowStreamlet)3 TransformStreamlet (com.twitter.heron.streamlet.impl.streamlets.TransformStreamlet)3 UnionStreamlet (com.twitter.heron.streamlet.impl.streamlets.UnionStreamlet)3 Arrays (java.util.Arrays)3