use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.
the class PassThroughTestCase method passThroughTest4.
@Test
public void passThroughTest4() throws InterruptedException {
log.info("pass through test4");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('passThroughTest4') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "insert into outputStream;" + "" + "@info(name = 'query2') " + "from outputStream " + "select * " + "insert into outputStream2 ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
log.info("Running : " + siddhiAppRuntime.getName());
QueryCallback queryCallback = new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
AssertJUnit.assertTrue("WSO2".equals(inEvents[0].getData(0)));
count = count + inEvents.length;
eventArrived = true;
}
};
siddhiAppRuntime.addCallback("query2", queryCallback);
queryCallback.startProcessing();
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 700f, 100L });
inputHandler.send(new Object[] { "WSO2", 60.5f, 200L });
Thread.sleep(100);
AssertJUnit.assertEquals(2, count);
AssertJUnit.assertTrue(eventArrived);
queryCallback.stopProcessing();
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream 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.siddhi.query.api.execution.query.output.stream.OutputStream 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.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.
the class SimpleQueryValidatorTestCase method testQueryWithEveryTable.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithEveryTable() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String tables = "define table TestTable(symbol string, volume float);\n" + "" + "from every TestTable " + "select * " + "insert into OutputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream in project siddhi by wso2.
the class TestDebugger method testDebugger4.
@Test
public void testDebugger4() throws InterruptedException {
log.info("Siddi Debugger Test 4: Test next traversal in a query with time batch window where next call delays" + " 1 sec");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
final String query = "@info(name = 'query1')" + "from cseEventStream#window.timeBatch(1 sec) " + "select symbol, price, volume " + "insert into OutputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
inEventCount.addAndGet(events.length);
AssertJUnit.assertEquals("Cannot emit all three in one time", 1, events.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {
@Override
public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
log.info(event);
int count = debugEventCount.addAndGet(getCount(event));
if (count != 1 && queryTerminal == SiddhiDebugger.QueryTerminal.IN) {
try {
Thread.sleep(1100);
} catch (InterruptedException e) {
}
}
// next call will not reach OUT since there is a window
debugger.next();
}
});
inputHandler.send(new Object[] { "WSO2", 50f, 60 });
inputHandler.send(new Object[] { "WSO2", 70f, 40 });
inputHandler.send(new Object[] { "WSO2", 60f, 50 });
Thread.sleep(1500);
AssertJUnit.assertEquals("Invalid number of output events", 3, inEventCount.get());
AssertJUnit.assertEquals("Invalid number of debug events", 3, debugEventCount.get());
siddhiAppRuntime.shutdown();
}
Aggregations