Search in sources :

Example 1 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException 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 InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.

the class WindowedStreamTest method testReduceByKeyWindowStream.

/**
 * Test for reduceByKeyWindow operation.
 */
@Test
public void testReduceByKeyWindowStream() throws InjectionException, IOException {
    final MISTBiFunction<Integer, Integer, Integer> reduceFunc = (x, y) -> x + y;
    final ContinuousStream<Map<String, Integer>> reducedWindowStream = timeWindowedStream.reduceByKeyWindow(0, String.class, reduceFunc);
    // Get info
    final Map<String, String> conf = reducedWindowStream.getConfiguration();
    Assert.assertEquals("0", conf.get(ConfKeys.ReduceByKeyOperator.KEY_INDEX.name()));
    Assert.assertEquals(SerializeUtils.serializeToString(reduceFunc), conf.get(ConfKeys.ReduceByKeyOperator.MIST_BI_FUNC.name()));
    // Check windowed -> reduce by key
    checkEdges(queryBuilder.build().getDAG(), 1, timeWindowedStream, reducedWindowStream, new MISTEdge(Direction.LEFT));
}
Also used : TimeWindowInformation(edu.snu.mist.common.windows.TimeWindowInformation) UDFTestUtils(edu.snu.mist.client.utils.UDFTestUtils) MISTFunction(edu.snu.mist.common.functions.MISTFunction) Iterator(java.util.Iterator) 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) Inject(javax.inject.Inject) SerializeUtils(edu.snu.mist.common.SerializeUtils) DAG(edu.snu.mist.common.graph.DAG) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) ApplyStatefulFunction(edu.snu.mist.common.functions.ApplyStatefulFunction) After(org.junit.After) Map(java.util.Map) Direction(edu.snu.mist.formats.avro.Direction) MISTBiFunction(edu.snu.mist.common.functions.MISTBiFunction) TestParameters(edu.snu.mist.client.utils.TestParameters) WindowData(edu.snu.mist.common.windows.WindowData) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) Before(org.junit.Before) Map(java.util.Map) MISTEdge(edu.snu.mist.common.graph.MISTEdge) Test(org.junit.Test)

Example 3 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.

the class ReduceByKeyOperatorTest method testReduceByKeyOperator.

/**
 * Test whether reduceByKeyOperator generates correct outputs.
 * Input: a list of tuples: ("a", 1), ("b", 1), ("c", 1), ("a", 1), ("d", 1), ("a", 1), ("b", 1)
 * Expected outputs: word counts:
 *  {"a": 1},
 *  {"a": 1, "b": 1},
 *  {"a": 1, "b": 1, "c": 1}
 *  {"a": 2, "b": 1, "c": 1}
 *  {"a": 2, "b": 1, "c": 1, "d": 1}
 *  {"a": 3, "b": 1, "c": 1, "d": 1}
 *  {"a": 3, "b": 2, "c": 1, "d": 1}
 */
@Test
public void testReduceByKeyOperator() throws InjectionException {
    // input stream
    final List<MistDataEvent> inputStream = ImmutableList.of(createTupleEvent("a", 1, 1L), createTupleEvent("b", 1, 2L), createTupleEvent("c", 1, 3L), createTupleEvent("a", 1, 4L), createTupleEvent("d", 1, 5L), createTupleEvent("a", 1, 6L), createTupleEvent("b", 1, 7L));
    // expected output
    final Map<String, Integer> o0 = new HashMap<>();
    o0.put("a", 1);
    final Map<String, Integer> o1 = new HashMap<>(o0);
    o1.put("b", 1);
    final Map<String, Integer> o2 = new HashMap<>(o1);
    o2.put("c", 1);
    final Map<String, Integer> o3 = new HashMap<>(o2);
    o3.put("a", 2);
    final Map<String, Integer> o4 = new HashMap<>(o3);
    o4.put("d", 1);
    final Map<String, Integer> o5 = new HashMap<>(o4);
    o5.put("a", 3);
    final Map<String, Integer> o6 = new HashMap<>(o5);
    o6.put("b", 2);
    final List<MistEvent> expectedStream = ImmutableList.of(new MistDataEvent(o0, 1L), new MistDataEvent(o1, 2L), new MistDataEvent(o2, 3L), new MistDataEvent(o3, 4L), new MistDataEvent(o4, 5L), new MistDataEvent(o5, 6L), new MistDataEvent(o6, 7L));
    // Set the key index of tuple
    final int keyIndex = 0;
    // Reduce function for word count
    final MISTBiFunction<Integer, Integer, Integer> wordCountFunc = (oldVal, val) -> oldVal + val;
    final ReduceByKeyOperator<String, Integer> wcOperator = new ReduceByKeyOperator<>(keyIndex, wordCountFunc);
    // output test
    final List<MistEvent> result = new LinkedList<>();
    wcOperator.setOutputEmitter(new OutputBufferEmitter(result));
    inputStream.stream().forEach(wcOperator::processLeftData);
    LOG.info("expected: " + expectedStream);
    LOG.info("result: " + result);
    Assert.assertEquals(expectedStream, result);
}
Also used : Tuple2(edu.snu.mist.common.types.Tuple2) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test) HashMap(java.util.HashMap) Logger(java.util.logging.Logger) MistDataEvent(edu.snu.mist.core.MistDataEvent) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) Map(java.util.Map) MISTBiFunction(edu.snu.mist.common.functions.MISTBiFunction) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) MistEvent(edu.snu.mist.core.MistEvent) LinkedList(java.util.LinkedList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) MistDataEvent(edu.snu.mist.core.MistDataEvent) Test(org.junit.Test)

