use of io.siddhi.core.event.Event in project siddhi by wso2.
the class JoinTestStoreTestCase method testTableJoinQuery6.
@Test
public void testTableJoinQuery6() throws InterruptedException, SQLException {
log.info("testTableJoinQuery6 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string); " + "@Store(type=\"testStoreContainingInMemoryTable\")\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 JoinTestStoreTestCase method testTableJoinQuery2.
@Test
public void testTableJoinQuery2() throws InterruptedException, SQLException {
log.info("testTableJoinQuery2 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string); " + "@Store(type=\"testStoreContainingInMemoryTable\")\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 CheckStockStream.symbol==StockTable.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(true, eventArrived, "Event arrived");
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class UpdateOrInsertTestStoreTestCase method updateOrInsertTableTest3.
@Test
public void updateOrInsertTableTest3() throws InterruptedException, SQLException {
log.info("updateOrInsertTableTest3");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume) in StockTable] " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query3", 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:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
break;
case 3:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
break;
default:
AssertJUnit.assertSame(3, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6F, 100L });
stockStream.send(new Object[] { "IBM", 55.6F, 100L });
checkStockStream.send(new Object[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
updateStockStream.send(new Object[] { "IBM", 77.6F, 200L });
checkStockStream.send(new Object[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class UpdateOrInsertTestStoreTestCase method updateOrInsertTableTest12.
@Test
public void updateOrInsertTableTest12() throws InterruptedException, SQLException {
log.info("updateOrInsertTableTest12");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update or insert into StockTable " + " on StockTable.volume == volume ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
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 });
updateStockStream.send(new Object[] { "GOOG", 10.6F, 200L });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
EventPrinter.print(events);
AssertJUnit.assertEquals(4, events.length);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class UpdateTestStoreTestCase method updateFromTableTest5.
@Test
public void updateFromTableTest5() throws InterruptedException, SQLException {
log.info("updateFromTableTest5");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\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[(StockTable.symbol==symbol) in StockTable] " + "insert into OutStream;";
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++;
}
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", 55.6f, 100L });
checkStockStream.send(new Object[] { "BSD", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
checkStockStream.send(new Object[] { "IBM", 100L });
Thread.sleep(1000);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations