use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class AggregationTestCase method incrementalStreamProcessorTest4.
@Test(dependsOnMethods = { "incrementalStreamProcessorTest3" })
public void incrementalStreamProcessorTest4() {
LOG.info("incrementalStreamProcessorTest4");
SiddhiManager siddhiManager = new SiddhiManager();
String stockStream = "" + " define stream stockStream (arrival long, symbol string, price float, volume int); ";
String query = "" + " @info(name = 'query3') " + " define aggregation stockAggregation " + " from stockStream " + " select sum(price) as sumPrice " + " group by price, volume " + " aggregate every sec, min, hour, day";
siddhiManager.createSiddhiAppRuntime(stockStream + query);
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class AggregationTestCase method incrementalStreamProcessorTest7.
@Test(dependsOnMethods = { "incrementalStreamProcessorTest6" })
public void incrementalStreamProcessorTest7() throws InterruptedException {
LOG.info("incrementalStreamProcessorTest7");
SiddhiManager siddhiManager = new SiddhiManager();
String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp string);";
String query = "" + "@BufferSize('3') " + "@IgnoreEventsOlderThanBuffer('true')" + "define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue " + "group by symbol " + "aggregate by timestamp every sec...year; " + "define stream inputStream (symbol string, value int, startTime string, " + "endTime string, perValue string); " + "@info(name = 'query1') " + "from inputStream as i join stockAggregation as s " + "on i.symbol == s.symbol " + "within \"2017-06-01 09:35:00 +05:30\", \"2017-06-01 10:37:57 +05:30\" " + "per i.perValue " + "select s.symbol, avgPrice, totalPrice as sumPrice, lastTradeValue " + "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;
}
if (removeEvents != null) {
EventPrinter.print(timestamp, inEvents, removeEvents);
for (Event event : removeEvents) {
removeEventsList.add(event.getData());
removeEventCount.incrementAndGet();
}
}
eventArrived = true;
}
});
InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
siddhiAppRuntime.start();
// Thursday, June 1, 2017 4:05:50 AM (add 5.30 to get corresponding IST time)
stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
// Thursday, June 1, 2017 4:05:51 AM
stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:51" });
// Thursday, June 1, 2017 4:05:52 AM
stockStreamInputHandler.send(new Object[] { "WSO2", 60f, 44f, 200L, 56, "2017-06-01 04:05:52" });
stockStreamInputHandler.send(new Object[] { "WSO2", 100f, null, 200L, 16, "2017-06-01 04:05:52" });
// Thursday, June 1, 2017 4:05:50 AM (out of order. must be processed with 1st event for 50th second)
stockStreamInputHandler.send(new Object[] { "WSO2", 70f, null, 40L, 10, "2017-06-01 04:05:50" });
// Thursday, June 1, 2017 4:05:54 AM
stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 26, "2017-06-01 04:05:54" });
stockStreamInputHandler.send(new Object[] { "IBM", 100f, null, 200L, 96, "2017-06-01 04:05:54" });
// Thursday, June 1, 2017 4:05:50 AM (out of order. should not be processed since events for 50th second is
// no longer in the buffer and @IgnoreEventsOlderThanBuffer is true)
stockStreamInputHandler.send(new Object[] { "IBM", 50f, 60f, 90L, 6, "2017-06-01 04:05:50" });
// Thursday, June 1, 2017 4:05:56 AM
stockStreamInputHandler.send(new Object[] { "IBM", 900f, null, 200L, 60, "2017-06-01 04:05:56" });
stockStreamInputHandler.send(new Object[] { "IBM", 500f, null, 200L, 7, "2017-06-01 04:05:56" });
// Thursday, June 1, 2017 4:06:56 AM
stockStreamInputHandler.send(new Object[] { "IBM", 400f, null, 200L, 9, "2017-06-01 04:06:56" });
// Thursday, June 1, 2017 4:07:56 AM
stockStreamInputHandler.send(new Object[] { "IBM", 600f, null, 200L, 6, "2017-06-01 04:07:56" });
// Thursday, June 1, 2017 5:07:56 AM
stockStreamInputHandler.send(new Object[] { "IBM", 700f, null, 200L, 20, "2017-06-01 05:07:56" });
Thread.sleep(100);
inputStreamInputHandler.send(new Object[] { "IBM", 1, "2017-06-01 09:35:51 +05:30", "2017-06-01 09:35:52 +05:30", "minutes" });
Thread.sleep(100);
List<Object[]> expected = Arrays.asList(new Object[] { "IBM", 330.0, 1650.0, 3500f }, new Object[] { "IBM", 400.0, 400.0, 3600f }, new Object[] { "IBM", 700.0, 700.0, 14000f }, new Object[] { "IBM", 600.0, 600.0, 3600f });
SiddhiTestHelper.waitForEvents(100, 4, inEventCount, 60000);
AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
AssertJUnit.assertEquals("Remove events matched", true, SiddhiTestHelper.isEventsMatch(removeEventsList, expected));
AssertJUnit.assertEquals("Number of success events", 4, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 4, removeEventCount.get());
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class AggregationTestCase method incrementalStreamProcessorTest15.
@Test(dependsOnMethods = { "incrementalStreamProcessorTest14" })
public void incrementalStreamProcessorTest15() {
LOG.info("incrementalStreamProcessorTest15");
SiddhiManager siddhiManager = new SiddhiManager();
String stockStream = "" + " define stream stockStream (arrival long, symbol string, price float, volume int); ";
String query = "" + " @info(name = 'query3') " + " define aggregation stockAggregation " + " from stockStream " + " select sum(price) as sumPrice " + " group by price " + " aggregate every sec, hour, day";
siddhiManager.createSiddhiAppRuntime(stockStream + query);
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class AggregationTestCase method incrementalStreamProcessorTest16.
@Test(dependsOnMethods = { "incrementalStreamProcessorTest15" }, expectedExceptions = SiddhiAppRuntimeException.class)
public void incrementalStreamProcessorTest16() throws InterruptedException {
LOG.info("incrementalStreamProcessorTest16");
SiddhiManager siddhiManager = new SiddhiManager();
String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp string);";
String query = "" + "@BufferSize('3') " + "define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, " + "(price * quantity) as lastTradeValue " + "group by symbol " + "aggregate by timestamp every sec...year ; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
siddhiAppRuntime.start();
// Thursday, June 1, 2017 4:05:50 AM
stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 60f, 90L, 6, "June 1, 2017 4:05:50 AM" });
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class AggregationTestCase method incrementalStreamProcessorTest21.
@Test(dependsOnMethods = { "incrementalStreamProcessorTest20" }, expectedExceptions = StoreQueryCreationException.class)
public void incrementalStreamProcessorTest21() throws InterruptedException {
LOG.info("incrementalStreamProcessorTest21");
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, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue " + "group by symbol " + "aggregate by timestamp every sec...hour ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
siddhiAppRuntime.start();
Thread.sleep(100);
Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2017-06-** **:**:**\" " + "per \"days\"");
EventPrinter.print(events);
Thread.sleep(100);
siddhiAppRuntime.shutdown();
}
Aggregations