use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class LogSinkTest method testWithAllOptions.
@Test
public void testWithAllOptions() throws Exception {
SiddhiManager siddhiManager = new SiddhiManager();
String inputStream = "@App:name(\"HelloWorldApp\")\n" + "define stream CargoStream (weight int);";
String outputStream = "@sink(type='log', prefix='My Log', priority='info')\n" + "define stream OutputStream(weight int, totalWeight long);";
String query = ("@info(name='HelloWorldQuery') " + "from CargoStream " + "select weight, sum(weight) as totalWeight " + "insert into OutputStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + outputStream + query);
siddhiAppRuntime.start();
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("CargoStream");
Logger logger = Logger.getLogger(LogSink.class);
UnitTestAppender appender = new UnitTestAppender();
logger.addAppender(appender);
try {
inputHandler.send(new Object[] { 2 });
AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
AssertJUnit.assertTrue(appender.getMessages().contains("data=[2, 2]"));
inputHandler.send(new Object[] { 3 });
AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
AssertJUnit.assertTrue(appender.getMessages().contains("data=[3, 5]"));
} catch (Exception e) {
Assert.fail("Unexpected exception occurred when testing with all options", e);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class LogSinkTest method testWithDefaultPrefix.
@Test
public void testWithDefaultPrefix() throws Exception {
SiddhiManager siddhiManager = new SiddhiManager();
String inputStream = "@App:name(\"HelloWorldApp\")\n" + "define stream CargoStream (weight int);";
String outputStream = "@sink(type='log', priority='info')\n" + "define stream OutputStream(weight int, totalWeight long);";
String query = ("@info(name='HelloWorldQuery') " + "from CargoStream " + "select weight, sum(weight) as totalWeight " + "insert into OutputStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + outputStream + query);
siddhiAppRuntime.start();
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("CargoStream");
Logger logger = Logger.getLogger(LogSink.class);
UnitTestAppender appender = new UnitTestAppender();
logger.addAppender(appender);
try {
inputHandler.send(new Object[] { 2 });
AssertJUnit.assertTrue(appender.getMessages().contains("HelloWorldApp : OutputStream"));
AssertJUnit.assertTrue(appender.getMessages().contains("data=[2, 2]"));
inputHandler.send(new Object[] { 3 });
AssertJUnit.assertTrue(appender.getMessages().contains("HelloWorldApp : OutputStream"));
AssertJUnit.assertTrue(appender.getMessages().contains("data=[3, 5]"));
} catch (Exception e) {
Assert.fail("Unexpected exception occurred when testing with default prefix", e);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class LogSinkTest method testWithDefaultPriority.
@Test
public void testWithDefaultPriority() throws Exception {
SiddhiManager siddhiManager = new SiddhiManager();
String inputStream = "@App:name(\"HelloWorldApp\")\n" + "define stream CargoStream (weight int);";
String outputStream = "@sink(type='log', prefix='My Log')\n" + "define stream OutputStream(weight int, totalWeight long);";
String query = ("@info(name='HelloWorldQuery') " + "from CargoStream " + "select weight, sum(weight) as totalWeight " + "insert into OutputStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + outputStream + query);
siddhiAppRuntime.start();
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("CargoStream");
Logger logger = Logger.getLogger(LogSink.class);
UnitTestAppender appender = new UnitTestAppender();
logger.addAppender(appender);
try {
inputHandler.send(new Object[] { 2 });
AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
AssertJUnit.assertTrue(appender.getMessages().contains("data=[2, 2]"));
inputHandler.send(new Object[] { 3 });
AssertJUnit.assertTrue(appender.getMessages().contains("My Log"));
AssertJUnit.assertTrue(appender.getMessages().contains("data=[3, 5]"));
} catch (Exception e) {
Assert.fail("Unexpected exception occurred when testing with default priority", e);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitAnonymous_stream.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public AnonymousInputStream visitAnonymous_stream(@NotNull SiddhiQLParser.Anonymous_streamContext ctx) {
if (ctx.anonymous_stream() != null) {
return (AnonymousInputStream) visit(ctx.anonymous_stream());
}
Set<String> activeStreamsBackup = activeStreams;
try {
activeStreams = new HashSet<String>();
Query query = Query.query().from((InputStream) visit(ctx.query_input()));
if (ctx.query_section() != null) {
query.select((Selector) visit(ctx.query_section()));
}
if (ctx.output_rate() != null) {
query.output((OutputRate) visit(ctx.output_rate()));
}
if (ctx.output_event_type() != null) {
query.outStream(new ReturnStream((OutputStream.OutputEventType) visit(ctx.output_event_type())));
} else {
query.outStream(new ReturnStream());
}
AnonymousInputStream anonymousInputStream = new AnonymousInputStream(query);
populateQueryContext(anonymousInputStream, ctx);
return anonymousInputStream;
} finally {
activeStreams.clear();
activeStreams = activeStreamsBackup;
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitJoin_source.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Object visitJoin_source(@NotNull SiddhiQLParser.Join_sourceContext ctx) {
// join_source
// :io (basic_source_stream_handler)* window? (AS alias)?
// ;
Source source = (Source) visit(ctx.source());
String streamAlias = null;
if (ctx.alias() != null) {
streamAlias = (String) visit(ctx.alias());
activeStreams.remove(ctx.source().getText());
activeStreams.add(streamAlias);
}
BasicSingleInputStream basicSingleInputStream = new BasicSingleInputStream(streamAlias, source.streamId, source.isInnerStream);
if (ctx.basic_source_stream_handlers() != null) {
basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.basic_source_stream_handlers()));
}
if (ctx.window() != null) {
SingleInputStream inputStream = new SingleInputStream(basicSingleInputStream, (Window) visit(ctx.window()));
populateQueryContext(inputStream, ctx);
return inputStream;
} else {
populateQueryContext(basicSingleInputStream, ctx);
return basicSingleInputStream;
}
}
Aggregations