Search in sources :

Example 41 with Partition

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

the class SequencePartitionTestCase method testSequencePartitionQuery10.

@Test
public void testSequencePartitionQuery10() throws InterruptedException {
    log.info("Pattern -testSequence10 - OUT 1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
    String partitionStart = "partition with (volume of Stream1 , volume of Stream2) begin ";
    String query = "" + "@info(name = 'query1') " + "from every e1=Stream2[price>20]+, e2=Stream1[price>e1[0].price] " + "select e1[0].price as price1, e1[1].price as price2, e2.price as price3 " + "insert into OutputStream ;";
    String partitionEnd = "end";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + partitionStart + query + partitionEnd);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                if (event.isExpired()) {
                    removeEventCount++;
                } else {
                    inEventCount++;
                    switch(inEventCount) {
                        case 1:
                            AssertJUnit.assertArrayEquals(new Object[] { 55.6f, null, 57.6f }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(1, inEventCount);
                    }
                }
                eventArrived = true;
            }
        }
    });
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "WSO2", 59.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 55.6f, 100 });
    Thread.sleep(100);
    stream1.send(new Object[] { "WSO2", 57.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 55.6f, 120 });
    Thread.sleep(100);
    stream1.send(new Object[] { "WSO2", 57.6f, 150 });
    Thread.sleep(100);
    AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
    AssertJUnit.assertEquals("Event arrived", true, 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 42 with Partition

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

the class TablePartitionTestCase method testPartitionQuery2.

@Test
public void testPartitionQuery2() throws InterruptedException {
    log.info("Table Partition test 2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "define stream streamB (symbol string);" + "define table tableA (symbol string, price int);" + "partition with (symbol of streamA, symbol of streamB) " + "begin " + "   @info(name = 'query1') " + "   from streamA " + "   select symbol, price " + "   insert into tableA;  " + "" + "end ;" + "" + "@info(name = 'query2') " + "from streamB[(symbol==tableA.symbol) in tableA] " + "select symbol " + "insert into outputStream;  " + "";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                count.incrementAndGet();
            }
            eventArrived = true;
        }
    });
    InputHandler streamAInputHandler = siddhiAppRuntime.getInputHandler("streamA");
    InputHandler streamBInputHandler = siddhiAppRuntime.getInputHandler("streamB");
    siddhiAppRuntime.start();
    streamAInputHandler.send(new Object[] { "IBM", 700 });
    streamAInputHandler.send(new Object[] { "WSO2", 60 });
    streamAInputHandler.send(new Object[] { "WSO2", 60 });
    streamBInputHandler.send(new Object[] { "WSO2" });
    streamBInputHandler.send(new Object[] { "FB" });
    streamBInputHandler.send(new Object[] { "IBM" });
    SiddhiTestHelper.waitForEvents(100, 2, count, 60000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals(2, count.get());
    AssertJUnit.assertEquals(true, eventArrived);
}
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 43 with Partition

use of org.wso2.siddhi.query.api.execution.partition.Partition 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 44 with Partition

use of org.wso2.siddhi.query.api.execution.partition.Partition 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)

Example 45 with Partition

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

the class JoinPartitionTestCase method testJoinPartition7.

@Test
public void testJoinPartition7() throws InterruptedException {
    log.info("Join partition test7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int);  define stream " + "twitterStream (user string, tweet string, company string, volume int);" + "partition with (volume>=100 as 'large' or volume<100 as 'small' of cseEventStream, volume>=100 as " + "'large' or volume<100 as 'small' of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.user== twitterStream.user " + "select cseEventStream.symbol as symbol, cseEventStream.user as user,twitterStream.tweet, " + "cseEventStream.volume,twitterStream.company " + "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 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2", 200 });
    twitterStreamHandler.send(new Object[] { "User1", "World", "WSO2", 200 });
    cseEventStreamHandler.send(new Object[] { "IBM", "User1", 10 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2", 10 });
    twitterStreamHandler.send(new Object[] { "User1", "World", "IBM", 10 });
    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)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