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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations