Search in sources :

Example 26 with Remove

use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.

the class SequencePartitionTestCase method testSequencePartitionQuery8.

@Test
public void testSequencePartitionQuery8() throws InterruptedException {
    log.info("Pattern -testSequence8 - OUT 2");
    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=Stream2[price>e1.price] or e3=Stream2[symbol=='IBM'] " + "select e1.price as price1, e2.price as price2, e3.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, 55.0f }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { 155.6f, null, 95.0f }, event.getData());
                            break;
                        case 3:
                            AssertJUnit.assertArrayEquals(new Object[] { 55.0f, 57.6f, null }, event.getData());
                            break;
                        case 4:
                            AssertJUnit.assertArrayEquals(new Object[] { 95.0f, 207.6f, null }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(4, inEventCount);
                    }
                }
                eventArrived = true;
            }
        }
    });
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();
    stream2.send(new Object[] { "WSO2", 59.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 259.6f, 200 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 55.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 155.6f, 200 });
    Thread.sleep(100);
    stream2.send(new Object[] { "IBM", 55.0f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "IBM", 95.0f, 200 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 57.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 207.6f, 200 });
    Thread.sleep(100);
    AssertJUnit.assertEquals("Number of success events", 4, 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 27 with Remove

use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.

the class SequencePartitionTestCase method testSequencePartitionQuery12.

@Test
public void testSequencePartitionQuery12() throws InterruptedException {
    log.info("Pattern -testSequence12 - OUT 1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume int,name String); " + "define stream TwitterStream (symbol string, count int,user String); ";
    String partitionStart = "partition with (name of StockStream , user of TwitterStream) begin ";
    String query = "" + "@info(name = 'query1') " + "from every e1=StockStream[ price >= 50 and volume > 100 ], e2=TwitterStream[count > 10] " + "select e1.price as price, e1.symbol as symbol, e2.count as count " + "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[] { 76.6f, "IBM", 20 }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(1, inEventCount);
                    }
                }
                eventArrived = true;
            }
        }
    });
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler twitterStream = siddhiAppRuntime.getInputHandler("TwitterStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "IBM", 75.6f, 105, "user" });
    stockStream.send(new Object[] { "GOOG", 51f, 101, "user" });
    stockStream.send(new Object[] { "IBM", 76.6f, 111, "user" });
    stockStream.send(new Object[] { "IBM", 76.6f, 111, "user2" });
    Thread.sleep(100);
    twitterStream.send(new Object[] { "IBM", 20, "user" });
    stockStream.send(new Object[] { "WSO2", 45.6f, 100, "user" });
    Thread.sleep(100);
    twitterStream.send(new Object[] { "GOOG", 20, "user" });
    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 28 with Remove

use of org.wso2.carbon.humantask.core.engine.commands.Remove 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 29 with Remove

use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.

the class PlaybackTestCase method playbackTest2.

@Test
public void playbackTest2() throws InterruptedException {
    log.info("Playback Test 2: Playback with heartbeat disabled in query with start time enabled time batch " + "window");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "@app:playback " + "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(2 sec , 0) " + "select symbol, sum(price) as sumPrice, volume " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEventCount == 0) {
                AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
            }
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            } else if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    // Start sending events in the beginning of a cycle
    long timestamp = 0;
    inputHandler.send(timestamp, new Object[] { "IBM", 700f, 0 });
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 1 });
    timestamp += 8500;
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(timestamp, new Object[] { "II", 60.5f, 1 });
    timestamp += 13000;
    inputHandler.send(timestamp, new Object[] { "TT", 60.5f, 1 });
    inputHandler.send(timestamp, new Object[] { "YY", 60.5f, 1 });
    timestamp += 5000;
    inputHandler.send(timestamp, new Object[] { "ZZ", 0.0f, 0 });
    Thread.sleep(100);
    AssertJUnit.assertEquals(3, inEventCount);
    AssertJUnit.assertEquals(0, removeEventCount);
    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 30 with Remove

use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.

the class PlaybackTestCase method playbackTest3.

@Test
public void playbackTest3() throws InterruptedException {
    log.info("Playback Test 3: Playback with heartbeat enabled");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "@app:playback(idle.time = '100 millisecond', increment = '2 sec') " + "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(2 sec , 0) " + "select symbol, sum(price) as sumPrice, volume " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEventCount == 0) {
                AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
            }
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            } else if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    // Start sending events in the beginning of a cycle
    long timestamp = 0;
    inputHandler.send(timestamp, new Object[] { "IBM", 700f, 0 });
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 1 });
    timestamp += 8500;
    inputHandler.send(timestamp, new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(timestamp, new Object[] { "II", 60.5f, 1 });
    timestamp += 13000;
    inputHandler.send(timestamp, new Object[] { "TT", 60.5f, 1 });
    inputHandler.send(timestamp, new Object[] { "YY", 60.5f, 1 });
    // Anything more than 100 is enough. Used 200 to be on safe side
    Thread.sleep(200);
    AssertJUnit.assertEquals(3, inEventCount);
    AssertJUnit.assertEquals(0, removeEventCount);
    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

Test (org.testng.annotations.Test)624 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)617 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)617 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)617 Event (org.wso2.siddhi.core.event.Event)319 TestUtil (org.wso2.siddhi.core.TestUtil)298 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)254 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)65 ArrayList (java.util.ArrayList)42 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)15 HashMap (java.util.HashMap)12 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)12 Map (java.util.Map)11 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)11 List (java.util.List)9 API (org.wso2.carbon.apimgt.core.models.API)8 Attribute (org.wso2.charon3.core.attributes.Attribute)8 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)8 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)8 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)8