Search in sources :

Example 51 with Query

use of org.wso2.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class MinimumFunctionExtensionTestCase method testMinFunctionExtensionException6.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testMinFunctionExtensionException6() throws InterruptedException {
    log.info("MinimumFunctionExecutor TestCase 6");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 object,price2 double, price3 double);";
    String query = ("@info(name = 'query1') from inputStream " + "select minimum(price1, price2, price3) as min " + "insert into outputStream;");
    siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 52 with Query

use of org.wso2.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class JoinTestCase method joinTest3.

@Test
public void joinTest3() throws InterruptedException {
    log.info("Join test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); ";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(500 milliseconds) as a " + "join cseEventStream#window.time(500 milliseconds) as b " + "on a.symbol== b.symbol " + "select a.symbol as symbol, a.price as priceA, b.price as priceB " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                if (inEvents != null) {
                    inEventCount.addAndGet(inEvents.length);
                }
                if (removeEvents != null) {
                    removeEventCount.getAndAdd(removeEvents.length);
                }
                eventArrived = true;
            }
        });
        InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        siddhiAppRuntime.start();
        cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
        cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
        SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
        SiddhiTestHelper.waitForEvents(100, 2, removeEventCount, 60000);
        AssertJUnit.assertEquals(2, inEventCount.get());
        AssertJUnit.assertEquals(2, removeEventCount.get());
        AssertJUnit.assertTrue(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 53 with Query

use of org.wso2.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class JoinTestCase method joinTest14.

@Test
public void joinTest14() throws InterruptedException {
    log.info("Join test14");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
    String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "on order.custid == dow_items.custid \n" + "select  dow_items.item\n" + "having order.items == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
        InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                eventArrived = true;
            }
        });
        siddhiAppRuntime.start();
        Thread.sleep(100);
        itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
        orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
        Thread.sleep(100);
        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 54 with Query

use of org.wso2.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class JoinTestCase method joinTest17.

@Test
public void joinTest17() throws InterruptedException {
    log.info("Join test17");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
    String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "select  dow_items.custid\n" + "having order.items == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
        InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                eventArrived = true;
            }
        });
        siddhiAppRuntime.start();
        Thread.sleep(100);
        itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
        orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
        Thread.sleep(100);
        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 55 with Query

use of org.wso2.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class JoinTestCase method joinTest9.

@Test
public void joinTest9() throws InterruptedException {
    log.info("Join test9");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream join twitterStream " + "select count() as events, symbol " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                eventArrived = true;
            }
        });
        InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
        siddhiAppRuntime.start();
        twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
        cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
        cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
        cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
        Thread.sleep(500);
        AssertJUnit.assertFalse(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)

Aggregations

Test (org.testng.annotations.Test)1150 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1093 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1065 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1006 Event (org.wso2.siddhi.core.event.Event)673 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)528 TestUtil (org.wso2.siddhi.core.TestUtil)300 Query (org.wso2.siddhi.query.api.execution.query.Query)145 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)121 PreparedStatement (java.sql.PreparedStatement)97 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)83 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)82 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)78 SQLException (java.sql.SQLException)73 ArrayList (java.util.ArrayList)73 Connection (java.sql.Connection)69 ResultSet (java.sql.ResultSet)50 HashMap (java.util.HashMap)40 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)22 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)20