use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.
the class TimeWindowTestCase method timeWindowTest6.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void timeWindowTest6() throws InterruptedException, SiddhiAppCreationException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, time long, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(4.7) " + "select symbol,price,volume " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.
the class TimeWindowTestCase method timeWindowTest5.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void timeWindowTest5() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, time long, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(time) " + "select symbol,price,volume " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.
the class TimeWindowTestCase method timeWindowTest3.
@Test
public void timeWindowTest3() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String queries = "define stream fireAlarmEventStream (deviceID string, sonar double);\n" + "@info(name = 'query1')\n" + "from fireAlarmEventStream#window.time(30 milliseconds)\n" + "select deviceID\n" + "insert expired events into analyzeStream;\n" + "" + "@info(name = 'query2')\n" + "from analyzeStream\n" + "select deviceID\n" + "insert into bulbOnStream;\n";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(queries);
siddhiAppRuntime.addCallback("analyzeStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("fireAlarmEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "id1", 20d });
inputHandler.send(new Object[] { "id2", 20d });
Thread.sleep(2000);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.
the class TimeWindowTestCase method timeWindowTest1.
@Test
public void timeWindowTest1() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(2 sec) " + "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);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
}
if (removeEvents != null) {
AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
removeEventCount = removeEventCount + removeEvents.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(4000);
AssertJUnit.assertEquals(2, inEventCount);
AssertJUnit.assertEquals(2, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.SiddhiAppRuntime in project ballerina by ballerina-lang.
the class TimeWindowTestCase method timeWindowTest2.
/**
* Commenting out intermittent failing test case until fix this properly.
*
* @throws InterruptedException throw exception if interrupted the input handler sender.
*/
@Test
public void timeWindowTest2() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "@info(name = 'query1') from cseEventStream#window.time(1 sec) 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);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
}
if (removeEvents != null) {
AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
Thread.sleep(1100);
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
Thread.sleep(1100);
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(4000);
AssertJUnit.assertEquals(6, inEventCount);
AssertJUnit.assertEquals(6, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations