Search in sources :

Example 96 with Event

use of org.wso2.siddhi.core.event.Event 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 97 with Event

use of org.wso2.siddhi.core.event.Event 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 98 with Event

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

Example 99 with Event

use of org.wso2.siddhi.core.event.Event in project siddhi by wso2.

the class JoinTestCase method joinTest10.

@Test
public void joinTest10() throws InterruptedException {
    log.info("Join test10");
    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#window.length(1) " + "select count() as events, symbol " + "insert 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.getAndAdd(inEvents.length);
                }
                if (removeEvents != null) {
                    removeEventCount.getAndAdd(removeEvents.length);
                }
                eventArrived = true;
            }
        });
        InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
        siddhiAppRuntime.start();
        cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
        twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
        cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
        cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
        SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
        AssertJUnit.assertEquals("inEventCount", 2, inEventCount.get());
        AssertJUnit.assertEquals("removeEventCount", 0, 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 100 with Event

use of org.wso2.siddhi.core.event.Event in project siddhi by wso2.

the class JoinTestCase method joinTest15.

@Test
public void joinTest15() throws InterruptedException {
    log.info("Join test15");
    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 dow_items.item == \"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)

Aggregations

Test (org.testng.annotations.Test)1150 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1146 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1145 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1119 Event (org.wso2.siddhi.core.event.Event)855 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)587 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)86 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Query (org.wso2.siddhi.query.api.execution.query.Query)79 ArrayList (java.util.ArrayList)68 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)63 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)38 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)35 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 HashMap (java.util.HashMap)14 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13