Search in sources :

Example 1 with MISTQuery

use of edu.snu.mist.client.MISTQuery in project mist by snuspl.

the class ContinuousStreamTest method testBasicOperatorStream.

/**
 * Test for basic stateless OperatorStreams.
 */
@Test
public void testBasicOperatorStream() throws IOException {
    final Map<String, String> filteredConf = filteredMappedStream.getConfiguration();
    Assert.assertEquals(SerializeUtils.serializeToString(defaultMap), filteredConf.get(ConfKeys.OperatorConf.UDF_STRING.name()));
    final MISTQuery query = queryBuilder.build();
    final DAG<MISTStream, MISTEdge> dag = query.getDAG();
    // Check src -> filiter
    final Map<MISTStream, MISTEdge> neighbors = dag.getEdges(sourceStream);
    Assert.assertEquals(1, neighbors.size());
    final MISTEdge edgeInfo = neighbors.get(filteredStream);
    Assert.assertEquals(Direction.LEFT, edgeInfo.getDirection());
    Assert.assertEquals(0, edgeInfo.getIndex());
    // Check filter -> map
    final Map<MISTStream, MISTEdge> neighbors2 = dag.getEdges(filteredStream);
    Assert.assertEquals(1, neighbors2.size());
    final MISTEdge edgeInfo2 = neighbors2.get(filteredMappedStream);
    Assert.assertEquals(Direction.LEFT, edgeInfo2.getDirection());
    Assert.assertEquals(0, edgeInfo2.getIndex());
}
Also used : MISTQuery(edu.snu.mist.client.MISTQuery) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 2 with MISTQuery

use of edu.snu.mist.client.MISTQuery 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 3 with MISTQuery

use of edu.snu.mist.client.MISTQuery 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 4 with MISTQuery

use of edu.snu.mist.client.MISTQuery in project mist by snuspl.

the class DefaultDagGeneratorImplTest method testPlanGenerator.

/**
 * Round-trip test of de-serializing AvroOperatorChainDag.
 * @throws org.apache.reef.tang.exceptions.InjectionException
 */
@Test
public void testPlanGenerator() throws InjectionException, IOException, URISyntaxException, ClassNotFoundException {
    // Generate a query
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.setApplicationId(TestParameters.SUPER_GROUP_ID);
    queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF).flatMap(s -> Arrays.asList(s.split(" "))).filter(s -> s.startsWith("A")).map(s -> new Tuple2<>(s, 1)).reduceByKey(0, String.class, (Integer x, Integer y) -> x + y).textSocketOutput(TestParameters.HOST, TestParameters.SINK_PORT);
    final MISTQuery query = queryBuilder.build();
    // Generate avro operator chain dag
    final Tuple<List<AvroVertex>, List<Edge>> serializedDag = query.getAvroOperatorDag();
    final AvroDag.Builder avroDagBuilder = AvroDag.newBuilder();
    final AvroDag avroChainedDag = avroDagBuilder.setAppId(TestParameters.SUPER_GROUP_ID).setQueryId(TestParameters.QUERY_ID).setJarPaths(new ArrayList<>()).setAvroVertices(serializedDag.getKey()).setEdges(serializedDag.getValue()).build();
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    jcb.bindNamedParameter(TaskHostname.class, "127.0.0.1");
    final Injector injector = Tang.Factory.getTang().newInjector(jcb.build());
    final ConfigDagGenerator configDagGenerator = injector.getInstance(ConfigDagGenerator.class);
    final DagGenerator dagGenerator = injector.getInstance(DagGenerator.class);
    final Tuple<String, AvroDag> tuple = new Tuple<>("query-test", avroChainedDag);
    final DAG<ConfigVertex, MISTEdge> configDag = configDagGenerator.generate(tuple.getValue());
    final ExecutionDag executionDag = dagGenerator.generate(configDag, new LinkedList<>());
    // Test execution dag
    final DAG<ExecutionVertex, MISTEdge> dag = executionDag.getDag();
    final Set<ExecutionVertex> sources = dag.getRootVertices();
    Assert.assertEquals(1, sources.size());
    Assert.assertTrue(sources.iterator().next() instanceof PhysicalSource);
    final PhysicalSource source = (PhysicalSource) sources.iterator().next();
    final Map<ExecutionVertex, MISTEdge> nextOps = dag.getEdges(source);
    Assert.assertEquals(1, nextOps.size());
    final PhysicalOperator flatMapOp = (PhysicalOperator) nextOps.entrySet().iterator().next().getKey();
    final PhysicalOperator filterOp = (PhysicalOperator) dag.getEdges(flatMapOp).entrySet().iterator().next().getKey();
    final PhysicalOperator mapOp = (PhysicalOperator) dag.getEdges(filterOp).entrySet().iterator().next().getKey();
    final PhysicalOperator reduceByKeyOp = (PhysicalOperator) dag.getEdges(mapOp).entrySet().iterator().next().getKey();
    final PhysicalSink sink = (PhysicalSink) dag.getEdges(reduceByKeyOp).entrySet().iterator().next().getKey();
    Assert.assertTrue(flatMapOp.getOperator() instanceof FlatMapOperator);
    Assert.assertTrue(filterOp.getOperator() instanceof FilterOperator);
    Assert.assertTrue(mapOp.getOperator() instanceof MapOperator);
    Assert.assertTrue(reduceByKeyOp.getOperator() instanceof ReduceByKeyOperator);
    Assert.assertTrue(sink.getSink() instanceof NettyTextSink);
}
Also used : Injector(org.apache.reef.tang.Injector) java.util(java.util) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Tuple2(edu.snu.mist.common.types.Tuple2) URISyntaxException(java.net.URISyntaxException) MISTEdge(edu.snu.mist.common.graph.MISTEdge) AvroDag(edu.snu.mist.formats.avro.AvroDag) MISTQuery(edu.snu.mist.client.MISTQuery) ReduceByKeyOperator(edu.snu.mist.core.operators.ReduceByKeyOperator) ServerSocket(java.net.ServerSocket) DAG(edu.snu.mist.common.graph.DAG) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) After(org.junit.After) MapOperator(edu.snu.mist.core.operators.MapOperator) Before(org.junit.Before) Tang(org.apache.reef.tang.Tang) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test) IOException(java.io.IOException) TestParameters(edu.snu.mist.core.utils.TestParameters) TaskHostname(edu.snu.mist.core.parameters.TaskHostname) FilterOperator(edu.snu.mist.core.operators.FilterOperator) Edge(edu.snu.mist.formats.avro.Edge) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) AvroVertex(edu.snu.mist.formats.avro.AvroVertex) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) AvroDag(edu.snu.mist.formats.avro.AvroDag) MapOperator(edu.snu.mist.core.operators.MapOperator) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) Injector(org.apache.reef.tang.Injector) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) MISTEdge(edu.snu.mist.common.graph.MISTEdge) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) FilterOperator(edu.snu.mist.core.operators.FilterOperator) ReduceByKeyOperator(edu.snu.mist.core.operators.ReduceByKeyOperator) MISTQuery(edu.snu.mist.client.MISTQuery) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test)

