Search in sources :

Example 16 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery34.

@Test
public void testPartitionQuery34() throws InterruptedException {
    log.info("Partition test33");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest33') " + "define stream cseEventStream (atr1 string,  atr2 float, 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[700>atr5 OR atr8 >= atr3 OR atr6 >= atr2 OR atr4 " + ">= atr6 OR atr2 >= atr7 OR atr3 >= atr4 OR atr4 >= atr3 OR atr6 >= atr3 OR atr3" + ">= atr2 OR atr8 >= atr5 OR atr6 >= atr4 OR atr3 >= atr6 OR atr7 >= atr8 OR atr7 " + ">= atr4 OR atr6 >= atr5 OR atr11 >= atr3 OR atr8 >= atr2] select" + " atr1 as symbol, sum(atr2) as price" + " insert into " + "OutStockStream ;  end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75.6f, 100, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105 });
    inputHandler.send(new Object[] { "WSO2", 75.6f, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107 });
    inputHandler.send(new Object[] { "ORACLE", 75.6f, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, true, 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)

Example 17 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery21.

@Test
public void testPartitionQuery21() throws InterruptedException {
    log.info("Partition test21");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest20') " + "" + "" + "define stream cseEventStream (symbol string, price float,volume int); " + "" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "" + "@info(name = 'query')" + "from cseEventStreamOne " + "select symbol, price, volume " + "insert into cseEventStream;" + " " + "partition with (price>=100 as 'large' or price<100 as 'medium' or price<50 as 'small' of " + "cseEventStream) " + "   begin" + "   @info(name = 'query1') " + "   from cseEventStream " + "   select symbol, sum(price) as price " + "   insert into #OutStockStream1 ; " + " " + "   @info(name = 'query2') " + "   from #OutStockStream1 " + "   insert into #OutStockStream2 ;" + " " + "   @info(name = 'query3') " + "   from #OutStockStream2 " + "   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();
                eventArrived = true;
                if (count.get() == 1) {
                    AssertJUnit.assertEquals(25.0, event.getData()[1]);
                } else if (count.get() == 2) {
                    AssertJUnit.assertEquals(25.0, event.getData()[1]);
                } else if (count.get() == 3) {
                    AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]);
                } else if (count.get() == 4) {
                    AssertJUnit.assertTrue(event.getData()[1].equals(50.0) || event.getData()[1].equals(100.0));
                } else if (count.get() == 5) {
                    AssertJUnit.assertTrue(event.getData()[1].equals(50.0) || event.getData()[1].equals(100.0));
                } else if (count.get() == 6) {
                    AssertJUnit.assertEquals(50.0, event.getData()[1]);
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 25f, 100 });
    inputHandler.send(new Object[] { "WSO2", 7005.6f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 25f, 100 });
    SiddhiTestHelper.waitForEvents(100, 5, count, 60000);
    AssertJUnit.assertTrue(5 == 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 18 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class PatternPartitionTestCase method testPatternPartitionQuery21.

@Test
public void testPatternPartitionQuery21() throws InterruptedException {
    log.info("testPatternLogical1 - 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 e1=Stream1[price > 20] -> e2=Stream2[price > e1.price] or e3=Stream2['IBM' == symbol] " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "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.incrementAndGet();
                } else {
                    inEventCount.incrementAndGet();
                    AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "GOOG" }, event.getData());
                }
                eventArrived = true;
            }
        }
    });
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "WSO2", 55.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "GOOG", 59.6f, 200 });
    Thread.sleep(100);
    stream2.send(new Object[] { "GOOG", 59.6f, 100 });
    SiddhiTestHelper.waitForEvents(100, 1, inEventCount, 60000);
    AssertJUnit.assertEquals("Number of success events", 1, inEventCount.get());
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount.get());
    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 19 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class SequencePartitionTestCase method testSequencePartitionQuery9.

@Test
public void testSequencePartitionQuery9() throws InterruptedException {
    log.info("Pattern -testSequence9 - 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, 57.6f, null }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { 57.6f, null, 55.7f }, event.getData());
                            break;
                        case 3:
                            AssertJUnit.assertArrayEquals(new Object[] { 155.6f, 207.6f, null }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(3, 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", 155.6f, 200 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 55.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 57.6f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "IBM", 55.7f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "WSO2", 207.6f, 200 });
    Thread.sleep(100);
    AssertJUnit.assertEquals("Number of success events", 3, 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 20 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class SequencePartitionTestCase method testSequencePartitionQuery11.

@Test
public void testSequencePartitionQuery11() throws InterruptedException {
    log.info("Pattern -testSequence11 - 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=Stream1[price>20], " + "   e2=Stream1[((e2[last].price is null) and price>=e1.price) or ((not (e2[last].price is null)) and " + "price>=e2[last].price)]+, " + "   e3=Stream1[price<e2[last].price] " + "select e1.price as price1, e2[0].price as price2, e2[1].price as price3, e3.price as price4 " + "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[] { 29.6f, 35.6f, 57.6f, 47.6f }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { 129.6f, 135.6f, 157.6f, 147.6f }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(2, inEventCount);
                    }
                }
                eventArrived = true;
            }
        }
    });
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "WSO2", 29.6f, 100 });
    Thread.sleep(100);
    stream1.send(new Object[] { "WSO2", 35.6f, 100 });
    Thread.sleep(100);
    stream1.send(new Object[] { "WSO2", 57.6f, 100 });
    Thread.sleep(100);
    stream1.send(new Object[] { "IBM", 47.6f, 100 });
    Thread.sleep(100);
    stream1.send(new Object[] { "WSO2", 129.6f, 10 });
    Thread.sleep(100);
    stream1.send(new Object[] { "WSO2", 135.6f, 10 });
    Thread.sleep(100);
    stream1.send(new Object[] { "WSO2", 157.6f, 10 });
    Thread.sleep(100);
    stream1.send(new Object[] { "IBM", 147.6f, 10 });
    Thread.sleep(100);
    AssertJUnit.assertEquals("Number of success events", 2, 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)

Aggregations

Test (org.testng.annotations.Test)170 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)156 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)152 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)149 TestUtil (org.wso2.siddhi.core.TestUtil)76 Event (org.wso2.siddhi.core.event.Event)66 ArrayList (java.util.ArrayList)51 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)44 HashMap (java.util.HashMap)38 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)30 IOException (java.io.IOException)24 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)24 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)21 Map (java.util.Map)18 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)17 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)16 File (java.io.File)13 List (java.util.List)13 Response (feign.Response)11 Attribute (org.wso2.charon3.core.attributes.Attribute)10