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));
}
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);
}
Aggregations