Search in sources :

Example 36 with Query

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

the class InstanceOfFunctionTestCase method testInstanceOfDoubleFunctionExtensionExceptionTestCase.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testInstanceOfDoubleFunctionExtensionExceptionTestCase() throws InterruptedException {
    log.info("testInstanceOfDoubleFunctionExtensionException 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 ,instanceOfDouble(longitude,sensorName) as valid, longitude " + "insert into outputStream;");
    siddhiManager.createSiddhiAppRuntime(sensorEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 37 with Query

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

the class InstanceOfFunctionTestCase method testInstanceOfIntegerFunctionExtensionExceptionTestCase.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testInstanceOfIntegerFunctionExtensionExceptionTestCase() throws InterruptedException {
    log.info("testInstanceOfIntegerFunctionExtensionException 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,sensorName) as valid, sensorId " + "insert into outputStream;");
    siddhiManager.createSiddhiAppRuntime(sensorEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 38 with Query

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

the class InstanceOfFunctionTestCase method testInstanceOfStringFunctionExtensionExceptionTestCase.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testInstanceOfStringFunctionExtensionExceptionTestCase() throws InterruptedException {
    log.info("testInstanceOfStringFunctionExtensionException 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 ,instanceOfString(sensorName,sensorId) as valid " + "insert into outputStream;");
    siddhiManager.createSiddhiAppRuntime(sensorEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 39 with Query

use of org.wso2.siddhi.query.api.execution.query.Query 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 40 with Query

use of org.wso2.siddhi.query.api.execution.query.Query 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)

Aggregations

Test (org.testng.annotations.Test)1150 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1093 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1065 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1006 Event (org.wso2.siddhi.core.event.Event)673 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)528 TestUtil (org.wso2.siddhi.core.TestUtil)300 Query (org.wso2.siddhi.query.api.execution.query.Query)145 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)121 PreparedStatement (java.sql.PreparedStatement)97 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)83 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)82 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)78 SQLException (java.sql.SQLException)73 ArrayList (java.util.ArrayList)73 Connection (java.sql.Connection)69 ResultSet (java.sql.ResultSet)50 HashMap (java.util.HashMap)40 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)22 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)20