use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest4.
@Test
public void externalTimeBatchWindowTest4() throws InterruptedException {
log.info("externalTimeBatchWindow test4");
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, 6 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[] { 1366335804999L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805000L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805999L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335806000L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335806001L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335824341L, "192.10.1.7" });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 3, 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 ExternalTimeWindowTestCase method externalTimeWindowTest1.
@Test
public void externalTimeWindowTest1() throws InterruptedException {
log.info("externalTimeWindow test1");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;";
String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTime(timestamp,5 sec) " + "select timestamp, ip " + "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[] { 1366335804342L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335814341L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335814345L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335824341L, "192.10.1.7" });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("In Events ", 5, inEventCount);
AssertJUnit.assertEquals("Remove Events ", 4, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class LengthBatchWindowTestCase method lengthBatchWindowTest9.
@Test
public void lengthBatchWindowTest9() throws InterruptedException {
log.info("LengthBatchWindow Test9");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(2) join twitterStream#window.lengthBatch(2) " + "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[] { "WSO2", 55.6f, 100 });
cseEventStreamHandler.send(new Object[] { "IBM", 59.6f, 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(500);
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(1000);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertEquals(0, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class LengthBatchWindowTestCase method lengthBatchWindowTest1.
@Test
public void lengthBatchWindowTest1() throws InterruptedException {
log.info("Testing length batch window with no of events smaller than window size");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol,price,volume " + "insert into outputStream ;";
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);
AssertJUnit.fail("No events should arrive");
inEventCount = inEventCount + inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(500);
AssertJUnit.assertEquals(0, inEventCount);
AssertJUnit.assertFalse(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class LengthWindowTestCase method lengthWindowTest1.
@Test
public void lengthWindowTest1() throws InterruptedException {
log.info("Testing length window with no of events smaller than window size");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "@info(name = 'query1') from cseEventStream#window.length(4) select symbol,price,volume insert" + " all events into outputStream ;";
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);
AssertJUnit.assertEquals("Message order inEventCount", inEventCount, inEvents[0].getData(2));
AssertJUnit.assertEquals("Events cannot be expired", false, inEvents[0].isExpired());
inEventCount = inEventCount + inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(500);
AssertJUnit.assertEquals(2, inEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations