Search in sources :

Example 51 with Name

use of org.wso2.ballerinalang.compiler.util.Name 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 52 with Name

use of org.wso2.ballerinalang.compiler.util.Name 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 53 with Name

use of org.wso2.ballerinalang.compiler.util.Name 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 54 with Name

use of org.wso2.ballerinalang.compiler.util.Name 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 55 with Name

use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.

the class InstanceOfFunctionTestCase method testInstanceOfFloatFunctionExtensionExceptionTestCase.

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

Aggregations

Test (org.testng.annotations.Test)1322 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)1191 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)1162 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)1118 Event (org.wso2.siddhi.core.event.Event)786 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)585 TestUtil (org.wso2.siddhi.core.TestUtil)298 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)200 ArrayList (java.util.ArrayList)136 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)100 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)82 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)80 Query (org.wso2.siddhi.query.api.execution.query.Query)80 HashMap (java.util.HashMap)76 SQLException (java.sql.SQLException)70 PreparedStatement (java.sql.PreparedStatement)67 API (org.wso2.carbon.apimgt.core.models.API)65 Connection (java.sql.Connection)64 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)64 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)50