use of io.siddhi.core.UnitTestAppender in project siddhi by wso2.
the class LogSinkTest method testWithDefaultPrefix.
@Test
public void testWithDefaultPrefix() throws Exception {
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();
UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null);
final Logger logger = (Logger) LogManager.getRootLogger();
logger.setLevel(Level.ALL);
logger.addAppender(appender);
appender.start();
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");
try {
inputHandler.send(new Object[] { 2 });
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("HelloWorldApp : OutputStream"));
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("data=[2, 2]"));
inputHandler.send(new Object[] { 3 });
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("HelloWorldApp : OutputStream"));
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("data=[3, 5]"));
} catch (Exception e) {
Assert.fail("Unexpected exception occurred when testing with default prefix", e);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.UnitTestAppender in project siddhi by wso2.
the class LogSinkTest method testWithDefaultPriority.
@Test
public void testWithDefaultPriority() throws Exception {
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();
UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null);
final Logger logger = (Logger) LogManager.getRootLogger();
logger.setLevel(Level.ALL);
logger.addAppender(appender);
appender.start();
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");
try {
inputHandler.send(new Object[] { 2 });
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("My Log"));
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("data=[2, 2]"));
inputHandler.send(new Object[] { 3 });
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("My Log"));
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages().contains("data=[3, 5]"));
} catch (Exception e) {
Assert.fail("Unexpected exception occurred when testing with default priority", e);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.UnitTestAppender in project siddhi by wso2.
the class FaultStreamTestCase method faultStreamTest4.
@Test(dependsOnMethods = "faultStreamTest3")
public void faultStreamTest4() throws InterruptedException {
log.info("faultStreamTest4-Tests fault handling when it's set to stream. " + "Events would be available in the corresponding fault stream");
UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null);
Logger logger = (Logger) LogManager.getLogger(StreamJunction.class);
logger.addAppender(appender);
appender.start();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setExtension("custom:fault", FaultFunctionExtension.class);
String siddhiApp = "" + "@OnError(action='stream')" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[custom:fault() > volume] " + "select symbol, price, symbol as sym1 " + "insert into outputStream ;" + "" + "from !cseEventStream " + "select * " + "insert into faultStream";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("faultStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
Assert.assertTrue(events[0].getData(3) != null);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
try {
inputHandler.send(new Object[] { "IBM", 0f, 100L });
AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders().get("UnitTestAppender")).getMessages() == null);
} catch (Exception e) {
Assert.fail("Unexpected exception occurred when testing.", e);
} finally {
logger.removeAppender(appender);
siddhiAppRuntime.shutdown();
}
AssertJUnit.assertEquals(1, count.get());
AssertJUnit.assertTrue(eventArrived);
}
Aggregations