use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
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 });
Thread.sleep(1200);
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 io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery22.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery21" })
public void testSnapshotOutputRateLimitQuery22() throws InterruptedException {
log.info("SnapshotOutputRateLimit test22");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest22') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "select ip, calls " + "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;
count.incrementAndGet();
for (Event inEvent : inEvents) {
value++;
if (value == 1) {
AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
} else if (value == 2) {
AssertJUnit.assertEquals("192.10.1.6", (String) inEvent.getData(0));
} else if (value == 3) {
AssertJUnit.assertEquals("192.10.1.7", (String) inEvent.getData(0));
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
Thread.sleep(1200);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event bundles", 1, count.get());
AssertJUnit.assertEquals("Number of output events", 3, value);
siddhiAppRuntime.shutdown();
Thread.sleep(2000);
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery28.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery27" })
public void testSnapshotOutputRateLimitQuery28() throws InterruptedException {
log.info("SnapshotOutputRateLimit test28");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest28') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "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;
count.incrementAndGet();
if (inEvents != null) {
for (Event inEvent : inEvents) {
value++;
if (value == 1) {
AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
} else if (value == 2) {
AssertJUnit.assertEquals("192.10.1.3", (String) inEvent.getData(0));
} else if (value == 3) {
AssertJUnit.assertEquals("192.10.1.4", (String) inEvent.getData(0));
} else if (value == 4) {
AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
} else if (value == 5) {
AssertJUnit.assertEquals("192.10.1.6", (String) inEvent.getData(0));
} else if (value == 6) {
AssertJUnit.assertEquals("192.10.1.7", (String) inEvent.getData(0));
}
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(2100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
Thread.sleep(1200);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
Thread.sleep(1200);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertTrue("Number of output event bundles count > 2", count.get() > 2);
AssertJUnit.assertEquals("Number of output events", 6, value);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery23.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery22" })
public void testSnapshotOutputRateLimitQuery23() throws InterruptedException {
log.info("SnapshotOutputRateLimit test23");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest23') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "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;
count.incrementAndGet();
for (Event inEvent : inEvents) {
value++;
if (value == 1) {
AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
} else if (value == 2) {
AssertJUnit.assertEquals("192.10.1.6", (String) inEvent.getData(0));
} else if (value == 3) {
AssertJUnit.assertEquals("192.10.1.7", (String) inEvent.getData(0));
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
Thread.sleep(1200);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event bundles", 1, count.get());
AssertJUnit.assertEquals("Number of output events", 3, value);
siddhiAppRuntime.shutdown();
Thread.sleep(2000);
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery27.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery26" })
public void testSnapshotOutputRateLimitQuery27() throws InterruptedException {
log.info("SnapshotOutputRateLimit test27");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest27') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(3) " + "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;
count.incrementAndGet();
for (Event inEvent : inEvents) {
value++;
if (value == 1) {
AssertJUnit.assertEquals("192.10.1.5", (String) inEvent.getData(0));
} else if (value == 2) {
AssertJUnit.assertEquals("192.10.1.6", (String) inEvent.getData(0));
} else if (value == 3) {
AssertJUnit.assertEquals("192.10.1.7", (String) inEvent.getData(0));
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
Thread.sleep(100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 3 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3", 6 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5", 1 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.6", 1 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.7", 2 });
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.8", 10 });
Thread.sleep(1200);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event bundles", 1, count.get());
AssertJUnit.assertEquals("Number of output events", 3, value);
siddhiAppRuntime.shutdown();
Thread.sleep(2000);
}
Aggregations