Search in sources :

Example 41 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class ContinuousStreamTest method testTimeWindowedStream.

/**
 * Test for creating time-based WindowedStream from ContinuousStream.
 */
@Test
public void testTimeWindowedStream() {
    final WindowedStream<Tuple2<String, Integer>> timeWindowedStream = filteredMappedStream.window(new TimeWindowInformation(windowSize, windowEmissionInterval));
    final Map<String, String> conf = timeWindowedStream.getConfiguration();
    checkSizeBasedWindowInfo(windowSize, windowEmissionInterval, conf);
    // Check map -> timeWindow
    checkEdges(queryBuilder.build().getDAG(), 1, filteredMappedStream, timeWindowedStream, new MISTEdge(Direction.LEFT));
}
Also used : Tuple2(edu.snu.mist.common.types.Tuple2) TimeWindowInformation(edu.snu.mist.common.windows.TimeWindowInformation) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 42 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class ContinuousStreamTest method testMqttSink.

/**
 * Test for Mqtt sink.
 */
@Test
public void testMqttSink() throws InjectionException {
    final MISTStream<MqttMessage> sink = filteredMappedStream.mqttOutput(TestParameters.HOST, TestParameters.TOPIC);
    final Map<String, String> conf = sink.getConfiguration();
    Assert.assertEquals(TestParameters.HOST, conf.get(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name()));
    Assert.assertEquals(TestParameters.TOPIC, conf.get(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name()));
    // Check src -> sink
    final DAG<MISTStream, MISTEdge> dag = queryBuilder.build().getDAG();
    final Map<MISTStream, MISTEdge> neighbors = dag.getEdges(filteredMappedStream);
    Assert.assertEquals(1, neighbors.size());
    Assert.assertEquals(new MISTEdge(Direction.LEFT), neighbors.get(sink));
}
Also used : MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 43 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class ContinuousStreamTest method testReduceByKeyOperatorStream.

/**
 * Test for reduceByKey operator.
 */
@Test
public void testReduceByKeyOperatorStream() throws IOException {
    final MISTBiFunction<Integer, Integer, Integer> biFunc = (x, y) -> x + y;
    final int keyIndex = 0;
    final ContinuousStream<Map<String, Integer>> reducedStream = filteredMappedStream.reduceByKey(0, String.class, biFunc);
    final Map<String, String> conf = reducedStream.getConfiguration();
    Assert.assertEquals(String.valueOf(keyIndex), conf.get(ConfKeys.ReduceByKeyOperator.KEY_INDEX.name()));
    Assert.assertEquals(SerializeUtils.serializeToString(biFunc), conf.get(ConfKeys.ReduceByKeyOperator.MIST_BI_FUNC.name()));
    // Check filter -> map -> reduceBy
    checkEdges(queryBuilder.build().getDAG(), 1, filteredMappedStream, reducedStream, 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) Map(java.util.Map) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 44 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class OperatorChainDagGenerator method generateOperatorChainDAG.

/**
 * Generate OperatorChain DAG according to the logic described above.
 * @return the OperatorChain DAG
 * The chain is represented as a list and AvroVertexSerializable can be serialized by avro
 */
public DAG<List<MISTStream>, MISTEdge> generateOperatorChainDAG() {
    final DAG<OperatorChain, MISTEdge> chainDag = new AdjacentListDAG<>();
    final Map<MISTStream, OperatorChain> vertexChainMap = new HashMap<>();
    // from the root operators which are following sources.
    for (final MISTStream source : optimizedDag.getRootVertices()) {
        final Map<MISTStream, MISTEdge> rootEdges = optimizedDag.getEdges(source);
        // This chaining group is a wrapper for List, for equality check
        final OperatorChain srcChain = new OperatorChain();
        // Partition Source
        srcChain.chain.add(source);
        chainDag.addVertex(srcChain);
        vertexChainMap.put(source, srcChain);
        for (final Map.Entry<MISTStream, MISTEdge> entry : rootEdges.entrySet()) {
            final MISTStream nextVertex = entry.getKey();
            final MISTEdge edge = entry.getValue();
            final OperatorChain nextChain = getOperatorChain(nextVertex, vertexChainMap, chainDag);
            chainDag.addEdge(srcChain, nextChain, edge);
            chainingInDfsOrder(nextChain, nextVertex, chainDag, vertexChainMap);
        }
    }
    // Convert to List<AvroVertexSerializable> for AvroOperatorChainDag
    final DAG<List<MISTStream>, MISTEdge> result = new AdjacentListDAG<>();
    final Queue<OperatorChain> queue = new LinkedList<>();
    final Iterator<OperatorChain> iterator = GraphUtils.topologicalSort(chainDag);
    while (iterator.hasNext()) {
        final OperatorChain queryPartition = iterator.next();
        queue.add(queryPartition);
        result.addVertex(queryPartition.chain);
    }
    for (final OperatorChain operatorChain : queue) {
        final Map<OperatorChain, MISTEdge> edges = chainDag.getEdges(operatorChain);
        for (final Map.Entry<OperatorChain, MISTEdge> edge : edges.entrySet()) {
            result.addEdge(operatorChain.chain, edge.getKey().chain, edge.getValue());
        }
    }
    return result;
}
Also used : MISTStream(edu.snu.mist.client.datastreams.MISTStream) MISTEdge(edu.snu.mist.common.graph.MISTEdge) AdjacentListDAG(edu.snu.mist.common.graph.AdjacentListDAG)

Example 45 with MISTEdge

use of edu.snu.mist.common.graph.MISTEdge in project mist by snuspl.

the class ContinuousStreamImpl method mqttOutput.

@Override
public MISTStream<MqttMessage> mqttOutput(final String brokerURI, final String topic) {
    final Map<String, String> confMap = new HashMap<>();
    confMap.put(ConfKeys.SinkConf.SINK_TYPE.name(), ConfValues.SinkType.MQTT.name());
    confMap.put(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name(), brokerURI);
    confMap.put(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name(), topic);
    final MISTStream<MqttMessage> sink = new MISTStreamImpl<>(dag, confMap);
    dag.addVertex(sink);
    dag.addEdge(this, sink, new MISTEdge(Direction.LEFT));
    return sink;
}
Also used : MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) MISTEdge(edu.snu.mist.common.graph.MISTEdge)

Aggregations

MISTEdge (edu.snu.mist.common.graph.MISTEdge)50 Test (org.junit.Test)23 Tuple2 (edu.snu.mist.common.types.Tuple2)12 MISTStream (edu.snu.mist.client.datastreams.MISTStream)11 Map (java.util.Map)11 DAG (edu.snu.mist.common.graph.DAG)9 Direction (edu.snu.mist.formats.avro.Direction)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 InjectionException (org.apache.reef.tang.exceptions.InjectionException)6 MISTQuery (edu.snu.mist.client.MISTQuery)5 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)5 UDFTestUtils (edu.snu.mist.client.utils.UDFTestUtils)5 AdjacentListDAG (edu.snu.mist.common.graph.AdjacentListDAG)5 TimeWindowInformation (edu.snu.mist.common.windows.TimeWindowInformation)5 List (java.util.List)5 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)5 TestParameters (edu.snu.mist.client.utils.TestParameters)4 SerializeUtils (edu.snu.mist.common.SerializeUtils)4 ConfKeys (edu.snu.mist.common.configurations.ConfKeys)4