use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class PlaybackTestCase method playbackTest12.
@Test(dependsOnMethods = { "playbackTest11" })
public void playbackTest12() throws InterruptedException {
log.info("Playback Test 12: Testing playback with out of order event with greater than system timestamp");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "@app:playback(idle.time = '100 millisecond', increment = '1 sec') " + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(2 sec) " + "select symbol,price,volume " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
}
if (removeEvents != null) {
AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
removeEventCount = removeEventCount + removeEvents.length;
if (removeEventCount == 3) {
// Last timestamp is 1900 + 3 sec (increment) = 2200
AssertJUnit.assertEquals(4900, removeEvents[0].getTimestamp());
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(100, new Object[] { "IBM", 700f, 0 });
inputHandler.send(200, new Object[] { "WSO2", 600.5f, 1 });
Thread.sleep(150);
inputHandler.send(1900, new Object[] { "ORACLE", 500.0f, 2 });
// Anything more than 100 is enough. Used 200 to be on safe side
Thread.sleep(350);
SiddhiTestHelper.waitForEvents(100, 3, inEventCount, 60000);
SiddhiTestHelper.waitForEvents(100, 3, removeEventCount, 60000);
AssertJUnit.assertEquals(3, inEventCount);
AssertJUnit.assertEquals(3, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class PlaybackTestCase method playbackTest17_1.
@Test(dependsOnMethods = { "playbackTest17" })
public void playbackTest17_1() throws InterruptedException {
log.info("Playback Test 17: Switching between Playback mode and live mode with heartbeat disabled in query " + "containing regular time batch window test only current batch ");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(1 sec) " + "select * " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEventCount == 0) {
AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
}
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
siddhiAppRuntime.enablePlayBack(true, null, null);
long timestamp = System.currentTimeMillis();
inputHandler.send(timestamp - 500, new Object[] { "IBM", 700f, 0 });
Thread.sleep(10);
inputHandler.send(timestamp - 100, new Object[] { "WSO2", 60.5f, 1 });
siddhiAppRuntime.enablePlayBack(false, null, null);
// 1 sec passed
Thread.sleep(605);
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
SiddhiTestHelper.waitForEvents(100, 0, removeEventCount, 60000);
AssertJUnit.assertEquals(2, inEventCount);
AssertJUnit.assertEquals(0, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery65.
@Test
public void testFilterQuery65() throws InterruptedException {
log.info("Filter test65");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.EQUAL, Expression.value(40))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50f, 60L });
inputHandler.send(new Object[] { "WSO2", 70f, 40L });
inputHandler.send(new Object[] { "WSO2", 44f, 200L });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery3.
@Test
public void testFilterQuery3() throws InterruptedException {
log.info("Filter test3");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "@info(name = 'query1') from cseEventStream[70 > price] select symbol,price insert into " + "outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
AssertJUnit.assertTrue("WSO2".equals(inEvents[0].getData(0)));
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "WSO2", 57.6f, 200 });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery22.
@Test
public void testFilterQuery22() throws InterruptedException {
log.info("Filter test22");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume double);";
String query = "@info(name = 'query1') from cseEventStream[volume > 12L and price < 56] select symbol,price," + "volume insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
AssertJUnit.assertEquals(100d, inEvents[0].getData(2));
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.6f, 100d });
inputHandler.send(new Object[] { "WSO2", 57.6f, 10d });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
siddhiAppRuntime.shutdown();
}
Aggregations