Search in sources :

Example 96 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class StatisticsTestCase method statisticsTest5.

/**
 * To not enable stats if no Stats manager enabled
 */
@Test
public void statisticsTest5() throws InterruptedException {
    log.info("statistics test 5");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.enableStats(true);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            for (Event event : events) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(event.getData(0)) || "WSO2".equals(event.getData(0)));
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream old = System.out;
    System.setOut(ps);
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    Thread.sleep(3010);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(3, count);
    System.out.flush();
    String output = baos.toString();
    AssertJUnit.assertFalse(output.contains("Gauges"));
    log.info(output);
    System.setOut(old);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) PrintStream(java.io.PrintStream) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 97 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class StatisticsTestCase method statisticsTest1.

@Test
public void statisticsTest1() throws InterruptedException {
    log.info("statistics test 1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:statistics(reporter = 'console', interval = '2' )" + " " + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            for (Event event : events) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(event.getData(0)) || "WSO2".equals(event.getData(0)));
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream old = System.out;
    System.setOut(ps);
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    Thread.sleep(3010);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(3, count);
    System.out.flush();
    String output = baos.toString();
    AssertJUnit.assertTrue(output.contains("Gauges"));
    AssertJUnit.assertTrue(output.contains("org.wso2.siddhi." + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS));
    AssertJUnit.assertTrue(output.contains("query1.memory"));
    AssertJUnit.assertTrue(output.contains("Meters"));
    AssertJUnit.assertTrue(output.contains(SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_STREAMS + SiddhiConstants.METRIC_DELIMITER + "cseEventStream"));
    AssertJUnit.assertTrue(output.contains("Timers"));
    AssertJUnit.assertTrue(output.contains("query1.latency"));
    log.info(output);
    System.setOut(old);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) PrintStream(java.io.PrintStream) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 98 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class StatisticsTestCase method statisticsTest4.

/**
 * To test stats dynamic enabling
 */
@Test
public void statisticsTest4() throws InterruptedException {
    log.info("statistics test 4");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:statistics(reporter = 'console', interval = '2' )" + " " + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.enableStats(false);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            for (Event event : events) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(event.getData(0)) || "WSO2".equals(event.getData(0)));
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    PrintStream old = System.out;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    System.setOut(ps);
    siddhiAppRuntime.start();
    siddhiAppRuntime.enableStats(false);
    inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    Thread.sleep(3010);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(3, count);
    System.out.flush();
    String output = baos.toString();
    baos.reset();
    log.info(output);
    AssertJUnit.assertFalse(output.contains("Gauges"));
    // reset
    eventArrived = false;
    count = 0;
    siddhiAppRuntime.enableStats(true);
    Thread.sleep(100);
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    Thread.sleep(3030);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(1, count);
    System.out.flush();
    output = baos.toString();
    baos.reset();
    log.info(output);
    AssertJUnit.assertTrue(output.contains("Gauges"));
    siddhiAppRuntime.shutdown();
    System.setOut(old);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) PrintStream(java.io.PrintStream) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 99 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class StatisticsTestCase method statisticsTest6.

@Test
public void statisticsTest6() throws InterruptedException {
    log.info("statistics test 1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:statistics(reporter = 'console', interval = '2', include='*query2.*,*cseEventStream2*' )" + " " + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select * " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream[volume > 90] " + "select * " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            for (Event event : events) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(event.getData(0)) || "WSO2".equals(event.getData(0)));
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    PrintStream old = System.out;
    System.setOut(ps);
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    Thread.sleep(3010);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(3, count);
    System.out.flush();
    String output = baos.toString();
    AssertJUnit.assertTrue(output.contains("Gauges"));
    AssertJUnit.assertTrue(output.contains("org.wso2.siddhi." + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS));
    AssertJUnit.assertFalse(output.contains("query1.memory"));
    AssertJUnit.assertTrue(output.contains("cseEventStream2.throughput"));
    AssertJUnit.assertTrue(output.contains("Meters"));
    AssertJUnit.assertTrue(output.contains(SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_STREAMS + SiddhiConstants.METRIC_DELIMITER + "cseEventStream"));
    AssertJUnit.assertTrue(output.contains("Timers"));
    AssertJUnit.assertFalse(output.contains("query1.latency"));
    AssertJUnit.assertTrue(output.contains("query2.memory"));
    log.info(output);
    System.setOut(old);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) PrintStream(java.io.PrintStream) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 100 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class ValidateTestCase method validateTest1.

@Test
public void validateTest1() throws InterruptedException {
    log.info("validate test1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('validateTest') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[symbol is null] " + "select symbol, price " + "insert into outputStream;";
    siddhiManager.validateSiddhiApp(siddhiApp);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)845 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)841 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)818 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)777 Event (org.wso2.siddhi.core.event.Event)473 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)377 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)100 Query (org.wso2.siddhi.query.api.execution.query.Query)80 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)67 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)65 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 IOException (java.io.IOException)14 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)11 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)11 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)10 Response (javax.ws.rs.core.Response)9 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)8 ObjectOutputStream (java.io.ObjectOutputStream)7 OutputStream (java.io.OutputStream)6