Search in sources :

Example 46 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class TimeBatchWindowTestCase method timeWindowBatchTest7.

@Test
public void timeWindowBatchTest7() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(2 sec , 0) " + "select symbol, sum(price) as sumPrice, volume " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEventCount == 0) {
                AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
            }
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            } else if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    // Start sending events in the beginning of a cycle
    while (System.currentTimeMillis() % 2000 != 0) {
        ;
    }
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    Thread.sleep(8500);
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(new Object[] { "II", 60.5f, 1 });
    Thread.sleep(13000);
    inputHandler.send(new Object[] { "TT", 60.5f, 1 });
    inputHandler.send(new Object[] { "YY", 60.5f, 1 });
    Thread.sleep(5000);
    AssertJUnit.assertEquals(3, inEventCount);
    AssertJUnit.assertEquals(0, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 47 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class CustomJoinWindowTestCase method testMultipleStreamsFromWindow.

@Test
public void testMultipleStreamsFromWindow() throws InterruptedException {
    log.info("Test joining a single window by multiple streams");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockInputStream (symbol string, price float, volume long); " + "define stream SummaryOfCompanyTriggerStream (symbol string); " + "define stream VolumeGreaterThanTriggerStream (volume long); " + "define window StockWindow (symbol string, price float, volume long) lengthBatch(10); ";
    String query = "" + "@info(name = 'query0') " + "from StockInputStream " + "insert into StockWindow; " + "@info(name = 'query1') " + "from StockWindow join SummaryOfCompanyTriggerStream#window.length(1) " + "on StockWindow.symbol == SummaryOfCompanyTriggerStream.symbol " + "select StockWindow.symbol, sum(StockWindow.price) as totalPrice, sum(StockWindow.volume) as volumes " + "insert into SummaryOfCompanyOutputStream; " + "" + "@info(name = 'query2') " + "from StockWindow join VolumeGreaterThanTriggerStream#window.length(1) " + "on StockWindow.volume > VolumeGreaterThanTriggerStream.volume " + "select StockWindow.symbol, StockWindow.price, StockWindow.volume as volume " + "insert into VolumeGreaterThanOutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("SummaryOfCompanyOutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            Object[] data = events[0].getData();
            if ("WSO2".equals(data[0])) {
                assertArrayEquals(new Object[] { "WSO2", 430.0, 57L }, data);
            } else if ("IBM".equals(data[0])) {
                assertArrayEquals(new Object[] { "IBM", 222.0, 16L }, data);
            }
        }
    });
    siddhiAppRuntime.addCallback("VolumeGreaterThanOutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            assertEquals("Error in number of events with volume > 6", 6, events.length);
        }
    });
    siddhiAppRuntime.start();
    InputHandler stockInputStreamInputHandler = siddhiAppRuntime.getInputHandler("StockInputStream");
    InputHandler summaryOfCompanyTriggerStreamInputHandler = siddhiAppRuntime.getInputHandler("SummaryOfCompanyTriggerStream");
    InputHandler volumeGreaterThanTriggerStreamInputHandler = siddhiAppRuntime.getInputHandler("VolumeGreaterThanTriggerStream");
    // 10 inputs
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 84.0f, 20L });
    stockInputStreamInputHandler.send(new Object[] { "IBM", 90.0f, 1L });
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 55.0f, 5L });
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 77.0f, 10L });
    stockInputStreamInputHandler.send(new Object[] { "IBM", 46.0f, 5L });
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 36.0f, 2L });
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 56.0f, 6L });
    stockInputStreamInputHandler.send(new Object[] { "IBM", 86.0f, 10L });
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 26.0f, 6L });
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 96.0f, 8L });
    // out of 10
    stockInputStreamInputHandler.send(new Object[] { "WSO2", 56.0f, 10L });
    stockInputStreamInputHandler.send(new Object[] { "IBM", 36.0f, 15L });
    Thread.sleep(100);
    summaryOfCompanyTriggerStreamInputHandler.send(new Object[] { "WSO2" });
    summaryOfCompanyTriggerStreamInputHandler.send(new Object[] { "IBM" });
    volumeGreaterThanTriggerStreamInputHandler.send(new Object[] { 5L });
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 48 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method testExternalTimeBatchWindow11.

