use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class PersistenceTestCase method persistenceTest9.
@Test(dependsOnMethods = "persistenceTest8")
public void persistenceTest9() throws InterruptedException {
log.info("persistence test 9 - batch window query");
PersistenceStore persistenceStore = new InMemoryPersistenceStore();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setPersistenceStore(persistenceStore);
String siddhiApp = "" + "@app:name('Test') " + "" + "define stream StockStream ( symbol string, price float, volume long );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.timeBatch(300) " + "select * " + "insert all events into OutStream ";
QueryCallback queryCallback = new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
eventArrived = true;
if (inEvents != null) {
for (Event inEvent : inEvents) {
atomicCount.incrementAndGet();
AssertJUnit.assertTrue("IBM".equals(inEvent.getData(0)) || "WSO2".equals(inEvent.getData(0)));
lastValue = (Long) inEvent.getData(2);
}
}
}
};
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", queryCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100L });
inputHandler.send(new Object[] { "WSO2", 75.6f, 101L });
inputHandler.send(new Object[] { "IBM", 75.6f, 102L });
Thread.sleep(400);
inputHandler.send(new Object[] { "WSO2", 75.6f, 103L });
inputHandler.send(new Object[] { "WSO2", 75.6f, 104L });
Thread.sleep(100);
AssertJUnit.assertTrue(eventArrived);
// persisting
siddhiAppRuntime.persist();
inputHandler.send(new Object[] { "IBM", 75.6f, 105L });
inputHandler.send(new Object[] { "WSO2", 75.6f, 106L });
Thread.sleep(50);
// restarting execution plan
siddhiAppRuntime.shutdown();
siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", queryCallback);
inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
// loading
try {
siddhiAppRuntime.restoreLastRevision();
} catch (CannotRestoreSiddhiAppStateException e) {
Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
}
inputHandler.send(new Object[] { "IBM", 75.6f, 107L });
inputHandler.send(new Object[] { "IBM", 75.6f, 108L });
Thread.sleep(10);
SiddhiTestHelper.waitForEvents(100, 7, atomicCount, 10000);
AssertJUnit.assertEquals(7, atomicCount.get());
// shutdown siddhi app
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class SelectOptimisationAggregationTestCase method aggregationFunctionTestcase11.
@Test(dependsOnMethods = "aggregationFunctionTestcase10")
public void aggregationFunctionTestcase11() throws InterruptedException {
LOG.info("aggregationFunctionTestcase10: testing latest incremental aggregator - different select ");
SiddhiManager siddhiManager = new SiddhiManager();
String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);";
String query = "define aggregation stockAggregation " + "from stockStream " + "select symbol, sum(price) as sumPrice " + "group by symbol " + "aggregate by timestamp every sec...year ;" + "define stream inputStream (symbol string); " + "@info(name = 'query1') " + "from inputStream as i join stockAggregation as s " + "within 1496200000000L, 1596535449000L " + "per \"seconds\" " + "select s.symbol, sum(s.sumPrice) as sumPrice " + "group by i.symbol " + "order by AGG_TIMESTAMP " + "insert all events into outputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
if (inEvents != null) {
EventPrinter.print(timestamp, inEvents, removeEvents);
for (Event event : inEvents) {
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
}
eventArrived = true;
}
}
});
InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
siddhiAppRuntime.start();
// Thursday, June 1, 2017 4:05:50 AM
stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, 1496289950000L });
stockStreamInputHandler.send(new Object[] { "WSO22", 75f, null, 40L, 10, 1496289950100L });
// Thursday, June 1, 2017 4:05:52 AM
stockStreamInputHandler.send(new Object[] { "WSO23", 60f, 44f, 200L, 56, 1496289952000L });
stockStreamInputHandler.send(new Object[] { "WSO24", 100f, null, 200L, 16, 1496289952000L });
// Thursday, June 1, 2017 4:05:50 AM - Out of order event
stockStreamInputHandler.send(new Object[] { "WSO23", 70f, null, 40L, 10, 1496289950090L });
// Thursday, June 1, 2017 4:05:54 AM
stockStreamInputHandler.send(new Object[] { "IBM", 101f, null, 200L, 26, 1496289954000L });
stockStreamInputHandler.send(new Object[] { "IBM1", 102f, null, 200L, 100, 1496289954000L });
// Thursday, June 1, 2017 4:05:56 AM
stockStreamInputHandler.send(new Object[] { "IBM", 900f, null, 200L, 60, 1496289956000L });
stockStreamInputHandler.send(new Object[] { "IBM1", 500f, null, 200L, 7, 1496289956000L });
Thread.sleep(100);
inputStreamInputHandler.send(new Object[] { "IBM" });
Thread.sleep(100);
SiddhiTestHelper.waitForEvents(100, 1, inEventCount, 10000);
AssertJUnit.assertTrue("Event arrived", eventArrived);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount.get());
AssertJUnit.assertTrue("In events matched", Arrays.equals(inEventsList.get(0), new Object[] { "WSO22", 1958.0 }));
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class SelectOptimisationAggregationTestCase method aggregationFunctionTestcase12.
@Test(dependsOnMethods = "aggregationFunctionTestcase11")
public void aggregationFunctionTestcase12() throws InterruptedException {
LOG.info("aggregationFunctionTestcase11: testing latest incremental aggregator - different select ");
SiddhiManager siddhiManager = new SiddhiManager();
String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);";
String query = "define aggregation stockAggregation " + "from stockStream " + "select symbol, sum(price) as sumPrice " + "group by symbol " + "aggregate by timestamp every sec...year ;" + "define stream inputStream (symbol string); " + "@info(name = 'query1') " + "from inputStream as i join stockAggregation as s " + "within 1496200000000L, 1596535449000L " + "per \"seconds\" " + "select i.symbol, sum(sumPrice) as totalPrice " + "group by i.symbol " + "order by AGG_TIMESTAMP " + "insert all events into outputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
if (inEvents != null) {
EventPrinter.print(timestamp, inEvents, removeEvents);
for (Event event : inEvents) {
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
}
eventArrived = true;
}
}
});
InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
siddhiAppRuntime.start();
// Thursday, June 1, 2017 4:05:50 AM
stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, 1496289950000L });
stockStreamInputHandler.send(new Object[] { "WSO22", 75f, null, 40L, 10, 1496289950100L });
// Thursday, June 1, 2017 4:05:52 AM
stockStreamInputHandler.send(new Object[] { "WSO23", 60f, 44f, 200L, 56, 1496289952000L });
stockStreamInputHandler.send(new Object[] { "WSO24", 100f, null, 200L, 16, 1496289952000L });
// Thursday, June 1, 2017 4:05:50 AM - Out of order event
stockStreamInputHandler.send(new Object[] { "WSO23", 70f, null, 40L, 10, 1496289950090L });
// Thursday, June 1, 2017 4:05:54 AM
stockStreamInputHandler.send(new Object[] { "IBM", 101f, null, 200L, 26, 1496289954000L });
stockStreamInputHandler.send(new Object[] { "IBM1", 102f, null, 200L, 100, 1496289954000L });
// Thursday, June 1, 2017 4:05:56 AM
stockStreamInputHandler.send(new Object[] { "IBM", 900f, null, 200L, 60, 1496289956000L });
stockStreamInputHandler.send(new Object[] { "IBM1", 500f, null, 200L, 7, 1496289956000L });
Thread.sleep(100);
inputStreamInputHandler.send(new Object[] { "IBM" });
Thread.sleep(100);
SiddhiTestHelper.waitForEvents(100, 1, inEventCount, 10000);
AssertJUnit.assertTrue("Event arrived", eventArrived);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount.get());
AssertJUnit.assertTrue("In events matched", Arrays.equals(inEventsList.get(0), new Object[] { "IBM", 1958.0 }));
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery66.
@Test
public void testFilterQuery66() throws InterruptedException {
log.info("Filter test66");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.not(Expression.compare(Expression.variable("volume"), Compare.Operator.EQUAL, Expression.value(40)))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
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.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50f, 60L });
inputHandler.send(new Object[] { "WSO2", 70f, 40L });
inputHandler.send(new Object[] { "WSO2", 44f, 200L });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery41.
@Test
public void testFilterQuery41() throws InterruptedException {
log.info("Filter test41");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "@info(name = 'query1') from cseEventStream[volume <= 40] 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);
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.5f, 40 });
inputHandler.send(new Object[] { "WSO2", 53.5f, 50 });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
siddhiAppRuntime.shutdown();
}
Aggregations