Search in sources :

Example 56 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler 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 57 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler 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)

Example 58 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class JoinTestCase method joinTest20.

@Test
public void joinTest20() throws InterruptedException {
    log.info("Join test20");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream dataIn (id int, data string); " + "define stream countIn (id int); " + "define stream deleteIn (id int); " + "define table dataTable (id int, data string); ";
    String query = "" + "from dataIn\n" + "insert into dataTable;\n" + "" + "from deleteIn \n" + "delete dataTable\n" + "    on dataTable.id == id;\n" + "" + "@info(name = 'query1') " + "from countIn as c left outer join dataTable as d\n" + "on d.data == 'abc'\n" + "select count() as count\n" + "insert into countOut; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        InputHandler dataIn = siddhiAppRuntime.getInputHandler("dataIn");
        InputHandler countIn = siddhiAppRuntime.getInputHandler("countIn");
        InputHandler deleteIn = siddhiAppRuntime.getInputHandler("deleteIn");
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                inEventCount.incrementAndGet();
                if (inEventCount.get() == 1) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    AssertJUnit.assertTrue((Long) inEvents[0].getData(0) == 3L);
                } else {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    AssertJUnit.assertTrue((Long) inEvents[0].getData(0) == 2L);
                }
            }
        });
        siddhiAppRuntime.start();
        Thread.sleep(100);
        dataIn.send(new Object[] { 1, "abc" });
        dataIn.send(new Object[] { 2, "abc" });
        dataIn.send(new Object[] { 3, "abc" });
        countIn.send(new Object[] { 1 });
        deleteIn.send(new Object[] { 1 });
        countIn.send(new Object[] { 1 });
    } 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 59 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class JoinTestCase method joinTest16.

@Test
public void joinTest16() throws InterruptedException {
    log.info("Join test16");
    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  order.custid\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)

Example 60 with InputHandler

use of org.wso2.siddhi.core.stream.input.InputHandler in project siddhi by wso2.

the class OuterJoinTestCase method joinTest1.

@Test
public void joinTest1() throws InterruptedException {
    log.info("Outer Join test1");
    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#window.length(3) full outer join twitterStream#window.length(1) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            for (Event inEvent : inEvents) {
                inEventCount++;
                if (inEventCount == 1) {
                    AssertJUnit.assertEquals("WSO2", inEvent.getData(0));
                    AssertJUnit.assertEquals(null, inEvent.getData(1));
                    AssertJUnit.assertEquals(55.6f, inEvent.getData(2));
                }
                if (inEventCount == 2) {
                    AssertJUnit.assertEquals("WSO2", inEvent.getData(0));
                    AssertJUnit.assertEquals("Hello World", inEvent.getData(1));
                    AssertJUnit.assertEquals(55.6f, inEvent.getData(2));
                }
                if (inEventCount == 3) {
                    AssertJUnit.assertEquals("IBM", inEvent.getData(0));
                    AssertJUnit.assertEquals(null, inEvent.getData(1));
                    AssertJUnit.assertEquals(75.6f, inEvent.getData(2));
                }
                if (inEventCount == 4) {
                    AssertJUnit.assertEquals("WSO2", inEvent.getData(0));
                    AssertJUnit.assertEquals("Hello World", inEvent.getData(1));
                    AssertJUnit.assertEquals(57.6f, inEvent.getData(2));
                }
            }
            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 });
    Thread.sleep(500);
    AssertJUnit.assertEquals(4, inEventCount);
    AssertJUnit.assertTrue(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

InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1153 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1152 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1149 Test (org.testng.annotations.Test)1136 Event (org.wso2.siddhi.core.event.Event)798 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)585 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)201 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)80 Query (org.wso2.siddhi.query.api.execution.query.Query)79 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)77 ArrayList (java.util.ArrayList)25 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)13 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)13 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)13 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)13 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6