Search in sources :

Example 26 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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 27 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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 28 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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 29 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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 30 with OutputStream

use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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)845 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)841 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)818 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)777 Event (org.wso2.siddhi.core.event.Event)473 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)377 TestUtil (org.wso2.siddhi.core.TestUtil)300 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)100 Query (org.wso2.siddhi.query.api.execution.query.Query)80 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)67 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)65 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 IOException (java.io.IOException)14 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)11 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)11 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)10 Response (javax.ws.rs.core.Response)9 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)8 ObjectOutputStream (java.io.ObjectOutputStream)7 OutputStream (java.io.OutputStream)6