use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class LengthBatchWindowTestCase method lengthBatchWindowTest6.
@Test
public void lengthBatchWindowTest6() 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.lengthBatch(4) " + "select symbol,sum(price) as sumPrice,volume " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
AssertJUnit.assertEquals("Events cannot be expired", false, event.isExpired());
inEventCount++;
if (inEventCount == 1) {
AssertJUnit.assertEquals(100.0, event.getData(1));
} else if (inEventCount == 2) {
AssertJUnit.assertEquals(240.0, event.getData(1));
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 10f, 0 });
inputHandler.send(new Object[] { "WSO2", 20f, 1 });
inputHandler.send(new Object[] { "IBM", 30f, 0 });
inputHandler.send(new Object[] { "WSO2", 40f, 1 });
inputHandler.send(new Object[] { "IBM", 50f, 0 });
inputHandler.send(new Object[] { "WSO2", 60f, 1 });
inputHandler.send(new Object[] { "WSO2", 60f, 1 });
inputHandler.send(new Object[] { "IBM", 70f, 0 });
inputHandler.send(new Object[] { "WSO2", 80f, 1 });
Thread.sleep(500);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(2, inEventCount);
AssertJUnit.assertTrue(eventArrived);
}
use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class LengthBatchWindowTestCase method lengthBatchWindowTest5.
@Test
public void lengthBatchWindowTest5() throws InterruptedException {
final int length = 2;
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(" + length + ") " + "select symbol,price,volume " + "insert expired events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count++;
AssertJUnit.assertEquals("Remove event order", count, event.getData(2));
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(500);
AssertJUnit.assertEquals("Remove event count", 4, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class LengthBatchWindowTestCase method lengthBatchWindowTest2.
@Test
public void lengthBatchWindowTest2() throws InterruptedException {
log.info("Testing length batch window with no of events greater than window size");
final int length = 4;
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(" + length + ") " + "select symbol,price,volume " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count++;
AssertJUnit.assertEquals("In event order", count, event.getData(2));
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(500);
AssertJUnit.assertEquals("Total event count", 4, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class CallbackTestCase method callbackTest1.
@Test
public void callbackTest1() throws InterruptedException {
log.info("callback test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('callbackTest1') " + "" + "define stream StockStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from StockStream[70 > price] " + "select symbol, price " + "insert into outputStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
count = count + inEvents.length;
eventArrived = true;
}
});
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
count = count + events.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 100L });
inputHandler.send(new Object[] { "WSO2", 60.5f, 200L });
Thread.sleep(100);
AssertJUnit.assertEquals(2, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class ExceptionHandlerTestCase method createTestExecutionRuntime.
private SiddhiAppRuntime createTestExecutionRuntime() {
siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('callbackTest1') " + "" + "@async(buffer.size='2')" + "define stream StockStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "@Parallel " + "from StockStream[price + 0.0 > 0.0] " + "select symbol, price " + "insert into outputStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
return siddhiAppRuntime;
}
Aggregations