Search in sources :

Example 21 with And

use of org.wso2.siddhi.query.api.expression.condition.And 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)

Example 22 with And

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

the class SequencePartitionTestCase method testSequencePartitionQuery14.

@Test
public void testSequencePartitionQuery14() throws InterruptedException {
    log.info("Pattern -testSequence14 - OUT 3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream1 (symbol string, price float, volume int, quantity int); " + "define stream StockStream2 (symbol string, price float, volume int, quantity int); ";
    String partitionStart = "partition with (quantity of StockStream1 , quantity of StockStream2) begin ";
    String query = "" + "@info(name = 'query1') " + "from every e1=StockStream1[ price >= 50 and volume > 100 ], e2=StockStream2[price <= 40]*, " + "e3=StockStream2[volume <= 70] " + "select e3.symbol as symbol1, e2[0].symbol as symbol2, e3.volume as volume " + "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[] { "WSO2", "GOOG", 65 }, event.getData());
                            break;
                        case 2:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "DDD", 60 }, event.getData());
                            break;
                        case 3:
                            AssertJUnit.assertArrayEquals(new Object[] { "DOX", null, 25 }, event.getData());
                            break;
                        case 4:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "GOOG", 65 }, event.getData());
                            break;
                        case 5:
                            AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "DDD", 60 }, event.getData());
                            break;
                        case 6:
                            AssertJUnit.assertArrayEquals(new Object[] { "DOX", null, 25 }, event.getData());
                            break;
                        default:
                            AssertJUnit.assertSame(6, inEventCount);
                    }
                }
                eventArrived = true;
            }
        }
    });
    InputHandler stockStream1 = siddhiAppRuntime.getInputHandler("StockStream1");
    InputHandler stockStream2 = siddhiAppRuntime.getInputHandler("StockStream2");
    siddhiAppRuntime.start();
    stockStream1.send(new Object[] { "IBM", 75.6f, 105, 2 });
    Thread.sleep(100);
    stockStream2.send(new Object[] { "GOOG", 21f, 81, 2 });
    stockStream2.send(new Object[] { "WSO2", 176.6f, 65, 2 });
    stockStream1.send(new Object[] { "BIRT", 21f, 81, 2 });
    stockStream1.send(new Object[] { "AMBA", 126.6f, 165, 2 });
    stockStream2.send(new Object[] { "DDD", 23f, 181, 2 });
    stockStream2.send(new Object[] { "BIRT", 21f, 86, 2 });
    stockStream2.send(new Object[] { "BIRT", 21f, 82, 2 });
    stockStream2.send(new Object[] { "WSO2", 176.6f, 60, 2 });
    stockStream1.send(new Object[] { "AMBA", 126.6f, 165, 2 });
    stockStream2.send(new Object[] { "DOX", 16.2f, 25, 2 });
    Thread.sleep(100);
    stockStream1.send(new Object[] { "IBM", 75.6f, 105, 22 });
    Thread.sleep(100);
    stockStream2.send(new Object[] { "GOOG", 21f, 81, 22 });
    stockStream2.send(new Object[] { "WSO2", 176.6f, 65, 22 });
    stockStream1.send(new Object[] { "BIRT", 21f, 81, 22 });
    stockStream1.send(new Object[] { "AMBA", 126.6f, 165, 22 });
    stockStream2.send(new Object[] { "DDD", 23f, 181, 22 });
    stockStream2.send(new Object[] { "BIRT", 21f, 86, 22 });
    stockStream2.send(new Object[] { "BIRT", 21f, 82, 22 });
    stockStream2.send(new Object[] { "WSO2", 176.6f, 60, 22 });
    stockStream1.send(new Object[] { "AMBA", 126.6f, 165, 22 });
    stockStream2.send(new Object[] { "DOX", 16.2f, 25, 22 });
    Thread.sleep(100);
    AssertJUnit.assertEquals("Number of success events", 6, 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 23 with And

use of org.wso2.siddhi.query.api.expression.condition.And 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 24 with And

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

the class PartitionTestCase1 method testPartitionQuery30.

@Test
public void testPartitionQuery30() throws InterruptedException {
    log.info("Partition test26");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest26') " + "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 AND atr5 != atr6 AND atr2 != atr3 AND atr6 " + "!= atr3 AND atr2 != atr5 AND atr4 != atr6 AND atr3 != atr4 AND atr4 != atr7 AND atr8 " + "!= atr2 AND atr4 != atr8 AND atr6 != atr8 AND atr3 != atr2 AND atr3 != atr5 AND atr9 " + "!= atr10 AND atr3 != atr11] 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 25 with And

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

the class PartitionTestCase1 method testPartitionQuery28.

@Test
public void testPartitionQuery28() throws InterruptedException {
    log.info("Partition test24");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest24') " + "define stream cseEventStream (symbol string,  price float, volume int, threshold double);" + "partition with (symbol of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[700>price AND threshold != volume] select symbol, sum(price) as price, " + "volume , threshold" + " 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, 100.0 });
    inputHandler.send(new Object[] { "WSO2", 75.6f, 100, 52.0 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100, 50.0 });
    inputHandler.send(new Object[] { "ORACLE", 75.6f, 100, 200.0 });
    SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
    AssertJUnit.assertEquals(3, 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)409 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)337 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)336 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)327 TestUtil (org.wso2.siddhi.core.TestUtil)204 Event (org.wso2.siddhi.core.event.Event)119 ArrayList (java.util.ArrayList)110 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)86 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)77 HashMap (java.util.HashMap)61 PreparedStatement (java.sql.PreparedStatement)55 SQLException (java.sql.SQLException)51 IOException (java.io.IOException)45 Connection (java.sql.Connection)45 ActivityInterface (org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)44 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)43 API (org.wso2.carbon.apimgt.core.models.API)39 ResultSet (java.sql.ResultSet)35 Map (java.util.Map)33 CharonException (org.wso2.charon3.core.exceptions.CharonException)33