Search in sources :

Example 1 with QueryCallback

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

the class SiddhiAppRuntime method addCallback.

public void addCallback(String queryName, QueryCallback callback) {
    callback.setContext(siddhiAppContext);
    QueryRuntime queryRuntime = queryProcessorMap.get(queryName);
    if (queryRuntime == null) {
        throw new QueryNotExistException("No query found with name: " + queryName);
    }
    callback.setQuery(queryRuntime.getQuery());
    queryRuntime.addCallback(callback);
}
Also used : QueryNotExistException(org.wso2.siddhi.core.exception.QueryNotExistException) QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) StoreQueryRuntime(org.wso2.siddhi.core.query.StoreQueryRuntime)

Example 2 with QueryCallback

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

the class InstanceOfFunctionTestCase method testInstanceOfIntegerFunctionExtensionTestCase.

@Test
public void testInstanceOfIntegerFunctionExtensionTestCase() throws InterruptedException {
    log.info("testInstanceOfIntegerFunctionExtension TestCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String sensorEventStream = "define stream sensorEventStream (timestamp long, " + "isPowerSaverEnabled bool, sensorId int , sensorName string, longitude double, latitude double, " + "humidity float, sensorValue double);";
    String query = ("@info(name = 'query1') " + "from sensorEventStream " + "select sensorName ,instanceOfInteger(sensorId) as valid, sensorId " + "insert into outputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(sensorEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            for (Event inEvent : inEvents) {
                count++;
                if (count == 1) {
                    AssertJUnit.assertEquals(true, inEvent.getData(1));
                }
                if (count == 2) {
                    AssertJUnit.assertEquals(false, inEvent.getData(1));
                }
                eventArrived = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("sensorEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 19900813115534L, false, 601, "temperature", 90.34344, 20.44345, 2.3f, 20.44345 });
    inputHandler.send(new Object[] { 19900813115534L, true, 60232434.657, "temperature", 90.34344, 20.44345, 2.3f, 20.44345 });
    Thread.sleep(100);
    org.testng.AssertJUnit.assertEquals(2, count);
    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 3 with QueryCallback

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

the class InstanceOfFunctionTestCase method testInstanceOfLongFunctionExtensionTestCase.

@Test
public void testInstanceOfLongFunctionExtensionTestCase() throws InterruptedException {
    log.info("testInstanceOfLongFunctionExtension TestCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String sensorEventStream = "define stream sensorEventStream (timestamp long, " + "isPowerSaverEnabled bool, sensorId int , sensorName string, longitude double, latitude double, " + "humidity float, sensorValue double);";
    String query = ("@info(name = 'query1') " + "from sensorEventStream " + "select sensorName ,instanceOfLong(timestamp) as valid, timestamp " + "insert into outputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(sensorEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            for (Event inEvent : inEvents) {
                count++;
                if (count == 1) {
                    AssertJUnit.assertEquals(true, inEvent.getData(1));
                }
                if (count == 2) {
                    AssertJUnit.assertEquals(false, inEvent.getData(1));
                }
                eventArrived = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("sensorEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 19900813115534L, false, 601, "temperature", 90.34344, 20.44345, 2.3f, 20.44345 });
    inputHandler.send(new Object[] { 1990, false, 602, "temperature", 90.34344, 20.44345, 2.3f, 20.44345 });
    Thread.sleep(100);
    org.testng.AssertJUnit.assertEquals(2, count);
    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 4 with QueryCallback

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

the class InstanceOfFunctionTestCase method testInstanceOfFloatFunctionExtensionTestCase.

@Test
public void testInstanceOfFloatFunctionExtensionTestCase() throws InterruptedException {
    log.info("testInstanceOfFloatFunctionExtension TestCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String sensorEventStream = "define stream sensorEventStream (timestamp long, " + "isPowerSaverEnabled bool, sensorId int , sensorName string, longitude double, latitude double, " + "humidity float, sensorValue double);";
    String query = ("@info(name = 'query1') " + "from sensorEventStream " + "select sensorName ,instanceOfFloat(humidity) as valid, longitude " + "insert into outputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(sensorEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            for (Event inEvent : inEvents) {
                count++;
                if (count == 1) {
                    AssertJUnit.assertEquals(true, inEvent.getData(1));
                }
                if (count == 2) {
                    AssertJUnit.assertEquals(false, inEvent.getData(1));
                }
                eventArrived = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("sensorEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 19900813115534L, false, 601, "temperature", 90.34344, 20.44345, 2.3f, 20.44345 });
    inputHandler.send(new Object[] { 19900813115534L, true, 602, "temperature", 90.34344, 20.44345, 2.3, 20.44345 });
    Thread.sleep(100);
    org.testng.AssertJUnit.assertEquals(2, count);
    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 5 with QueryCallback

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

the class MaximumFunctionExtensionTestCase method testMaxFunctionExtension10.

@Test
public void testMaxFunctionExtension10() throws InterruptedException {
    log.info("MaximumFunctionExecutor TestCase 10");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "define stream inputStream (price1 long,price2 long, price3 long);";
    String query = ("@info(name = 'query1') from inputStream " + "select maximum(price1, price2, price3) as max " + "insert into outputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            eventArrived = true;
            for (Event event : inEvents) {
                count++;
                switch(count) {
                    case 1:
                        AssertJUnit.assertEquals(3675L, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(3812L, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(3925L, event.getData(0));
                        break;
                    case 4:
                        AssertJUnit.assertEquals(3775L, event.getData(0));
                        break;
                    case 5:
                        AssertJUnit.assertEquals(3812L, event.getData(0));
                        break;
                    case 6:
                        AssertJUnit.assertEquals(3812L, event.getData(0));
                        break;
                    default:
                        org.junit.Assert.fail();
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 36L, 3675L, 3575L });
    inputHandler.send(new Object[] { 3788L, 3812L, 3762L });
    inputHandler.send(new Object[] { 3900L, 3925L, 3862L });
    inputHandler.send(new Object[] { 3688L, 3775L, 3675L });
    inputHandler.send(new Object[] { 3812L, 3812L, 3775L });
    inputHandler.send(new Object[] { 3812L, 40L, 3775L });
    Thread.sleep(300);
    AssertJUnit.assertEquals(6, count);
    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