Search in sources :

Example 71 with In

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

the class PrimaryKeyTableTestCase method primaryKeyTableTest23.

@Test
public void primaryKeyTableTest23() throws InterruptedException {
    log.info("primaryKeyTableTest23");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "@PrimaryKey('volume') " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream[(volume > StockTable.volume) in StockTable] " + "insert into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        siddhiAppRuntime.addCallback("query2", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                if (inEvents != null) {
                    for (Event event : inEvents) {
                        inEventsList.add(event.getData());
                        inEventCount.incrementAndGet();
                    }
                    eventArrived = true;
                }
                if (removeEvents != null) {
                    removeEventCount = removeEventCount + removeEvents.length;
                }
                eventArrived = true;
            }
        });
        InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
        InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
        siddhiAppRuntime.start();
        stockStream.send(new Object[] { "WSO2", 55.6f, 200L });
        stockStream.send(new Object[] { "BAR", 55.6f, 150L });
        stockStream.send(new Object[] { "IBM", 55.6f, 100L });
        checkStockStream.send(new Object[] { "FOO", 170L });
        checkStockStream.send(new Object[] { "FOO", 500L });
        List<Object[]> expected = new ArrayList<Object[]>();
        expected.add(new Object[] { "FOO", 170L });
        expected.add(new Object[] { "FOO", 500L });
        SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
        AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList, expected));
        AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get());
        AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
        AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) ArrayList(java.util.ArrayList) 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 72 with In

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

the class UpdateFromTableTestCase method updateFromTableTest3.

@Test
public void updateFromTableTest3() throws InterruptedException {
    log.info("updateFromTableTest3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update StockTable " + "   on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and  volume==StockTable.volume) in StockTable] " + "insert into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("query3", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                for (Event event : inEvents) {
                    inEventCount++;
                    switch(inEventCount) {
                        case 1:
                            AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
                            break;
                        case 3:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(3, inEventCount);
                    }
                }
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
    InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 55.6f, 100L });
    checkStockStream.send(new Object[] { "IBM", 100L });
    checkStockStream.send(new Object[] { "WSO2", 100L });
    updateStockStream.send(new Object[] { "IBM", 77.6f, 200L });
    checkStockStream.send(new Object[] { "IBM", 100L });
    checkStockStream.send(new Object[] { "WSO2", 100L });
    Thread.sleep(500);
    AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
    AssertJUnit.assertEquals("Event arrived", true, 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 73 with In

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

the class UpdateFromTableTestCase method updateFromTableTest6.

@Test
public void updateFromTableTest6() throws InterruptedException {
    log.info("updateFromTableTest6");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define stream UpdateStockStream (comp string, vol long); " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream join StockTable " + "   on UpdateStockStream.comp == StockTable.symbol " + "select symbol, vol as volume " + "update StockTable " + "   on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume and price==StockTable" + ".price) in StockTable] " + "insert into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("query3", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                for (Event event : inEvents) {
                    inEventCount++;
                    switch(inEventCount) {
                        case 1:
                            AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L, 155.6f }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { "IBM", 200L, 155.6f }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(2, inEventCount);
                    }
                }
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
    InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 155.6f, 100L });
    checkStockStream.send(new Object[] { "IBM", 100L, 155.6f });
    checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
    updateStockStream.send(new Object[] { "IBM", 200L });
    checkStockStream.send(new Object[] { "IBM", 200L, 155.6f });
    checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
    Thread.sleep(500);
    AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
    AssertJUnit.assertEquals("Event arrived", true, 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 74 with In

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

the class UpdateFromTableTestCase method updateFromTableTest5.

@Test
public void updateFromTableTest5() throws InterruptedException {
    log.info("updateFromTableTest5");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define stream UpdateStockStream (comp string, vol long); " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "select comp as symbol, vol as volume " + "update StockTable " + "   on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume and price==StockTable" + ".price) in StockTable] " + "insert into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("query3", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                for (Event event : inEvents) {
                    inEventCount++;
                    switch(inEventCount) {
                        case 1:
                            AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L, 155.6f }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { "IBM", 200L, 155.6f }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(2, inEventCount);
                    }
                }
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
    InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 155.6f, 100L });
    checkStockStream.send(new Object[] { "IBM", 100L, 155.6f });
    checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
    updateStockStream.send(new Object[] { "IBM", 200L });
    checkStockStream.send(new Object[] { "IBM", 200L, 155.6f });
    checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
    Thread.sleep(500);
    AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
    AssertJUnit.assertEquals("Event arrived", true, 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 75 with In

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

the class UpdateFromTableTestCase method updateFromTableTest4.

@Test
public void updateFromTableTest4() throws InterruptedException {
    log.info("updateFromTableTest4");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define stream UpdateStockStream (comp string, vol long); " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "select comp as symbol, vol as volume " + "update StockTable " + "   on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and  volume==StockTable.volume) in StockTable] " + "insert into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("query3", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                for (Event event : inEvents) {
                    inEventCount++;
                    switch(inEventCount) {
                        case 1:
                            AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
                            break;
                        case 3:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(3, inEventCount);
                    }
                }
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
    InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 55.6f, 100L });
    checkStockStream.send(new Object[] { "IBM", 100L });
    checkStockStream.send(new Object[] { "WSO2", 100L });
    updateStockStream.send(new Object[] { "IBM", 200L });
    checkStockStream.send(new Object[] { "IBM", 100L });
    checkStockStream.send(new Object[] { "WSO2", 100L });
    Thread.sleep(500);
    AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
    AssertJUnit.assertEquals("Event arrived", true, 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)

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