use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest10.
@Test
public void externalTimeBatchWindowTest10() throws InterruptedException {
log.info("externalTimeBatchWindow test10");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 2 sec) " + "select timestamp, ip, count() as total " + "insert into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
for (Event event : inEvents) {
inEventCount++;
if (inEventCount == 1) {
AssertJUnit.assertEquals(4L, event.getData(2));
} else if (inEventCount == 2) {
AssertJUnit.assertEquals(3L, event.getData(2));
} else if (inEventCount == 3) {
AssertJUnit.assertEquals(5L, event.getData(2));
} else if (inEventCount == 4) {
AssertJUnit.assertEquals(7L, event.getData(2));
} else if (inEventCount == 5) {
AssertJUnit.assertEquals(2L, event.getData(2));
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
inputHandler.send(new Object[] { 1366335804599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335804600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335804607L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335805599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335805607L, "192.10.1.6" });
Thread.sleep(2100);
inputHandler.send(new Object[] { 1366335805606L, "192.10.1.7" });
inputHandler.send(new Object[] { 1366335805605L, "192.10.1.8" });
Thread.sleep(2100);
inputHandler.send(new Object[] { 1366335805606L, "192.10.1.91" });
inputHandler.send(new Object[] { 1366335805605L, "192.10.1.92" });
inputHandler.send(new Object[] { 1366335806606L, "192.10.1.9" });
inputHandler.send(new Object[] { 1366335806690L, "192.10.1.10" });
Thread.sleep(3000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 5, inEventCount);
org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest12.
@Test
public void externalTimeBatchWindowTest12() throws InterruptedException {
log.info("externalTimeBatchWindow Test12");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " + "define stream twitterStream (timestamp long, user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.externalTimeBatch(timestamp, 1 sec, 0) join twitterStream#window" + ".externalTimeBatch(timestamp, 1 sec, 0) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += (inEvents.length);
}
if (removeEvents != null) {
removeEventCount += (removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { 1366335804341L, "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { 1366335804341L, "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { 1366335805301L, "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { 1366335805341L, "WSO2", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { 1366335806541L, "WSO2", 57.6f, 100 });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals(2, inEventCount);
org.testng.AssertJUnit.assertEquals(0, removeEventCount);
org.testng.AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest11.
@Test
public void externalTimeBatchWindowTest11() throws InterruptedException {
log.info("externalTimeBatchWindow test11");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0) " + "select timestamp, ip, count() as total " + "insert into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
for (Event event : inEvents) {
inEventCount++;
if (inEventCount == 1) {
AssertJUnit.assertEquals(4L, event.getData(2));
} else if (inEventCount == 2) {
AssertJUnit.assertEquals(7L, event.getData(2));
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
inputHandler.send(new Object[] { 1366335804599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335804600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335804607L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335805599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335805607L, "192.10.1.6" });
Thread.sleep(2100);
inputHandler.send(new Object[] { 1366335805606L, "192.10.1.7" });
inputHandler.send(new Object[] { 1366335805605L, "192.10.1.8" });
Thread.sleep(2100);
inputHandler.send(new Object[] { 1366335805606L, "192.10.1.91" });
inputHandler.send(new Object[] { 1366335805605L, "192.10.1.92" });
inputHandler.send(new Object[] { 1366335806606L, "192.10.1.9" });
inputHandler.send(new Object[] { 1366335806690L, "192.10.1.10" });
Thread.sleep(3000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 2, inEventCount);
org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest7.
@Test
public void externalTimeBatchWindowTest7() throws InterruptedException {
log.info("externalTimeBatchWindow test7");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 2 sec) " + "select timestamp, ip, count() as total " + "insert all events into uniqueIps ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 1366335804341L, "192.10.1.3" });
inputHandler.send(new Object[] { 1366335804599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335804600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335804607L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335805599L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805600L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335805607L, "192.10.1.6" });
Thread.sleep(3000);
inputHandler.send(new Object[] { 1366335805606L, "192.10.1.7" });
inputHandler.send(new Object[] { 1366335805605L, "192.10.1.8" });
Thread.sleep(3000);
inputHandler.send(new Object[] { 1366335806606L, "192.10.1.9" });
inputHandler.send(new Object[] { 1366335806690L, "192.10.1.10" });
Thread.sleep(3000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 4, inEventCount);
org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest13.
@Test
public void externalTimeBatchWindowTest13() throws InterruptedException {
log.info("externalTimeBatchWindow Test13");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " + "define stream twitterStream (timestamp long, user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.externalTimeBatch(timestamp, 1 sec, 0) join twitterStream#window" + ".externalTimeBatch(timestamp, 1 sec, 0) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += (inEvents.length);
}
if (removeEvents != null) {
removeEventCount += (removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { 1366335804341L, "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { 1366335804341L, "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { 1366335805301L, "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { 1366335805341L, "WSO2", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { 1366335806541L, "WSO2", 57.6f, 100 });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals(2, inEventCount);
org.testng.AssertJUnit.assertEquals(1, removeEventCount);
org.testng.AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
Aggregations