use of org.apache.heron.streamlet.impl.streamlets.JoinStreamlet 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);
}
Aggregations