use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class AbsentPatternTestCase method testQueryAbsent10.
@Test(dependsOnMethods = { "testQueryAbsent9" })
public void testQueryAbsent10() throws InterruptedException {
log.info("Test the query e1 -> e2 -> not e3 with e1, e2 and e3 which does not meet the condition for 1 sec");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> e2=Stream2[price>20] -> not Stream3[price>30] for 1 sec " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "WSO2", "IBM" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 28.7f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 25.7f, 100 });
TestUtil.waitForInEvents(500, callback, 5);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery12.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery11" })
public void testSnapshotOutputRateLimitQuery12() throws InterruptedException {
log.info("SnapshotOutputRateLimit test12");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest12') " + "" + "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("uniqueIps", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.incrementAndGet();
eventArrived = true;
}
});
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);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 1, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery18.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery17" })
public void testSnapshotOutputRateLimitQuery18() throws InterruptedException {
log.info("SnapshotOutputRateLimit test18");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest18') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(1 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) {
AssertJUnit.assertTrue((Long) inEvents[0].getData(1) == 9L);
} else if (count.get() == 2) {
// AssertJUnit.assertTrue((Long) inEvents[0].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 });
Thread.sleep(1200);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("Number of output event value", 2, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery3.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery2" })
public void testSnapshotOutputRateLimitQuery3() throws InterruptedException {
log.info("SnapshotOutputRateLimit test3");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest3') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "select 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;
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.4".equals(event.getData(0)));
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.5" });
Thread.sleep(100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.3" });
Thread.sleep(2200);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.9" });
Thread.sleep(100);
inputHandler.send(new Object[] { System.currentTimeMillis(), "192.10.1.4" });
Thread.sleep(1100);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertTrue("Number of output event value", 3 == count.get());
Thread.sleep(2000);
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class SnapshotOutputRateLimitTestCase method testSnapshotOutputRateLimitQuery5.
@Test(dependsOnMethods = { "testSnapshotOutputRateLimitQuery4" })
public void testSnapshotOutputRateLimitQuery5() throws InterruptedException {
log.info("SnapshotOutputRateLimit test5");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest5') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents " + "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("uniqueIps", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
count.incrementAndGet();
if (count.get() == 3) {
AssertJUnit.assertTrue((Long) events[0].getData(1) == 5L && (Long) events[1].getData(1) == 16L);
}
for (Event event : events) {
if (event.isExpired()) {
AssertJUnit.fail("Remove events emitted");
} else {
value++;
AssertJUnit.assertTrue("192.10.1.5".equals(event.getData(0)) || "192.10.1.3".equals(event.getData(0)));
}
}
}
});
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", 3, count.get());
siddhiAppRuntime.shutdown();
Thread.sleep(2000);
}
Aggregations