use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class SequenceTestCase method testQuery1.
@Test
public void testQuery1() throws InterruptedException {
log.info("testSequence1 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>20],e2=Stream2[price>e1.price] " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + 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;
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "IBM" }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 55.7f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest5.
@Test
public void externalTimeBatchWindowTest5() throws InterruptedException {
log.info("externalTimeBatchWindow test5");
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, 3 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" });
Thread.sleep(5000);
org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
org.testng.AssertJUnit.assertEquals("In Events ", 1, 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 schedulerLastBatchTriggerTest.
@Test
public void schedulerLastBatchTriggerTest() throws InterruptedException {
siddhiManager = new SiddhiManager();
String inputStream = "define stream inputStream(currentTime long,value int); ";
String query = " " + "@info(name='query') " + "from inputStream#window.externalTimeBatch(currentTime,5 sec, 0, 6 sec) " + "select value, currentTime " + "insert current events into outputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
int count = 0;
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
if (count == 0) {
AssertJUnit.assertEquals(1, inEvents[0].getData(0));
} else if (count == 1) {
AssertJUnit.assertEquals(6, inEvents[0].getData(0));
} else if (count == 2) {
AssertJUnit.assertEquals(11, inEvents[0].getData(0));
} else if (count == 3) {
AssertJUnit.assertEquals(14, inEvents[0].getData(0));
} else if (count == 4) {
AssertJUnit.assertEquals(15, inEvents[0].getData(0));
}
count += 1;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 10000L, 1 });
Thread.sleep(100);
inputHandler.send(new Object[] { 11000L, 2 });
Thread.sleep(100);
inputHandler.send(new Object[] { 12000L, 3 });
Thread.sleep(100);
inputHandler.send(new Object[] { 13000L, 4 });
Thread.sleep(100);
inputHandler.send(new Object[] { 14000L, 5 });
Thread.sleep(100);
inputHandler.send(new Object[] { 15000L, 6 });
Thread.sleep(100);
inputHandler.send(new Object[] { 16500L, 7 });
Thread.sleep(100);
inputHandler.send(new Object[] { 17000L, 8 });
Thread.sleep(100);
inputHandler.send(new Object[] { 18000L, 9 });
Thread.sleep(100);
inputHandler.send(new Object[] { 19000L, 10 });
Thread.sleep(100);
inputHandler.send(new Object[] { 20100L, 11 });
Thread.sleep(100);
inputHandler.send(new Object[] { 20500L, 12 });
Thread.sleep(100);
inputHandler.send(new Object[] { 22000L, 13 });
Thread.sleep(100);
inputHandler.send(new Object[] { 25000L, 14 });
Thread.sleep(100);
inputHandler.send(new Object[] { 32000L, 15 });
Thread.sleep(100);
inputHandler.send(new Object[] { 33000L, 16 });
Thread.sleep(6000);
}
use of org.ballerinalang.siddhi.core.query.output.callback.QueryCallback in project ballerina by ballerina-lang.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest2.
@Test
public void externalTimeBatchWindowTest2() throws InterruptedException {
log.info("externalTimeBatchWindow test2");
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) " + "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[] { 1366335804342L, "192.10.1.4" });
inputHandler.send(new Object[] { 1366335805340L, "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);
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 externalTimeBatchWindowTest16.
@Test
public void externalTimeBatchWindowTest16() throws InterruptedException {
log.info("externalTimeBatchWindow test16");
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, 100, true) " + "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;
for (Event event : inEvents) {
AssertJUnit.assertTrue(((Long) event.getData(0)) % 100 == 0);
}
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
for (Event event : removeEvents) {
AssertJUnit.assertTrue(((Long) event.getData(0)) % 100 == 0);
}
}
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[] { 1366335805341L, "192.10.1.5" });
inputHandler.send(new Object[] { 1366335814341L, "192.10.1.6" });
inputHandler.send(new Object[] { 1366335814345L, "192.10.1.7" });
inputHandler.send(new Object[] { 1366335824341L, "192.10.1.8" });
inputHandler.send(new Object[] { 1366335824351L, "192.10.1.9" });
inputHandler.send(new Object[] { 1366335824441L, "192.10.1.10" });
Thread.sleep(1000);
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();
}
Aggregations