Search in sources :

Example 56 with Event

use of org.wso2.siddhi.core.event.Event in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery16.

@Test
public void testPartitionQuery16() throws InterruptedException {
    log.info("partition test16");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest16') " + "define stream streamA (symbol string, price int);" + "partition with (symbol of streamA) begin @info(name = 'query1') from streamA select symbol,price " + "insert into StockQuote ;" + "@info(name = 'query2') from streamA select symbol,price insert into StockQuote ; end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("StockQuote", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700 });
    inputHandler.send(new Object[] { "WSO2", 60 });
    inputHandler.send(new Object[] { "WSO2", 60 });
    SiddhiTestHelper.waitForEvents(100, 6, count, 60000);
    AssertJUnit.assertEquals(6, 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 57 with Event

use of org.wso2.siddhi.core.event.Event in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery37.

@Test
public void testPartitionQuery37() throws InterruptedException {
    log.info("Partition test36");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest36') " + "define stream cseEventStream (atr1 string,  atr2 object, 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 AND atr10] select 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);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75.6, 100, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105 });
    inputHandler.send(new Object[] { "WSO2", 75.6, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106 });
    inputHandler.send(new Object[] { "IBM", 75.6, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107 });
    inputHandler.send(new Object[] { "ORACLE", 75.6, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, false, 108 });
    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)

Example 58 with Event

use of org.wso2.siddhi.core.event.Event in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery.

@Test
public void testPartitionQuery() throws InterruptedException {
    log.info("Partition test");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "partition with (symbol of streamA) " + "begin " + "@info(name = 'query1') " + "from streamA select symbol,price insert into StockQuote ;  " + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    StreamCallback streamCallback = new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            eventArrived = true;
        }
    };
    siddhiAppRuntime.addCallback("StockQuote", streamCallback);
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700 });
    inputHandler.send(new Object[] { "WSO2", 60 });
    inputHandler.send(new Object[] { "WSO2", 60 });
    SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(3, count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 59 with Event

use of org.wso2.siddhi.core.event.Event 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 60 with Event

use of org.wso2.siddhi.core.event.Event in project siddhi by wso2.

the class PartitionTestCase2 method testSubtractExpressionExecutorFloatCase.

@Test
public void testSubtractExpressionExecutorFloatCase() throws InterruptedException {
    log.info("Partition testSubtractExpressionExecutorFloatCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('testSubtractExpressionExecutorFloatCase') " + "define stream cseEventStream (atr1 string,  atr2 string, atr3 int, atr4 float, " + "atr5 long,  atr6 long,  atr7 float,  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(89.57f, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 2) {
                    AssertJUnit.assertEquals(85.79f, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 3) {
                    AssertJUnit.assertEquals(56.77f, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 4) {
                    AssertJUnit.assertEquals(13.660004f, event.getData(0));
                    eventArrived = true;
                }
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", null, 100, 101.0f, 500L, 200L, 11.43f, 75.7f, false, true, 105 });
    inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0f, 501L, 201L, 15.21f, 76.7f, false, true, 106 });
    inputHandler.send(new Object[] { "IBM", null, 100, 102.0f, 502L, 202L, 45.23f, 77.7f, false, true, 107 });
    inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0f, 502L, 202L, 87.34f, 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)1150 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1146 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1145 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1119 Event (org.wso2.siddhi.core.event.Event)855 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)587 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)218 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)86 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)79 Query (org.wso2.siddhi.query.api.execution.query.Query)79 ArrayList (java.util.ArrayList)68 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)63 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)38 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)35 GroupedComplexEvent (org.wso2.siddhi.core.event.GroupedComplexEvent)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 HashMap (java.util.HashMap)14 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13