Search in sources :

Example 26 with SiddhiApp

use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery7.

@Test
public void testPartitionQuery7() throws InterruptedException {
    log.info("Partition test7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest7') " + "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,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);
            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(110.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(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 27 with SiddhiApp

use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery23.

@Test
public void testPartitionQuery23() throws InterruptedException {
    log.info("Partition test23");
    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#window.time(1 sec) " + "select symbol, avg(price) as avgPrice, volume " + "having avgPrice >= 0 or avgPrice is null " + "insert expired events 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(null, event.getData()[1]);
                }
                eventArrived = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75f, 100 });
    SiddhiTestHelper.waitForEvents(200, 1, count, 60000);
    AssertJUnit.assertEquals(1, 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 28 with SiddhiApp

use of org.wso2.siddhi.query.api.SiddhiApp 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 29 with SiddhiApp

use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery40.

@Test
public void testPartitionQuery40() throws InterruptedException {
    log.info("Partition test");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest') " + "@app:statistics('true') " + "define stream streamA (symbol string,  price int);" + "@info(name = 'partitionB')" + "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 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 30 with SiddhiApp

use of org.wso2.siddhi.query.api.SiddhiApp in project siddhi by wso2.

the class PartitionTestCase1 method testPartitionQuery18.

@Test
public void testPartitionQuery18() throws InterruptedException {
    log.info("Partition test18");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest18') " + "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 'small' of cseEventStream) begin @info(name " + "= 'query1') from cseEventStream#window.length(4) select symbol,sum(price) 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);
            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(7005.60009765625, event.getData()[1]);
                } else if (count.get() == 3) {
                    AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0));
                } else if (count.get() == 4) {
                    AssertJUnit.assertEquals(100.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[] { "IBM", 50f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 25f, 100 });
    SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
    AssertJUnit.assertTrue(count.get() <= 4);
    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

SiddhiManager (org.wso2.siddhi.core.SiddhiManager)273 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)272 Test (org.testng.annotations.Test)261 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)245 Event (org.wso2.siddhi.core.event.Event)241 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)138 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)109 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)88 Query (org.wso2.siddhi.query.api.execution.query.Query)84 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)81 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)13 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)13 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)13 Partition (org.wso2.siddhi.query.api.execution.partition.Partition)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6 HashMap (java.util.HashMap)6 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)6 InMemoryConfigManager (org.wso2.siddhi.core.util.config.InMemoryConfigManager)5 ExecutionElement (org.wso2.siddhi.query.api.execution.ExecutionElement)4