@Test
public void testExternalTimeBatchWindow11() throws InterruptedException {
    log.info("ExternalTimeBatchWindow test11");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string); " + "define window LoginWindow (timestamp long, ip string) externalTimeBatch(timestamp, 1 sec, 0); ";
    String query = "" + "@info(name = 'query0') " + "from LoginEvents " + "insert into LoginWindow; " + "" + "@info(name = 'query1') " + "from LoginWindow " + "select timestamp, ip, count() as total  " + "insert into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            for (Event event : inEvents) {
                inEventCount++;
                if (inEventCount == 1) {
                    assertEquals(4L, event.getData(2));
                } else if (inEventCount == 2) {
                    assertEquals(7L, event.getData(2));
                }
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
    inputHandler.send(new Object[] { 1366335804599L, "192.10.1.4" });
    inputHandler.send(new Object[] { 1366335804600L, "192.10.1.5" });
    inputHandler.send(new Object[] { 1366335804607L, "192.10.1.6" });
    inputHandler.send(new Object[] { 1366335805599L, "192.10.1.4" });
    inputHandler.send(new Object[] { 1366335805600L, "192.10.1.5" });
    inputHandler.send(new Object[] { 1366335805607L, "192.10.1.6" });
    Thread.sleep(2100);
    inputHandler.send(new Object[] { 1366335805606L, "192.10.1.7" });
    inputHandler.send(new Object[] { 1366335805605L, "192.10.1.8" });
    Thread.sleep(2100);
    inputHandler.send(new Object[] { 1366335805606L, "192.10.1.91" });
    inputHandler.send(new Object[] { 1366335805605L, "192.10.1.92" });
    inputHandler.send(new Object[] { 1366335806606L, "192.10.1.9" });
    inputHandler.send(new Object[] { 1366335806690L, "192.10.1.10" });
    Thread.sleep(3000);
    assertEquals("Event arrived", true, eventArrived);
    assertEquals("In Events ", 2, inEventCount);
    assertEquals("Remove Events ", 0, removeEventCount);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 49 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method testExternalTimeBatchWindow6.

@Test
public void testExternalTimeBatchWindow6() throws InterruptedException {
    log.info("ExternalTimeBatchWindow test6");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string); " + "define window LoginWindow (timestamp long, ip string) externalTimeBatch(timestamp, 1 sec, 0, 3 sec) " + "output all events; ";
    String query = "" + "@info(name = 'query0') " + "from LoginEvents " + "insert into LoginWindow; " + "" + "@info(name = 'query1') " + "from LoginWindow " + "select timestamp, ip, count() as total  " + "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
    inputHandler.send(new Object[] { 1366335804599L, "192.10.1.4" });
    inputHandler.send(new Object[] { 1366335804600L, "192.10.1.5" });
    inputHandler.send(new Object[] { 1366335804607L, "192.10.1.6" });
    inputHandler.send(new Object[] { 1366335805599L, "192.10.1.4" });
    inputHandler.send(new Object[] { 1366335805600L, "192.10.1.5" });
    inputHandler.send(new Object[] { 1366335805607L, "192.10.1.6" });
    Thread.sleep(5000);
    assertEquals("Event arrived", true, eventArrived);
    assertEquals("In Events ", 2, inEventCount);
    assertEquals("Remove Events ", 0, removeEventCount);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 50 with In

use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.

the class ExternalTimeBatchWindowTestCase method testExternalTimeBatchWindow7.

@Test
public void testExternalTimeBatchWindow7() throws InterruptedException {
    log.info("ExternalTimeBatchWindow test7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string); " + "define window LoginWindow (timestamp long, ip string) externalTimeBatch(timestamp, 1 sec, 0, 2 sec) " + "output all events; ";
    String query = "" + "@info(name = 'query0') " + "from LoginEvents " + "insert into LoginWindow; " + "" + "@info(name = 'query1') " + "from LoginWindow " + "select timestamp, ip, count() as total  " + "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
    inputHandler.send(new Object[] { 1366335804599L, "192.10.1.4" });
    inputHandler.send(new Object[] { 1366335804600L, "192.10.1.5" });
    inputHandler.send(new Object[] { 1366335804607L, "192.10.1.6" });
    inputHandler.send(new Object[] { 1366335805599L, "192.10.1.4" });
    inputHandler.send(new Object[] { 1366335805600L, "192.10.1.5" });
    inputHandler.send(new Object[] { 1366335805607L, "192.10.1.6" });
    Thread.sleep(3000);
    inputHandler.send(new Object[] { 1366335805606L, "192.10.1.7" });
    inputHandler.send(new Object[] { 1366335805605L, "192.10.1.8" });
    Thread.sleep(3000);
    inputHandler.send(new Object[] { 1366335806606L, "192.10.1.9" });
    inputHandler.send(new Object[] { 1366335806690L, "192.10.1.10" });
    Thread.sleep(3000);
    assertEquals("Event arrived", true, eventArrived);
    assertEquals("In Events ", 4, inEventCount);
    assertEquals("Remove Events ", 0, removeEventCount);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)348 Test (org.testng.annotations.Test)281 ArrayList (java.util.ArrayList)264 HashMap (java.util.HashMap)214 IOException (java.io.IOException)188 Event (org.wso2.siddhi.core.event.Event)187 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)186 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)186 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)182 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)160 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)153 Map (java.util.Map)116 SQLException (java.sql.SQLException)113 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)107 PreparedStatement (java.sql.PreparedStatement)106 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)96 Connection (java.sql.Connection)92 UserStoreException (org.wso2.carbon.user.api.UserStoreException)87 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)81 Resource (org.wso2.carbon.registry.core.Resource)78