Search in sources :

Example 1 with UnitTestAppender

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();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) UnitTestAppender(org.wso2.siddhi.core.UnitTestAppender) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Logger(org.apache.log4j.Logger) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 2 with UnitTestAppender

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();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) UnitTestAppender(org.wso2.siddhi.core.UnitTestAppender) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Logger(org.apache.log4j.Logger) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 3 with UnitTestAppender

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();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) UnitTestAppender(org.wso2.siddhi.core.UnitTestAppender) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Logger(org.apache.log4j.Logger) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 4 with UnitTestAppender

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();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) UnitTestAppender(org.wso2.siddhi.core.UnitTestAppender) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Logger(org.apache.log4j.Logger) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Logger (org.apache.log4j.Logger)4 Test (org.testng.annotations.Test)4 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)4 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)4 UnitTestAppender (org.wso2.siddhi.core.UnitTestAppender)4 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)4