use of org.ballerinalang.siddhi.core.event.Event in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery6.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery5" })
public void testSnapshotOutputRateLimitQuery6() throws InterruptedException {
log.info("SnapshotOutputRateLimit test6");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest6') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(1 sec) " + "select 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("uniqueIps", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
count.incrementAndGet();
value += events.length;
if (count.get() == 1) {
AssertJUnit.assertTrue((Long) events[0].getData(0) == 3L || (Long) events[1].getData(0) == 6L);
} else if (count.get() == 2) {
AssertJUnit.assertTrue((Long) events[0].getData(0) == 2L || (Long) events[1].getData(0) == 10L);
}
}
});
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", 2, count.get());
AssertJUnit.assertTrue("Number of output events", 4 == value);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.event.Event 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.event.Event in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery14.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery13" })
public void testSnapshotOutputRateLimitQuery14() throws InterruptedException {
log.info("SnapshotOutputRateLimit test14");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest14') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(2 sec) " + "select ip " + "output snapshot every 2 sec " + "insert all events into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
siddhiAppRuntime.addCallback("uniqueIps", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
for (Event event : events) {
if (event.isExpired()) {
AssertJUnit.fail("Remove events emitted");
} else {
count.incrementAndGet();
AssertJUnit.assertTrue("192.10.1.3".equals(event.getData(0)) || "192.10.1.5".equals(event.getData(0)));
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> eventArrived && count.get() == 2);
AssertJUnit.assertTrue("Event arrived", (eventArrived && count.get() == 2));
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.event.Event in project ballerina by ballerina-lang.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery7.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery6" })
public void testSnapshotOutputRateLimitQuery7() throws InterruptedException {
log.info("SnapshotOutputRateLimit test7");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest7') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(5 sec) " + "select 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("uniqueIps", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
count.incrementAndGet();
value += events.length;
if (count.get() == 1 || count.get() == 2) {
AssertJUnit.assertTrue((Long) events[0].getData(0) == 3L || (Long) events[1].getData(0) == 6L);
} else if (count.get() == 3) {
AssertJUnit.assertTrue((Long) events[0].getData(0) == 5L || (Long) events[1].getData(0) == 16L);
}
}
});
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 == 14);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event bundles", 7, count.get());
AssertJUnit.assertTrue("Number of output event value", 14 == value);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.event.Event 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();
}
Aggregations