Search in sources :

Example 96 with Partition

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

the class PartitionTestCase1 method testPartitionQuery41.

@Test
public void testPartitionQuery41() throws InterruptedException {
    log.info("Partition test");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest') " + "define stream streamA (symbol string,  price int);" + "" + "from streamA#window.lengthBatch(3) " + "insert into streamB;" + "" + "partition with (symbol of streamB) " + "begin " + "@info(name = 'query1') " + "from streamB  " + "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 Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    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) 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 97 with Partition

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

the class PartitionTestCase1 method testPartitionQuery36.

@Test
public void testPartitionQuery36() throws InterruptedException {
    log.info("Partition test35");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest35') " + "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 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, 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 98 with Partition

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

the class PartitionTestCase1 method testPartitionQuery2.

@Test
public void testPartitionQuery2() throws InterruptedException {
    log.info("Partition test2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest2') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream StockStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream , symbol of StockStream1) begin @info(name = 'query1') " + "from cseEventStream[700>price] select symbol,sum(price) as price,volume 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 });
    inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
    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 99 with Partition

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

the class PartitionTestCase1 method testPartitionQuery27.

@Test
public void testPartitionQuery27() throws InterruptedException {
    log.info("Partition test");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest')" + "@async(buffer.size='2') " + "define stream streamA (symbol string,  price int); " + "@async(buffer.size='2') " + "define stream streamB (symbol string,  price int); " + "partition with (symbol of streamA,  symbol of streamB) " + "begin " + "@info(name = 'query1') " + "from streamA  " + "select symbol, price insert into StockQuote ;  " + "@info(name = 'query2') " + "from streamB  " + "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 inputHandlerA = siddhiAppRuntime.getInputHandler("streamA");
    InputHandler inputHandlerB = siddhiAppRuntime.getInputHandler("streamB");
    siddhiAppRuntime.start();
    Thread.sleep(500);
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 701 }));
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 61 }));
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 62 }));
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 702 }));
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 63 }));
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 64 }));
    SiddhiTestHelper.waitForEvents(500, 6, count, 60000);
    AssertJUnit.assertTrue(eventArrived);
    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 100 with Partition

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

the class PartitionTestCase2 method testMultiplyExpressionExecutorDoubleCase.

@Test
public void testMultiplyExpressionExecutorDoubleCase() throws InterruptedException {
    log.info("Partition testMultiplyExpressionExecutorDoubleCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('testMultiplyExpressionExecutorDoubleCase') " + "define stream cseEventStream (atr1 string,  atr2 string, 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 ] 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(1154.43, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 2) {
                    AssertJUnit.assertEquals(1536.21, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 3) {
                    AssertJUnit.assertEquals(4613.46, event.getData(0));
                    eventArrived = true;
                }
                if (count.get() == 4) {
                    AssertJUnit.assertEquals(8821.34, event.getData(0));
                    eventArrived = true;
                }
            }
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", null, 100, 101.0, 500L, 200L, 11.43, 75.7f, false, true, 105 });
    inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0, 501L, 201L, 15.21, 76.7f, false, true, 106 });
    inputHandler.send(new Object[] { "IBM", null, 100, 102.0, 502L, 202L, 45.23, 77.7f, false, true, 107 });
    inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0, 502L, 202L, 87.34, 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)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