Example 5 with MISTQuery

use of edu.snu.mist.client.MISTQuery in project mist by snuspl.

the class GroupRecoveryTest method testSingleQueryRecovery.

@Test(timeout = 500000)
public void testSingleQueryRecovery() throws Exception {
    // Start source servers.
    final CountDownLatch sourceCountDownLatch1 = new CountDownLatch(1);
    final NettyTextMessageStreamGenerator textMessageStreamGenerator1 = new NettyTextMessageStreamGenerator(SERVER_ADDR, SOURCE_PORT1, new TestChannelHandler(sourceCountDownLatch1));
    final TestSinkHandler handler1 = new TestSinkHandler();
    final NettyTextMessageOutputReceiver receiver1 = new NettyTextMessageOutputReceiver("localhost", SINK_PORT, handler1);
    // Submit query.
    final MISTQuery query = buildQuery();
    // Generate avro chained dag : needed parts from MISTExamplesUtils.submitQuery()
    final Tuple<List<AvroVertex>, List<Edge>> initialAvroOpChainDag = query.getAvroOperatorDag();
    final String appId = "testApp";
    final String queryId = "testQuery";
    final AvroDag.Builder avroDagBuilder = AvroDag.newBuilder();
    final AvroDag avroDag = avroDagBuilder.setAppId(appId).setQueryId(queryId).setJarPaths(new ArrayList<>()).setAvroVertices(initialAvroOpChainDag.getKey()).setEdges(initialAvroOpChainDag.getValue()).build();
    // Build QueryManager.
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    jcb.bindNamedParameter(PeriodicCheckpointPeriod.class, "1000");
    jcb.bindImplementation(QueryManager.class, GroupAwareQueryManagerImpl.class);
    jcb.bindImplementation(QueryStarter.class, ImmediateQueryMergingStarter.class);
    jcb.bindNamedParameter(TaskHostname.class, "127.0.0.1");
    final Injector injector = Tang.Factory.getTang().newInjector(jcb.build());
    injector.bindVolatileInstance(GroupIdRequestor.class, new TestGroupIdRequestor());
    injector.bindVolatileInstance(TaskStatsUpdater.class, mock(TaskStatsUpdater.class));
    final CheckpointManager checkpointManager = injector.getInstance(CheckpointManager.class);
    final QueryManager queryManager = injector.getInstance(QueryManager.class);
    queryManager.createApplication(appId, Arrays.asList(""));
    queryManager.create(avroDag);
    // Wait until all sources connect to stream generator
    sourceCountDownLatch1.await();
    final ExecutionDags executionDags = checkpointManager.getApplication(appId).getGroups().get(0).getExecutionDags();
    Assert.assertEquals(executionDags.values().size(), 1);
    final ExecutionDag executionDag = executionDags.values().iterator().next();
    // 1st stage. Push inputs to all sources and see if the results are proper.
    SRC0INPUT1.forEach(textMessageStreamGenerator1::write);
    LATCH1.await();
    Assert.assertEquals("{aa=2, bb=1, cc=1}", handler1.getResults().get(handler1.getResults().size() - 1));
    // Sleep 2 seconds for the checkpoint events to be sent out.
    sleep(2000);
    // Checkpoint the entire MISTTask, delete it, and restore it to see if it works.
    final String groupId = checkpointManager.getApplication(appId).getGroups().get(0).getGroupId();
    checkpointManager.checkpointGroup(groupId);
    checkpointManager.deleteGroup(groupId);
    // Close the generator.
    textMessageStreamGenerator1.close();
    receiver1.close();
    // Restart source servers.
    final CountDownLatch sourceCountDownLatch2 = new CountDownLatch(1);
    final NettyTextMessageStreamGenerator textMessageStreamGenerator2 = new NettyTextMessageStreamGenerator(SERVER_ADDR, SOURCE_PORT1, new TestChannelHandler(sourceCountDownLatch2));
    final TestSinkHandler handler2 = new TestSinkHandler();
    final NettyTextMessageOutputReceiver receiver2 = new NettyTextMessageOutputReceiver("localhost", SINK_PORT, handler2);
    // Recover the group.
    checkpointManager.recoverGroup(groupId);
    // Wait until all sources connect to stream generator
    sourceCountDownLatch2.await();
    final ExecutionDags executionDags2 = checkpointManager.getApplication(appId).getGroups().get(0).getExecutionDags();
    Assert.assertEquals(executionDags2.values().size(), 1);
    final ExecutionDag executionDag2 = executionDags2.values().iterator().next();
    // 2nd stage. Push inputs to the recovered the query to see if it works.
    SRC0INPUT2.forEach(textMessageStreamGenerator2::write);
    LATCH2.await();
    Assert.assertEquals("{aa=3, bb=3, cc=3}", handler2.getResults().get(handler2.getResults().size() - 1));
    // Close the generators.
    textMessageStreamGenerator2.close();
    receiver2.close();
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NettyTextMessageOutputReceiver(edu.snu.mist.common.stream.textmessage.NettyTextMessageOutputReceiver) CountDownLatch(java.util.concurrent.CountDownLatch) AvroDag(edu.snu.mist.formats.avro.AvroDag) TaskStatsUpdater(edu.snu.mist.core.task.groupaware.TaskStatsUpdater) Injector(org.apache.reef.tang.Injector) MISTQuery(edu.snu.mist.client.MISTQuery) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NettyTextMessageStreamGenerator(edu.snu.mist.common.stream.textmessage.NettyTextMessageStreamGenerator) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) Test(org.junit.Test)

Aggregations

MISTQuery (edu.snu.mist.client.MISTQuery)6 Test (org.junit.Test)6 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)4 MISTEdge (edu.snu.mist.common.graph.MISTEdge)4 Tuple2 (edu.snu.mist.common.types.Tuple2)4 IOException (java.io.IOException)4 InjectionException (org.apache.reef.tang.exceptions.InjectionException)4 Assert (org.junit.Assert)4 DAG (edu.snu.mist.common.graph.DAG)3 AvroDag (edu.snu.mist.formats.avro.AvroDag)3 Injector (org.apache.reef.tang.Injector)3 After (org.junit.After)3 Before (org.junit.Before)3 TestParameters (edu.snu.mist.client.utils.TestParameters)2 UDFTestUtils (edu.snu.mist.client.utils.UDFTestUtils)2 SerializeUtils (edu.snu.mist.common.SerializeUtils)2 ConfKeys (edu.snu.mist.common.configurations.ConfKeys)2 edu.snu.mist.common.functions (edu.snu.mist.common.functions)2 CountWindowInformation (edu.snu.mist.common.windows.CountWindowInformation)2 SessionWindowInformation (edu.snu.mist.common.windows.SessionWindowInformation)2