Search in sources :

Example 41 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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 42 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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 43 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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)

Example 44 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class JoinPartitionTestCase method testJoinPartition8.

@Test
public void testJoinPartition8() throws InterruptedException {
    log.info("Join partition test8");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int);  define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.volume " + "insert all events into outputStream ;" + "" + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
    siddhiAppRuntime.start();
    cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User2", "Hellno World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User3", "Hellno World", "WSO2" });
    SiddhiTestHelper.waitForEvents(100, 6, count, 6000);
    AssertJUnit.assertEquals(6, count.get());
    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) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 45 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.

the class JoinPartitionTestCase method testJoinPartition3.

@Test
public void testJoinPartition3() throws InterruptedException {
    log.info("Join partition test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int);  define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream, user of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, cseEventStream.user as user,twitterStream.tweet, " + "cseEventStream.volume " + "insert all events into #outputStream ;" + "@info(name = 'query2') from #outputStream select symbol,user insert all events into outStream;" + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
    siddhiAppRuntime.start();
    cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User1", "World", "WSO2" });
    cseEventStreamHandler.send(new Object[] { "IBM", "User2", 100 });
    twitterStreamHandler.send(new Object[] { "User2", "Hello World", "IBM" });
    twitterStreamHandler.send(new Object[] { "User2", "World", "IBM" });
    SiddhiTestHelper.waitForEvents(100, 8, count, 6000);
    AssertJUnit.assertEquals(8, count.get());
    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) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)845 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)841 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)818 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)777 Event (org.wso2.siddhi.core.event.Event)473 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)377 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)100 Query (org.wso2.siddhi.query.api.execution.query.Query)80 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)67 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)65 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 IOException (java.io.IOException)14 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)11 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)11 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)10 Response (javax.ws.rs.core.Response)9 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)8 ObjectOutputStream (java.io.ObjectOutputStream)7 OutputStream (java.io.OutputStream)6