Search in sources :

Example 86 with Partition

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

the class PartitionTestCase1 method testPartitionQuery25.

@Test
public void testPartitionQuery25() 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[] { "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) 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 87 with Partition

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

the class PartitionTestCase1 method testPartitionQuery10.

@Test
public void testPartitionQuery10() throws InterruptedException {
    log.info("Partition test10");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest10') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream select symbol,avg(price) as avgPrice,volume 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(75.0, event.getData()[1]);
                } else if (count.get() == 2) {
                    AssertJUnit.assertEquals(705.0, event.getData()[1]);
                } else if (count.get() == 3) {
                    AssertJUnit.assertEquals(55.0, event.getData()[1]);
                } else if (count.get() == 4) {
                    AssertJUnit.assertEquals(50.0, event.getData()[1]);
                }
                eventArrived = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75f, 100 });
    inputHandler.send(new Object[] { "WSO2", 705f, 100 });
    inputHandler.send(new Object[] { "IBM", 35f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 50.0f, 100 });
    SiddhiTestHelper.waitForEvents(200, 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 88 with Partition

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

the class PartitionTestCase1 method testPartitionQuery11.

@Test
public void testPartitionQuery11() throws InterruptedException {
    log.info("Partition test11");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest11') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream select count(symbol) as entries 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(1L, event.getData()[0]);
                } else if (count.get() == 2) {
                    AssertJUnit.assertEquals(1L, event.getData()[0]);
                } else if (count.get() == 3) {
                    AssertJUnit.assertEquals(2L, event.getData()[0]);
                } else if (count.get() == 4) {
                    AssertJUnit.assertEquals(1L, event.getData()[0]);
                }
                eventArrived = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75f, 100 });
    inputHandler.send(new Object[] { "WSO2", 705f, 100 });
    inputHandler.send(new Object[] { "IBM", 35f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 50.0f, 100 });
    SiddhiTestHelper.waitForEvents(200, 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 89 with Partition

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

the class PartitionTestCase1 method testPartitionQuery38.

@Test
public void testPartitionQuery38() throws InterruptedException {
    log.info("Partition test");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest') " + "define stream streamA (symbol string,  price int); " + "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 ;  " + "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);
    SiddhiAppRuntime siddhiAppRuntime2 = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    StreamCallback streamCallback2 = 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;
        }
    };
    siddhiAppRuntime2.addCallback("StockQuote", streamCallback2);
    InputHandler inputHandlerA = siddhiAppRuntime.getInputHandler("streamA");
    InputHandler inputHandlerB = siddhiAppRuntime2.getInputHandler("streamA");
    siddhiAppRuntime.start();
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    byte[] snapshot = siddhiAppRuntime.snapshot();
    siddhiAppRuntime.shutdown();
    Thread.sleep(1000);
    try {
        siddhiAppRuntime2.restore(snapshot);
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    siddhiAppRuntime2.start();
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    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) CannotRestoreSiddhiAppStateException(org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 90 with Partition

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

the class PartitionTestCase1 method testPartitionQuery15.

@Test
public void testPartitionQuery15() throws InterruptedException {
    log.info("Partition test15");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest15') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "define stream StockStream (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream) begin @info(name = 'query') from cseEventStream select " + "symbol,price as price,volume insert into #StockStream ;" + "@info(name = 'query1') from #StockStream select symbol,price,volume insert into OutStockStream ;" + "@info(name = 'query2') from #StockStream select symbol,price,volume insert into StockStream ; end ;" + "partition with (symbol of cseEventStream1) begin @info(name = 'query3') from cseEventStream1 " + "select symbol,price+5 as price,volume insert into #StockStream ;" + "@info(name = 'query4') from #StockStream select symbol,price,volume insert into OutStockStream ; " + "end ;" + "@info(name = 'query5') from StockStream select symbol,price+15  as price,volume group by symbol " + "insert into OutStockStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("StockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            stockStreamEventCount = stockStreamEventCount + events.length;
        }
    });
    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");
    InputHandler inputHandler2 = siddhiAppRuntime.getInputHandler("cseEventStream1");
    InputHandler inputHandler3 = siddhiAppRuntime.getInputHandler("StockStream");
    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 });
    inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
    inputHandler2.send(new Object[] { "WSO21", 75.6f, 100 });
    inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
    inputHandler2.send(new Object[] { "ORACLE1", 75.6f, 100 });
    inputHandler3.send(new Object[] { "ABC", 75.6d, 100 });
    inputHandler3.send(new Object[] { "DEF", 75.6d, 100 });
    inputHandler3.send(new Object[] { "KLM", 75.6d, 100 });
    inputHandler3.send(new Object[] { "ABC", 75.6d, 100 });
    SiddhiTestHelper.waitForEvents(100, 16, count, 60000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals(16, count.get());
    AssertJUnit.assertEquals(8, stockStreamEventCount);
}
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