use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery8.
@Test
public void testEventOutputRateLimitQuery8() throws InterruptedException {
log.info("EventOutputRateLimit test8");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest8') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "group by ip " + "output first every 5 events " + "insert 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 += inEvents.length;
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived = true;
}
});
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.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.9" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 5, count);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery15.
@Test
public void testEventOutputRateLimitQuery15() throws InterruptedException {
log.info("EventOutputRateLimit test15");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest15') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(4) " + "select ip , count() as total " + "output all every 2 events " + "insert expired 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 (removeEvents != null) {
count += removeEvents.length;
} else {
AssertJUnit.fail("InEvents emitted");
}
eventArrived = true;
}
});
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" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.9" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.31" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.32" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.33" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 2, count);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery18.
@Test
public void testEventOutputRateLimitQuery18() throws InterruptedException {
log.info("EventOutputRateLimit test18");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest8') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output first every 2 events " + "insert 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 += inEvents.length;
for (Event event : inEvents) {
Assert.assertTrue(event.getData(0).equals("192.10.1.5") || event.getData(0).equals("192.10.1.4"));
}
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived = true;
}
});
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" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.9" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 6, count);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class TimeOutputRateLimitTestCase method testTimeOutputRateLimitQuery4.
@Test(dependsOnMethods = "testTimeOutputRateLimitQuery3")
public void testTimeOutputRateLimitQuery4() throws InterruptedException {
log.info("TimeOutputRateLimit test4");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest4') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output first every 1 sec " + "insert 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.addAndGet(inEvents.length);
AssertJUnit.assertTrue("192.10.1.5".equals(inEvents[0].getData(0)) || "192.10.1.9".equals(inEvents[0].getData(0)) || "192.10.1.30".equals(inEvents[0].getData(0)));
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived.set(true);
}
});
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" });
Thread.sleep(1100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.9" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
Thread.sleep(1100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived.get());
AssertJUnit.assertEquals("Number of output event value", 3, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class TimeOutputRateLimitTestCase method testTimeOutputRateLimitQuery8.
@Test(dependsOnMethods = "testTimeOutputRateLimitQuery7")
public void testTimeOutputRateLimitQuery8() throws InterruptedException {
log.info("TimeOutputRateLimit test8");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest8') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(2) " + "select ip " + "group by ip " + "output last every 1 sec " + "insert 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.addAndGet(inEvents.length);
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived.set(true);
}
});
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.5" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.9" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
Thread.sleep(1100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.30" });
Thread.sleep(1200);
AssertJUnit.assertEquals("Event arrived", true, eventArrived.get());
AssertJUnit.assertEquals("Number of output event value", 5, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations