use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery16.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery15" })
public void testSnapshotOutputRateLimitQuery16() throws InterruptedException {
log.info("SnapshotOutputRateLimit test16");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest16') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(1 sec) " + "select ip " + "group by ip " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
if (inEvents != null) {
count.incrementAndGet();
for (Event event : inEvents) {
AssertJUnit.assertTrue("192.10.1.5".equals(event.getData(0)) || "192.10.1.3".equals(event.getData(0)));
}
value += inEvents.length;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(1100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
Thread.sleep(2200);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 10 });
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 2 && value == 4);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event bundles with inEvents", 2, count.get());
AssertJUnit.assertEquals("Number of output event", 4, value);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery15.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery14" })
public void testSnapshotOutputRateLimitQuery15() throws InterruptedException {
log.info("SnapshotOutputRateLimit test15");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest15') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(1 sec) " + "select ip " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
if (inEvents != null) {
value++;
} else if (value == 1) {
AssertJUnit.assertNull(inEvents);
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
Thread.sleep(2200);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
Thread.sleep(2200);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 2, value);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery20.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery19" })
public void testSnapshotOutputRateLimitQuery20() throws InterruptedException {
log.info("SnapshotOutputRateLimit test20");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest20') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(5 sec) " + "select ip, sum(calls) as totalCalls " + "group by ip " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
if (inEvents != null) {
count.incrementAndGet();
if (count.get() == 1 || count.get() == 2) {
AssertJUnit.assertTrue((Long) inEvents[0].getData(1) == 3L && (Long) inEvents[1].getData(1) == 6L);
} else if (count.get() == 3 || count.get() == 4 || count.get() == 5) {
AssertJUnit.assertTrue((Long) inEvents[0].getData(1) == 5L && (Long) inEvents[1].getData(1) == 16L);
AssertJUnit.assertTrue((Long) inEvents[2].getData(1) == 5L && (Long) inEvents[3].getData(1) == 16L);
} else if (count.get() == 6 || count.get() == 7) {
AssertJUnit.assertTrue((Long) inEvents[0].getData(1) == 2L && (Long) inEvents[1].getData(1) == 10L);
}
value += inEvents.length;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(1100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
Thread.sleep(2200);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 10 });
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 7 && value == 20);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event bundles", 7, count.get());
AssertJUnit.assertEquals("Number of output event value", 20, value);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery17.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery16" })
public void testSnapshotOutputRateLimitQuery17() throws InterruptedException {
log.info("SnapshotOutputRateLimit test17");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest17') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(5 sec) " + "select ip " + "group by ip " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
count.incrementAndGet();
value += inEvents.length;
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(1100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
Thread.sleep(2200);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 10 });
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 7 && value == 20);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event bundles equal to 5 ", 7, count.get());
AssertJUnit.assertEquals("Number of output event value", 20, value);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery19.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery18" })
public void testSnapshotOutputRateLimitQuery19() throws InterruptedException {
log.info("SnapshotOutputRateLimit test19");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest19') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(5 sec) " + "select ip, sum(calls) as totalCalls " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
if (inEvents != null) {
count.incrementAndGet();
if (count.get() == 1 || count.get() == 2) {
AssertJUnit.assertTrue((Long) inEvents[0].getData(1) == 9L);
AssertJUnit.assertTrue((Long) inEvents[1].getData(1) == 9L);
} else if (count.get() == 3 || count.get() == 4 || count.get() == 5) {
AssertJUnit.assertTrue((Long) inEvents[0].getData(1) == 21L);
AssertJUnit.assertTrue((Long) inEvents[1].getData(1) == 21L);
AssertJUnit.assertTrue((Long) inEvents[2].getData(1) == 21L);
AssertJUnit.assertTrue((Long) inEvents[3].getData(1) == 21L);
} else if (count.get() == 6 || count.get() == 7) {
AssertJUnit.assertTrue((Long) inEvents[0].getData(1) == 12L);
AssertJUnit.assertTrue((Long) inEvents[1].getData(1) == 12L);
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(1100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
Thread.sleep(2200);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 10 });
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 7);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 7, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations