Search in sources :

Example 1 with SessionWindowInformation

use of edu.snu.mist.common.windows.SessionWindowInformation in project mist by snuspl.

the class ContinuousStreamTest method testSessionWindowedStream.

/**
 * Test for creating session-based WindowedStream from ContinuousStream.
 */
@Test
public void testSessionWindowedStream() throws InjectionException {
    final int sessionInterval = 1000;
    /* Creates a test windowed stream with 1 sec session interval */
    final WindowedStream<Tuple2<String, Integer>> sessionWindowedStream = filteredMappedStream.window(new SessionWindowInformation(sessionInterval));
    // Check window info
    final Map<String, String> conf = sessionWindowedStream.getConfiguration();
    Assert.assertEquals(String.valueOf(sessionInterval), conf.get(ConfKeys.WindowOperator.WINDOW_INTERVAL.name()));
    // Check map -> countWindow
    checkEdges(queryBuilder.build().getDAG(), 1, filteredMappedStream, sessionWindowedStream, new MISTEdge(Direction.LEFT));
}
Also used : Tuple2(edu.snu.mist.common.types.Tuple2) MISTEdge(edu.snu.mist.common.graph.MISTEdge) SessionWindowInformation(edu.snu.mist.common.windows.SessionWindowInformation) Test(org.junit.Test)

Example 2 with SessionWindowInformation

use of edu.snu.mist.common.windows.SessionWindowInformation in project mist by snuspl.

the class SessionWindow method submitQuery.

/**
 * Submit a query.
 * The query reads strings from a source server, puts them into a window,
 * and if there is no incoming data during the interval of the session window,
 * the session will be closed.
 * The query will print out the data in the session, and a new session is created
 * @return result of the submission
 * @throws IOException
 * @throws InjectionException
 */
public static APIQueryControlResult submitQuery(final Configuration configuration) throws IOException, InjectionException, URISyntaxException {
    // configurations for source and sink
    final String sourceSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(NettySourceAddress.class);
    final SourceConfiguration localTextSocketSourceConf = MISTExampleUtils.getLocalTextSocketSourceConf(sourceSocket);
    // configurations for windowing and aggregation by session dependent on time
    final int sessionInterval = 5000;
    final MISTFunction<WindowData<String>, String> aggregateFunc = (windowData) -> {
        return windowData.getDataCollection().toString() + ", window is started at " + windowData.getStart() + ", window is ended at " + windowData.getEnd() + ".";
    };
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.socketTextStream(localTextSocketSourceConf).window(new SessionWindowInformation(sessionInterval)).aggregateWindow(aggregateFunc).textSocketOutput(MISTExampleUtils.SINK_HOSTNAME, MISTExampleUtils.SINK_PORT);
    System.out.println("End of submitQuery");
    return MISTExampleUtils.submit(queryBuilder, configuration);
}
Also used : Tang(org.apache.reef.tang.Tang) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) MISTFunction(edu.snu.mist.common.functions.MISTFunction) NettySourceAddress(edu.snu.mist.examples.parameters.NettySourceAddress) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CommandLine(org.apache.reef.tang.formats.CommandLine) APIQueryControlResult(edu.snu.mist.client.APIQueryControlResult) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) Configuration(org.apache.reef.tang.Configuration) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) WindowData(edu.snu.mist.common.windows.WindowData) InjectionException(org.apache.reef.tang.exceptions.InjectionException) SessionWindowInformation(edu.snu.mist.common.windows.SessionWindowInformation) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) WindowData(edu.snu.mist.common.windows.WindowData) SourceConfiguration(edu.snu.mist.client.datastreams.configurations.SourceConfiguration) SessionWindowInformation(edu.snu.mist.common.windows.SessionWindowInformation)

Aggregations

SessionWindowInformation (edu.snu.mist.common.windows.SessionWindowInformation)2 APIQueryControlResult (edu.snu.mist.client.APIQueryControlResult)1 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)1 SourceConfiguration (edu.snu.mist.client.datastreams.configurations.SourceConfiguration)1 MISTFunction (edu.snu.mist.common.functions.MISTFunction)1 MISTEdge (edu.snu.mist.common.graph.MISTEdge)1 Tuple2 (edu.snu.mist.common.types.Tuple2)1 WindowData (edu.snu.mist.common.windows.WindowData)1 NettySourceAddress (edu.snu.mist.examples.parameters.NettySourceAddress)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Configuration (org.apache.reef.tang.Configuration)1 JavaConfigurationBuilder (org.apache.reef.tang.JavaConfigurationBuilder)1 Tang (org.apache.reef.tang.Tang)1 InjectionException (org.apache.reef.tang.exceptions.InjectionException)1 CommandLine (org.apache.reef.tang.formats.CommandLine)1 Test (org.junit.Test)1