Search in sources :

Example 61 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class PrimaryKeyTableTestCase method primaryKeyTableTest14.

@Test
public void primaryKeyTableTest14() throws InterruptedException {
    log.info("primaryKeyTableTest14");
    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);" + "@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 UpdateStockStream " + "select price, volume  " + "update StockTable " + "   on StockTable.volume > volume;" + "" + "@info(name = 'query3') " + "from CheckStockStream join StockTable " + " on CheckStockStream.volume <= StockTable.volume " + "select StockTable.price, StockTable.volume " + "insert into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        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) {
                        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");
        InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
        siddhiAppRuntime.start();
        stockStream.send(new Object[] { "WSO2", 55.6f, 200L });
        stockStream.send(new Object[] { "IBM", 55.6f, 100L });
        checkStockStream.send(new Object[] { "WSO2", 150L });
        updateStockStream.send(new Object[] { "FOO", 77.6f, 150L });
        checkStockStream.send(new Object[] { "BAR", 150L });
        List<Object[]> expected = Arrays.asList(new Object[] { 55.6f, 200L }, new Object[] { 77.6f, 150L });
        SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
        AssertJUnit.assertEquals("In first events matched", true, SiddhiTestHelper.isEventsMatch(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) 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 62 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class PrimaryKeyTableTestCase method primaryKeyTableTest26.

@Test
public void primaryKeyTableTest26() throws InterruptedException {
    log.info("primaryKeyTableTest26");
    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", 100L });
        List<Object[]> expected = new ArrayList<Object[]>();
        expected.add(new Object[] { "FOO", 170L });
        expected.add(new Object[] { "FOO", 100L });
        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 63 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class PrimaryKeyTableTestCase method primaryKeyTableTest32.

@Test(expectedExceptions = SiddhiParserException.class)
public void primaryKeyTableTest32() throws InterruptedException {
    log.info("primaryKeyTableTest32");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@PrimaryKey'symbol' " + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "";
    SiddhiAppRuntime siddhiAppRuntime = null;
    try {
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    } finally {
        if (siddhiAppRuntime != null) {
            siddhiAppRuntime.shutdown();
        }
    }
}
Also used : SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 64 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class PrimaryKeyTableTestCase method primaryKeyTableTest35.

@Test
public void primaryKeyTableTest35() throws InterruptedException {
    log.info("primaryKeyTableTest35");
    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); " + "define stream StockStream1 (symbol string, price float, volume long); " + "define stream CheckStockStream1 (symbol string, volume long); " + "define stream UpdateStockStream1 (symbol string, price float, volume long);" + "@PrimaryKey('symbol') " + "define table StockTable1 (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream join StockTable " + " on CheckStockStream.symbol==StockTable.symbol " + "select CheckStockStream.symbol, StockTable.volume " + "insert into OutStream;" + "" + "@info(name = 'query11') " + "from StockStream1 " + "insert into StockTable1 ;" + "" + "@info(name = 'query21') " + "from CheckStockStream1 join StockTable1 " + " on CheckStockStream1.symbol==StockTable1.symbol " + "select CheckStockStream1.symbol, StockTable1.volume " + "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) {
                eventArrived = true;
            }
        });
        InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
        InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
        InputHandler stockStream1 = siddhiAppRuntime.getInputHandler("StockStream1");
        InputHandler checkStockStream1 = siddhiAppRuntime.getInputHandler("CheckStockStream1");
        siddhiAppRuntime.start();
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 10; i++) {
            stockStream.send(new Object[] { "WSO2" + i, 55.6f, 100L });
        }
        for (int i = 0; i < 1000000; i++) {
            checkStockStream.send(new Object[] { "WSO20", 100L });
            checkStockStream.send(new Object[] { "WSO21", 100L });
        }
        long timeDiff = System.currentTimeMillis() - startTime;
        long startTime1 = System.currentTimeMillis();
        for (int i = 0; i < 10; i++) {
            stockStream1.send(new Object[] { "WSO2" + i, 55.6f, 100L });
        }
        for (int i = 0; i < 1000000; i++) {
            checkStockStream1.send(new Object[] { "WSO20", 100L });
            checkStockStream1.send(new Object[] { "WSO21", 100L });
        }
        long timeDiff1 = System.currentTimeMillis() - startTime1;
        AssertJUnit.assertEquals("Indexing is faster", true, timeDiff1 < timeDiff);
        AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    } finally {
        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 65 with Table

use of org.wso2.siddhi.core.table.Table 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)

Aggregations

Test (org.testng.annotations.Test)183 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)176 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)176 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)140 Event (org.wso2.siddhi.core.event.Event)119 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)102 ArrayList (java.util.ArrayList)47 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)23 HashMap (java.util.HashMap)22 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)20 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)19 Attribute (org.wso2.siddhi.query.api.definition.Attribute)19 Table (org.wso2.siddhi.core.table.Table)11 Expression (org.wso2.siddhi.query.api.expression.Expression)11 Variable (org.wso2.siddhi.query.api.expression.Variable)11 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)10 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)10 TableDefinition (org.wso2.siddhi.query.api.definition.TableDefinition)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)8