Example 4 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.

the class StatelessOperatorTest method testMapOperation.

/**
 * Test map operation.
 * It converts string to tuple (string, 1).
 */
@Test
public void testMapOperation() throws InjectionException {
    // input stream
    final List<MistDataEvent> inputStream = ImmutableList.of(new MistDataEvent("a", 1L), new MistDataEvent("b", 2L), new MistDataEvent("d", 3L), new MistDataEvent("b", 4L), new MistDataEvent("c", 5L));
    // expected output
    final List<MistEvent> expectedStream = ImmutableList.of(new MistDataEvent(new Tuple<>("a", 1), 1L), new MistDataEvent(new Tuple<>("b", 1), 2L), new MistDataEvent(new Tuple<>("d", 1), 3L), new MistDataEvent(new Tuple<>("b", 1), 4L), new MistDataEvent(new Tuple<>("c", 1), 5L));
    // map function: convert string to tuple
    final MISTFunction<String, Tuple> mapFunc = (mapInput) -> new Tuple<>(mapInput, 1);
    final MapOperator<String, Tuple> mapOperator = new MapOperator<>(mapFunc);
    testStatelessOperator(inputStream, expectedStream, mapOperator);
}
Also used : Arrays(java.util.Arrays) MISTFunction(edu.snu.mist.common.functions.MISTFunction) MISTPredicate(edu.snu.mist.common.functions.MISTPredicate) MistEvent(edu.snu.mist.core.MistEvent) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test) Logger(java.util.logging.Logger) MistDataEvent(edu.snu.mist.core.MistDataEvent) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) LinkedList(java.util.LinkedList) MistDataEvent(edu.snu.mist.core.MistDataEvent) MistEvent(edu.snu.mist.core.MistEvent) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test)

Example 5 with InjectionException

use of org.apache.reef.tang.exceptions.InjectionException in project mist by snuspl.

the class StatelessOperatorTest method testFlatMapOperation.

/**
 * Test flatMap operation.
 * It splits the string by space.
 */
@Test
public void testFlatMapOperation() throws InjectionException {
    // input stream
    final List<MistDataEvent> inputStream = ImmutableList.of(new MistDataEvent("a b c", 1L), new MistDataEvent("b c d", 2L), new MistDataEvent("d e f", 3L));
    // expected output
    final List<MistEvent> expectedStream = ImmutableList.of(new MistDataEvent("a", 1L), new MistDataEvent("b", 1L), new MistDataEvent("c", 1L), new MistDataEvent("b", 2L), new MistDataEvent("c", 2L), new MistDataEvent("d", 2L), new MistDataEvent("d", 3L), new MistDataEvent("e", 3L), new MistDataEvent("f", 3L));
    // map function: splits the string by space.
    final MISTFunction<String, List<String>> flatMapFunc = (mapInput) -> Arrays.asList(mapInput.split(" "));
    final FlatMapOperator<String, String> flatMapOperator = new FlatMapOperator<>(flatMapFunc);
    testStatelessOperator(inputStream, expectedStream, flatMapOperator);
}
Also used : Arrays(java.util.Arrays) MISTFunction(edu.snu.mist.common.functions.MISTFunction) MISTPredicate(edu.snu.mist.common.functions.MISTPredicate) MistEvent(edu.snu.mist.core.MistEvent) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test) Logger(java.util.logging.Logger) MistDataEvent(edu.snu.mist.core.MistDataEvent) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OutputBufferEmitter(edu.snu.mist.core.utils.OutputBufferEmitter) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) LinkedList(java.util.LinkedList) MistDataEvent(edu.snu.mist.core.MistDataEvent) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) MistEvent(edu.snu.mist.core.MistEvent) Test(org.junit.Test)

Aggregations

InjectionException (org.apache.reef.tang.exceptions.InjectionException)24 IOException (java.io.IOException)17 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)16 URISyntaxException (java.net.URISyntaxException)14 Configuration (org.apache.reef.tang.Configuration)14 Tang (org.apache.reef.tang.Tang)13 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)12 APIQueryControlResult (edu.snu.mist.client.APIQueryControlResult)11 SourceConfiguration (edu.snu.mist.client.datastreams.configurations.SourceConfiguration)11 CommandLine (org.apache.reef.tang.formats.CommandLine)11 Tuple2 (edu.snu.mist.common.types.Tuple2)9 MISTFunction (edu.snu.mist.common.functions.MISTFunction)8 NettySourceAddress (edu.snu.mist.examples.parameters.NettySourceAddress)8 Injector (org.apache.reef.tang.Injector)8 Assert (org.junit.Assert)8 Test (org.junit.Test)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 MISTBiFunction (edu.snu.mist.common.functions.MISTBiFunction)5 Tuple (org.apache.reef.io.Tuple)5