use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest1.
@Test
public void externalTimeBatchWindowTest1() throws InterruptedException {
log.info("externalTimeBatchWindow test1");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 6 sec) " + "select timestamp, ip, count() as total " + "insert all events into uniqueIps ;";
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) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
inputHandler.send(new Object[] { 1366335804342L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335814341L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335814345L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335824341L, "192.10.1.7" });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 2, inEventCount);
org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method test02NoMsg.
@Test
public void test02NoMsg() throws Exception {
siddhiManager = new SiddhiManager();
SiddhiAppRuntime runtime = simpleQueryRuntime();
final AtomicBoolean recieved = new AtomicBoolean();
runtime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
recieved.set(true);
EventPrinter.print(timestamp, inEvents, removeEvents);
}
});
InputHandler input = runtime.getInputHandler("jmxMetric");
runtime.start();
// external events' time stamp less than the window, should not have event recieved in call back.
long now = System.currentTimeMillis();
int length = 5;
for (int i = 0; i < length; i++) {
input.send(new Object[] { 15, now + i * 1000 });
}
Thread.sleep(1000);
AssertJUnit.assertFalse("Event happens inner external time batch window, should not have event recieved in " + "callback!", recieved.get());
runtime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest15.
@Test
public void externalTimeBatchWindowTest15() throws InterruptedException {
log.info("externalTimeBatchWindow test15");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, timestamp, 100) " + "select timestamp, ip, count() as total " + "insert all events into uniqueIps ;";
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) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
inputHandler.send(new Object[] { 1366335804342L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805341L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335814341L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335814345L, "192.10.1.7" });
inputHandler.send(new Object[] { 1366335824341L, "192.10.1.8" });
inputHandler.send(new Object[] { 1366335824351L, "192.10.1.9" });
inputHandler.send(new Object[] { 1366335824441L, "192.10.1.10" });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 4, inEventCount);
org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest8.
@Test
public void externalTimeBatchWindowTest8() throws InterruptedException {
log.info("externalTimeBatchWindow test8");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 2 sec) " + "select timestamp, ip, count() as total " + "insert all events into uniqueIps ;";
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 (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
for (Event event : inEvents) {
inEventCount++;
if (inEventCount == 1) {
AssertJUnit.assertEquals(4L, event.getData(2));
} else if (inEventCount == 2) {
AssertJUnit.assertEquals(3L, event.getData(2));
} else if (inEventCount == 3) {
AssertJUnit.assertEquals(5L, event.getData(2));
} else if (inEventCount == 4) {
AssertJUnit.assertEquals(7L, event.getData(2));
} else if (inEventCount == 5) {
AssertJUnit.assertEquals(2L, event.getData(2));
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
inputHandler.send(new Object[] { 1366335804599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335804600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335804607L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335805599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335805607L, "192.10.1.6" });
Thread.sleep(2100);
inputHandler.send(new Object[] { 1366335805606L, "192.10.1.7" });
inputHandler.send(new Object[] { 1366335805605L, "192.10.1.8" });
Thread.sleep(2100);
inputHandler.send(new Object[] { 1366335805606L, "192.10.1.91" });
inputHandler.send(new Object[] { 1366335805605L, "192.10.1.92" });
inputHandler.send(new Object[] { 1366335806606L, "192.10.1.9" });
inputHandler.send(new Object[] { 1366335806690L, "192.10.1.10" });
Thread.sleep(3000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 5, inEventCount);
org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest17.
@Test
public void externalTimeBatchWindowTest17() throws InterruptedException {
log.info("externalTimeBatchWindow test17");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 100, false) " + "select timestamp, ip, count() as total " + "insert all events into uniqueIps ;";
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;
for (Event event : inEvents) {
AssertJUnit.assertTrue(((Long) event.getData(0)) % 100 != 0);
}
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
for (Event event : removeEvents) {
AssertJUnit.assertTrue(((Long) event.getData(0)) % 100 != 0);
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
inputHandler.send(new Object[] { 1366335804342L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805341L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335814341L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335814345L, "192.10.1.7" });
inputHandler.send(new Object[] { 1366335824341L, "192.10.1.8" });
inputHandler.send(new Object[] { 1366335824351L, "192.10.1.9" });
inputHandler.send(new Object[] { 1366335824441L, "192.10.1.10" });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 4, inEventCount);
org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
Aggregations