use of edu.snu.mist.common.types.Tuple2 in project mist by snuspl.
the class ContinuousStreamTest method testJoinOperatorStream.
/**
* Test for join operation.
*/
@Test
public void testJoinOperatorStream() throws InjectionException, IOException, ClassNotFoundException {
final ContinuousStream<String> firstInputStream = queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF);
final ContinuousStream<String> secondInputStream = queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF);
final MISTBiPredicate<String, String> joinBiPred = (string1, string2) -> string1.equals(string2);
final WindowedStream<Tuple2<String, String>> joinedStream = firstInputStream.join(secondInputStream, joinBiPred, new CountWindowInformation(5, 3));
final Map<String, String> conf = joinedStream.getConfiguration();
Assert.assertEquals(SerializeUtils.serializeToString(joinBiPred), conf.get(ConfKeys.OperatorConf.UDF_STRING.name()));
// Check first input -> mapped
final MISTQuery query = queryBuilder.build();
final DAG<MISTStream, MISTEdge> dag = query.getDAG();
final MISTStream firstMappedInputStream = getNextOperatorStream(dag, 1, firstInputStream, new MISTEdge(Direction.LEFT));
// Check second input -> mapped
final MISTStream secondMappedInputStream = getNextOperatorStream(dag, 1, secondInputStream, new MISTEdge(Direction.LEFT));
// Check two mapped input -> unified
final MISTStream firstUnifiedStream = getNextOperatorStream(dag, 1, firstMappedInputStream, new MISTEdge(Direction.LEFT));
final MISTStream secondUnifiedStream = getNextOperatorStream(dag, 1, secondMappedInputStream, new MISTEdge(Direction.RIGHT));
Assert.assertEquals(firstUnifiedStream, secondUnifiedStream);
// Check unified stream -> windowed
final MISTStream windowedStream = getNextOperatorStream(dag, 1, firstUnifiedStream, new MISTEdge(Direction.LEFT));
// Check windowed stream -> joined
checkEdges(dag, 1, windowedStream, joinedStream, new MISTEdge(Direction.LEFT));
}
use of edu.snu.mist.common.types.Tuple2 in project mist by snuspl.
the class ContinuousStreamTest method testApplyStatefulOperatorStream.
/**
* Test for stateful UDF operator.
*/
@Test
public void testApplyStatefulOperatorStream() throws InjectionException, IOException, ClassNotFoundException {
final ApplyStatefulFunction<Tuple2<String, Integer>, Integer> applyStatefulFunction = new UDFTestUtils.TestApplyStatefulFunction();
final ContinuousStream<Integer> statefulOperatorStream = filteredMappedStream.applyStateful(applyStatefulFunction);
/* Simulate two data inputs on UDF stream */
final Map<String, String> conf = statefulOperatorStream.getConfiguration();
Assert.assertEquals(SerializeUtils.serializeToString(applyStatefulFunction), conf.get(ConfKeys.OperatorConf.UDF_STRING.name()));
// Check filter -> map -> applyStateful
checkEdges(queryBuilder.build().getDAG(), 1, filteredMappedStream, statefulOperatorStream, new MISTEdge(Direction.LEFT));
}
use of edu.snu.mist.common.types.Tuple2 in project mist by snuspl.
the class ContinuousStreamTest method testCountWindowedStream.
/**
* Test for creating count-based WindowedStream from ContinuousStream.
*/
@Test
public void testCountWindowedStream() throws InjectionException {
/* Creates a test windowed stream containing 5000 inputs and emits windowed stream every 1000 inputs */
final WindowedStream<Tuple2<String, Integer>> countWindowedStream = filteredMappedStream.window(new CountWindowInformation(windowSize, windowEmissionInterval));
checkSizeBasedWindowInfo(windowSize, windowEmissionInterval, countWindowedStream.getConfiguration());
// Check map -> countWindow
checkEdges(queryBuilder.build().getDAG(), 1, filteredMappedStream, countWindowedStream, new MISTEdge(Direction.LEFT));
}
use of edu.snu.mist.common.types.Tuple2 in project mist by snuspl.
the class ContinuousStreamTest method testUnionOperatorStream.
/**
* Test for union operator.
*/
@Test
public void testUnionOperatorStream() {
final ContinuousStream<Tuple2<String, Integer>> filteredMappedStream2 = queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF).filter(s -> s.contains("A")).map(s -> new Tuple2<>(s, 1));
final ContinuousStream<Tuple2<String, Integer>> unifiedStream = filteredMappedStream.union(filteredMappedStream2);
// Check filteredMappedStream (LEFT) ---> union
// filteredMappedStream2 (RIGHT) --/
final MISTQuery query = queryBuilder.build();
final DAG<MISTStream, MISTEdge> dag = query.getDAG();
final Map<MISTStream, MISTEdge> n1 = dag.getEdges(filteredMappedStream);
final Map<MISTStream, MISTEdge> n2 = dag.getEdges(filteredMappedStream2);
Assert.assertEquals(1, n1.size());
Assert.assertEquals(1, n2.size());
Assert.assertEquals(new MISTEdge(Direction.LEFT), n1.get(unifiedStream));
Assert.assertEquals(new MISTEdge(Direction.RIGHT), n2.get(unifiedStream));
}
use of edu.snu.mist.common.types.Tuple2 in project mist by snuspl.
the class ContinuousStreamTest method testConditionalBranchOperatorStream.
/**
* Test for creating conditional branch operator.
*/
@Test
public void testConditionalBranchOperatorStream() {
final ContinuousStream<Tuple2<String, Integer>> branch1 = filteredMappedStream.routeIf((t) -> t.get(1).equals(1));
final ContinuousStream<Tuple2<String, Integer>> branch2 = filteredMappedStream.routeIf((t) -> t.get(1).equals(2));
final ContinuousStream<Tuple2<String, Integer>> branch3 = filteredMappedStream.routeIf((t) -> t.get(1).equals(3));
final ContinuousStream<String> mapStream = filteredMappedStream.map((t) -> (String) t.get(0));
// --> branch 1
// filteredMappedStream --> branch 2
// --> branch 3
// --> mapStream
final DAG<MISTStream, MISTEdge> dag = queryBuilder.build().getDAG();
final Map<MISTStream, MISTEdge> edges = dag.getEdges(filteredMappedStream);
Assert.assertEquals(3, filteredMappedStream.getCondBranchCount());
Assert.assertEquals(4, edges.size());
Assert.assertEquals(new MISTEdge(Direction.LEFT), edges.get(branch1));
Assert.assertEquals(new MISTEdge(Direction.LEFT), edges.get(branch2));
Assert.assertEquals(new MISTEdge(Direction.LEFT), edges.get(branch3));
Assert.assertEquals(new MISTEdge(Direction.LEFT), edges.get(mapStream));
Assert.assertEquals(1, branch1.getBranchIndex());
Assert.assertEquals(2, branch2.getBranchIndex());
Assert.assertEquals(3, branch3.getBranchIndex());
Assert.assertEquals(0, mapStream.getBranchIndex());
}
Aggregations