use of org.wso2.siddhi.core.UnitTestAppender 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.core.UnitTestAppender 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.core.UnitTestAppender 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.core.UnitTestAppender in project siddhi by wso2.
the class LogSinkTest method testWithDefaultOptions.
@Test
public void testWithDefaultOptions() throws Exception {
SiddhiManager siddhiManager = new SiddhiManager();
String inputStream = "@App:name(\"HelloWorldApp\")\n" + "define stream CargoStream (weight int);";
String outputStream = "@sink(type='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("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 options", e);
} finally {
siddhiAppRuntime.shutdown();
}
}
Aggregations