Search in sources :

Example 96 with Event

use of org.wso2.carbon.apimgt.core.models.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.carbon.apimgt.core.models.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.carbon.apimgt.core.models.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.carbon.apimgt.core.models.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.carbon.apimgt.core.models.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)1159 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1147 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1143 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1121 Event (org.wso2.siddhi.core.event.Event)857 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)589 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 HashMap (java.util.HashMap)113 ArrayList (java.util.ArrayList)93 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)86 Event (org.wso2.carbon.identity.event.event.Event)82 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Query (org.wso2.siddhi.query.api.execution.query.Query)79 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)63 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)58 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)46 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)38 Map (java.util.Map)37 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)35