Search in sources :

Example 76 with Partition

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

the class JoinPartitionTestCase method testJoinPartition4.

@Test
public void testJoinPartition4() throws InterruptedException {
    log.info("Join partition test4");
    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 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");
    InputHandler outputStreamStreamHandler = siddhiAppRuntime.getInputHandler("outputStream");
    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", "User1", 100 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "IBM" });
    twitterStreamHandler.send(new Object[] { "User1", "World", "IBM" });
    outputStreamStreamHandler.send(new Object[] { "GOOG", "new_user_1" });
    outputStreamStreamHandler.send(new Object[] { "GOOG", "new_user_2" });
    SiddhiTestHelper.waitForEvents(100, 10, count, 6000);
    AssertJUnit.assertEquals(10, 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 77 with Partition

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

the class JoinPartitionTestCase method testJoinPartition6.

@Test
public void testJoinPartition6() throws InterruptedException {
    log.info("Join partition test6");
    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 = 'query2') from cseEventStream select symbol, user, sum(volume) as volume insert all " + "events into #cseEventStream;" + "@info(name = 'query1') from #cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec)" + " " + "on twitterStream.company== #cseEventStream.symbol " + "select #cseEventStream.user as user,twitterStream.tweet as tweet, twitterStream.company, " + "#cseEventStream.volume ,  #cseEventStream.symbol " + "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", 200 });
    cseEventStreamHandler.send(new Object[] { "IBM", "User2", 500 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "IBM" });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
    SiddhiTestHelper.waitForEvents(100, 4, count, 6000);
    AssertJUnit.assertEquals(4, 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)

Example 78 with Partition

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

the class JoinPartitionTestCase method testJoinPartition2.

@Test
public void testJoinPartition2() throws InterruptedException {
    log.info("Join partition test2");
    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 ;" + "" + "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[] { "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(1000, 8, count, 12000);
    AssertJUnit.assertEquals(8, 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 79 with Partition

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

the class JoinPartitionTestCase method testJoinPartition5.

@Test
public void testJoinPartition5() throws InterruptedException {
    log.info("Join partition test5");
    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 = 'query2') from cseEventStream select symbol, user, sum(volume) as volume insert all " + "events into #cseInnerStream;" + "@info(name = 'query1') from #cseInnerStream#window.time(1 sec) join twitterStream#window.time(1 sec)" + " " + "on twitterStream.company== #cseInnerStream.symbol " + "select #cseInnerStream.user as user,twitterStream.tweet as tweet, twitterStream.company, " + "#cseInnerStream.volume ,  #cseInnerStream.symbol " + "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", 200 });
    cseEventStreamHandler.send(new Object[] { "IBM", "User2", 500 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "IBM" });
    twitterStreamHandler.send(new Object[] { "User3", "Hello World", "GOOG" });
    SiddhiTestHelper.waitForEvents(100, 4, count, 6000);
    AssertJUnit.assertEquals(4, 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)

Example 80 with Partition

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

the class PartitionTestCase1 method testModExpressionExecutorDoubleCase.

@Test
public void testModExpressionExecutorDoubleCase() throws InterruptedException {
    log.info("Partition testModExpressionExecutorDoubleCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('testModExpressionExecutorDoubleCase') " + "define stream cseEventStream (atr1 string,  atr2 string, atr3 int, atr4 double, " + "atr5 long,  atr6 long,  atr7 double,  atr8 float , atr9 bool, atr10 bool,  atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[atr5 < 700 ] select atr4%atr7 as dividedVal, atr5 as threshold,  atr1 as" + " symbol, " + "cast(atr2,  'double') as priceInDouble,  sum(atr7) as summedValue insert " + "into OutStockStream ; end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                count.incrementAndGet();
                if (count.get() == 1) {
                    AssertJUnit.assertEquals(9.560000000000002, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 2) {
                    AssertJUnit.assertEquals(9.739999999999995, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 3) {
                    AssertJUnit.assertEquals(11.540000000000006, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 4) {
                    AssertJUnit.assertEquals(13.659999999999997, event.getData(0));
                    eventArrived = true;
                }
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", null, 100, 101.0, 500L, 200L, 11.43, 75.7f, false, true, 105 });
    inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0, 501L, 201L, 15.21, 76.7f, false, true, 106 });
    inputHandler.send(new Object[] { "IBM", null, 100, 102.0, 502L, 202L, 45.23, 77.7f, false, true, 107 });
    inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0, 502L, 202L, 87.34, 77.7f, false, false, 108 });
    SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
    AssertJUnit.assertEquals(4, 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)

Aggregations

Test (org.testng.annotations.Test)132 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)131 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)131 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)130 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)127 Event (org.wso2.siddhi.core.event.Event)125 Partition (org.wso2.siddhi.query.api.execution.partition.Partition)13 Query (org.wso2.siddhi.query.api.execution.query.Query)11 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)7 ArrayList (java.util.ArrayList)5 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)4 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)4 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)4 ExecutionElement (org.wso2.siddhi.query.api.execution.ExecutionElement)4 QueryRuntime (org.wso2.siddhi.core.query.QueryRuntime)3 Element (org.wso2.siddhi.query.api.annotation.Element)3 List (java.util.List)2 TestUtil (org.wso2.siddhi.core.TestUtil)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 PartitionRuntime (org.wso2.siddhi.core.partition.PartitionRuntime)2