use of io.siddhi.core.event.Event in project siddhi by wso2.
the class JoinTableWithCacheTestCase method testTableJoinQuery5.
@Test
public void testTableJoinQuery5() throws InterruptedException, SQLException {
log.info("testTableJoinQuery5 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream#window.length(1) join StockTable as s " + " on CheckStockStream.symbol==s.symbol " + "select CheckStockStream.symbol as checkSymbol, s.symbol as symbol, s.volume as volume " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query2", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
Assert.assertEquals(event.getData(), new Object[] { "WSO2", "WSO2", 100L });
break;
default:
Assert.assertSame(inEventCount, 1);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 10L });
checkStockStream.send(new Object[] { "WSO2" });
Thread.sleep(1000);
Assert.assertEquals(inEventCount, 1, "Number of success events");
Assert.assertEquals(removeEventCount, 0, "Number of remove events");
Assert.assertEquals(eventArrived, true, "Event arrived");
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class JoinTableWithCacheTestCase method testTableJoinQuery7.
@Test
public void testTableJoinQuery7() throws InterruptedException, SQLException {
log.info("testTableJoinQuery7 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream#window.length(1) join StockTable " + " on StockTable.symbol==CheckStockStream.symbol " + "select CheckStockStream.symbol as checkSymbol, StockTable.symbol as symbol, " + "StockTable.volume as volume " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query2", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
Assert.assertEquals(event.getData(), new Object[] { "WSO2", "WSO2", 100L });
break;
default:
Assert.assertSame(inEventCount, 1);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 10L });
checkStockStream.send(new Object[] { "WSO2" });
Thread.sleep(1000);
Assert.assertEquals(inEventCount, 1, "Number of success events");
Assert.assertEquals(removeEventCount, 0, "Number of remove events");
Assert.assertEquals(eventArrived, true, "Event arrived");
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test6.
@Test(expectedExceptions = SiddhiParserException.class)
public void test6() {
log.info("Test6 table with cache");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
try {
siddhiAppRuntime.start();
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol1, sum(volume) totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData(1));
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test9.
@Test
public void test9() throws InterruptedException {
log.info("Test9 table with cache");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on volume > 10 " + "select symbol, price, volume " + "order by price " + "limit 2 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(2, events.length);
AssertJUnit.assertEquals(55.6F, events[0].getData()[1]);
AssertJUnit.assertEquals(57.6f, events[1].getData()[1]);
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test5.
@Test(expectedExceptions = StoreQueryCreationException.class)
public void test5() {
log.info("Test5 table with cache");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
try {
siddhiAppRuntime.start();
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol1, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData(1));
} finally {
siddhiAppRuntime.shutdown();
}
}
Aggregations