use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class SimpleQueryValidatorTestCase method testQueryWithAggregation.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithAggregation() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String tables = "define stream TradeStream (symbol string, price double, volume long, timestamp long);\n" + "define aggregation TradeAggregation\n" + " from TradeStream\n" + " select symbol, avg(price) as avgPrice, sum(price) as total\n" + " group by symbol\n" + " aggregate by symbol every sec ... year; " + "" + "from every TradeAggregation \n" + "select * \n" + "insert into OutputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class SimpleQueryValidatorTestCase method testQueryWithEveryAggregation.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithEveryAggregation() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String tables = "define stream TradeStream (symbol string, price double, volume long, timestamp long);\n" + "define aggregation TradeAggregation\n" + " from TradeStream\n" + " select symbol, avg(price) as avgPrice, sum(price) as total\n" + " group by symbol\n" + " aggregate by symbol every sec ... year; " + "" + "from every TradeAggregation " + "select * " + "insert into OutputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class PersistenceTestCase method persistenceTest7.
@Test(dependsOnMethods = "persistenceTest6")
public void persistenceTest7() throws InterruptedException {
log.info("persistence test 7 - external time window with group by 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 int, timestamp long);" + "" + "@info(name = 'query1')" + "from StockStream#window.externalTime(timestamp,3 sec) " + "select symbol, price, sum(volume) as totalVol, timestamp " + "group by symbol " + "insert into OutStream ";
QueryCallback queryCallback = new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
for (Event inEvent : inEvents) {
count++;
AssertJUnit.assertTrue("IBM".equals(inEvent.getData(0)) || "WSO2".equals(inEvent.getData(0)));
if (count == 5) {
AssertJUnit.assertEquals(300L, inEvent.getData(2));
}
if (count == 6) {
AssertJUnit.assertEquals(100L, inEvent.getData(2));
}
}
}
};
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", queryCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
long currentTime = 0;
inputHandler.send(new Object[] { "IBM", 75.1f, 100, currentTime + 1000 });
Thread.sleep(100);
inputHandler.send(new Object[] { "WSO2", 75.2f, 100, currentTime + 2000 });
Thread.sleep(100);
inputHandler.send(new Object[] { "IBM", 75.3f, 100, currentTime + 3000 });
Thread.sleep(500);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(3, count);
// persisting
Thread.sleep(500);
siddhiAppRuntime.persist();
// restarting siddhi app
Thread.sleep(500);
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.4f, 100, currentTime + 4000 });
Thread.sleep(100);
inputHandler.send(new Object[] { "IBM", 75.5f, 100, currentTime + 5000 });
Thread.sleep(100);
inputHandler.send(new Object[] { "WSO2", 75.6f, 100, currentTime + 6000 });
// shutdown siddhi app
Thread.sleep(500);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(count, 6);
AssertJUnit.assertEquals(true, eventArrived);
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class PersistenceTestCase method persistenceTest13.
@Test
public void persistenceTest13() throws InterruptedException {
log.info("Persistence test 13 - partitioned sum with group-by on length windows.");
final int inputEventCount = 10;
PersistenceStore persistenceStore = new InMemoryPersistenceStore();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setPersistenceStore(persistenceStore);
String siddhiApp = "@app:name('incrementalPersistenceTest10') " + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "partition with (price>=100 as 'large' or price<100 as 'small' of cseEventStreamOne) " + "begin @info(name " + "= 'query1') from cseEventStreamOne#window.length(4) select symbol,sum(price) as price " + "group by symbol insert into " + "OutStockStream ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
if (events != null) {
for (Event event : events) {
count++;
lastValue = ((Double) event.getData(1)).longValue();
}
}
}
};
siddhiAppRuntime.addCallback("OutStockStream", streamCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
siddhiAppRuntime.start();
for (int i = 0; i < inputEventCount; i++) {
inputHandler.send(new Object[] { "IBM", 95f + i, 100 });
Thread.sleep(100);
siddhiAppRuntime.persist();
}
inputHandler.send(new Object[] { "IBM", 205f, 100 });
Thread.sleep(100);
siddhiAppRuntime.shutdown();
siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", streamCallback);
inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
siddhiAppRuntime.start();
Thread.sleep(1000);
// loading
try {
siddhiAppRuntime.restoreLastRevision();
} catch (CannotRestoreSiddhiAppStateException e) {
Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
}
Thread.sleep(1000);
inputHandler.send(new Object[] { "IBM", 105f, 100 });
Thread.sleep(1000);
AssertJUnit.assertEquals(new Long(414), lastValue);
siddhiAppRuntime.shutdown();
}
use of org.wso2.charon.core.objects.Group in project siddhi by wso2.
the class AggregationTestCase method incrementalStreamProcessorTest36.
@Test(dependsOnMethods = { "incrementalStreamProcessorTest35" }, expectedExceptions = StoreQueryCreationException.class)
public void incrementalStreamProcessorTest36() throws InterruptedException {
LOG.info("incrementalStreamProcessorTest36");
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 1513578087000L " + "per \"hours\"");
EventPrinter.print(events);
Thread.sleep(100);
siddhiAppRuntime.shutdown();
}
Aggregations