Search in sources :

Example 1 with Tuple2

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));
}
Also used : TimeWindowInformation(edu.snu.mist.common.windows.TimeWindowInformation) UDFTestUtils(edu.snu.mist.client.utils.UDFTestUtils) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) Tuple2(edu.snu.mist.common.types.Tuple2) ConfKeys(edu.snu.mist.common.configurations.ConfKeys) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test) IOException(java.io.IOException) MISTQuery(edu.snu.mist.client.MISTQuery) CountWindowInformation(edu.snu.mist.common.windows.CountWindowInformation) SerializeUtils(edu.snu.mist.common.SerializeUtils) DAG(edu.snu.mist.common.graph.DAG) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) After(org.junit.After) Map(java.util.Map) Direction(edu.snu.mist.formats.avro.Direction) TestParameters(edu.snu.mist.client.utils.TestParameters) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) edu.snu.mist.common.functions(edu.snu.mist.common.functions) SessionWindowInformation(edu.snu.mist.common.windows.SessionWindowInformation) Before(org.junit.Before) Tuple2(edu.snu.mist.common.types.Tuple2) MISTQuery(edu.snu.mist.client.MISTQuery) CountWindowInformation(edu.snu.mist.common.windows.CountWindowInformation) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 2 with Tuple2

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));
}
Also used : Tuple2(edu.snu.mist.common.types.Tuple2) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 3 with Tuple2

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));
}
Also used : Tuple2(edu.snu.mist.common.types.Tuple2) CountWindowInformation(edu.snu.mist.common.windows.CountWindowInformation) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 4 with Tuple2

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));
}
Also used : TimeWindowInformation(edu.snu.mist.common.windows.TimeWindowInformation) UDFTestUtils(edu.snu.mist.client.utils.UDFTestUtils) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) Tuple2(edu.snu.mist.common.types.Tuple2) ConfKeys(edu.snu.mist.common.configurations.ConfKeys) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test) IOException(java.io.IOException) MISTQuery(edu.snu.mist.client.MISTQuery) CountWindowInformation(edu.snu.mist.common.windows.CountWindowInformation) SerializeUtils(edu.snu.mist.common.SerializeUtils) DAG(edu.snu.mist.common.graph.DAG) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) After(org.junit.After) Map(java.util.Map) Direction(edu.snu.mist.formats.avro.Direction) TestParameters(edu.snu.mist.client.utils.TestParameters) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) edu.snu.mist.common.functions(edu.snu.mist.common.functions) SessionWindowInformation(edu.snu.mist.common.windows.SessionWindowInformation) Before(org.junit.Before) Tuple2(edu.snu.mist.common.types.Tuple2) MISTQuery(edu.snu.mist.client.MISTQuery) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 5 with Tuple2

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());
}
Also used : Tuple2(edu.snu.mist.common.types.Tuple2) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Aggregations

Tuple2 (edu.snu.mist.common.types.Tuple2)20 Test (org.junit.Test)16 MISTEdge (edu.snu.mist.common.graph.MISTEdge)9 IOException (java.io.IOException)9 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)8 InjectionException (org.apache.reef.tang.exceptions.InjectionException)8 Tang (org.apache.reef.tang.Tang)6 Assert (org.junit.Assert)6 TimeWindowInformation (edu.snu.mist.common.windows.TimeWindowInformation)5 URISyntaxException (java.net.URISyntaxException)5 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)5 APIQueryControlResult (edu.snu.mist.client.APIQueryControlResult)4 MISTQuery (edu.snu.mist.client.MISTQuery)4 SourceConfiguration (edu.snu.mist.client.datastreams.configurations.SourceConfiguration)4 MistDataEvent (edu.snu.mist.core.MistDataEvent)4 MistEvent (edu.snu.mist.core.MistEvent)4 OutputBufferEmitter (edu.snu.mist.core.utils.OutputBufferEmitter)4 LinkedList (java.util.LinkedList)4 Injector (org.apache.reef.tang.Injector)4 TestParameters (edu.snu.mist.client.utils.TestParameters)3