Search in sources :

Example 46 with QueryCallback

use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class OrderByLimitTestCase method limitTest4.

@Test
public void limitTest4() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol, sum(price) as totalPrice, volume " + "order by symbol " + "limit 2 " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            Assert.assertEquals(1, inEvents.length);
            Assert.assertTrue(inEvents[0].getData(2).equals(3) || inEvents[0].getData(2).equals(7));
            inEventCount = inEventCount + inEvents.length;
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 3 });
    inputHandler.send(new Object[] { "IBM", 700f, 4 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
    Thread.sleep(500);
    AssertJUnit.assertEquals(2, inEventCount);
    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) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 47 with QueryCallback

use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class OrderByLimitTestCase method limitTest9.

@Test
public void limitTest9() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.length(4) " + "select symbol, price, volume " + "group by symbol " + "order by price " + "limit 2 " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            Assert.assertEquals(1, inEvents.length);
            inEventCount = inEventCount + inEvents.length;
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "IBM", 60.5f, 1 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
    inputHandler.send(new Object[] { "XYZ", 60.5f, 3 });
    inputHandler.send(new Object[] { "IBM", 700f, 4 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
    Thread.sleep(500);
    AssertJUnit.assertEquals(8, inEventCount);
    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) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 48 with QueryCallback

use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class OrderByLimitTestCase method limitTest11.

@Test
public void limitTest11() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.length(4) " + "select symbol, price, volume " + "order by price asc " + "limit 2 " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            Assert.assertEquals(1, inEvents.length);
            inEventCount = inEventCount + inEvents.length;
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "IBM", 60.5f, 1 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
    inputHandler.send(new Object[] { "XYZ", 60.5f, 3 });
    inputHandler.send(new Object[] { "IBM", 700f, 4 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
    Thread.sleep(500);
    AssertJUnit.assertEquals(8, inEventCount);
    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) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 49 with QueryCallback

use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class OrderByLimitTestCase method limitTest3.

@Test
public void limitTest3() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol, sum(price) as totalPrice, volume " + "limit 2 " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            Assert.assertEquals(1, inEvents.length);
            Assert.assertTrue(inEvents[0].getData(2).equals(3) || inEvents[0].getData(2).equals(7));
            inEventCount = inEventCount + inEvents.length;
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 3 });
    inputHandler.send(new Object[] { "IBM", 700f, 4 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
    Thread.sleep(500);
    AssertJUnit.assertEquals(2, inEventCount);
    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) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 50 with QueryCallback

use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.

the class OrderByLimitTestCase method limitTest7.

@Test
public void limitTest7() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol, price, volume " + "group by symbol " + "order by price " + "limit 2 " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            Assert.assertEquals(2, inEvents.length);
            Assert.assertTrue(inEvents[0].getData(2).equals(1) || inEvents[0].getData(2).equals(7));
            inEventCount = inEventCount + inEvents.length;
            eventArrived = true;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 0 });
    inputHandler.send(new Object[] { "IBM", 60.5f, 1 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
    inputHandler.send(new Object[] { "XYZ", 60.5f, 3 });
    inputHandler.send(new Object[] { "IBM", 700f, 4 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 5 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 7 });
    Thread.sleep(500);
    AssertJUnit.assertEquals(4, inEventCount);
    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) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

SiddhiManager (org.wso2.siddhi.core.SiddhiManager)590 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)590 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)588 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)585 Event (org.wso2.siddhi.core.event.Event)584 Test (org.testng.annotations.Test)582 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)73 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)73 Query (org.wso2.siddhi.query.api.execution.query.Query)73 ArrayList (java.util.ArrayList)25 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)12 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)12 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)11 Test (org.junit.Test)5 ExecutionPlanRuntime (org.wso2.siddhi.core.ExecutionPlanRuntime)5 StringConcatAggregatorString (org.wso2.siddhi.core.query.extension.util.StringConcatAggregatorString)5 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1