use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery10.
@Test
public void testEventOutputRateLimitQuery10() throws InterruptedException {
log.info("EventOutputRateLimit test10");
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.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 testEventOutputRateLimitQuery14.
@Test
public void testEventOutputRateLimitQuery14() throws InterruptedException {
log.info("EventOutputRateLimit test14");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest14') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(4) " + "select ip , count() as total " + "output last 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", 1, count);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery7.
@Test
public void testEventOutputRateLimitQuery7() throws InterruptedException {
log.info("EventOutputRateLimit test7");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest7') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "output last every 4 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;
AssertJUnit.assertTrue("192.10.1.4".equals(inEvents[0].getData(0)));
} else {
AssertJUnit.fail("Remove events emitted");
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
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.3" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 1, count);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery16.
@Test
public void testEventOutputRateLimitQuery16() throws InterruptedException {
log.info("EventOutputRateLimit test16");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest16') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(4) " + "select ip , count() as total " + "group by ip " + "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", 4, count);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class EventOutputRateLimitTestCase method testEventOutputRateLimitQuery9.
@Test
public void testEventOutputRateLimitQuery9() throws InterruptedException {
log.info("EventOutputRateLimit test9");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('EventOutputRateLimitTest9') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select ip " + "group by ip " + "output last 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", 4, count);
siddhiAppRuntime.shutdown();
}
Aggregations