use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class UpdateOrInsertTableWithCacheTestCase method updateOrInsertTableTest5.
@Test(expectedExceptions = DuplicateDefinitionException.class, enabled = false)
public void updateOrInsertTableTest5() throws InterruptedException, SQLException {
log.info("updateOrInsertTableTest5");
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 (comp string, vol long); " + "@Store(type=\"testStoreContainingInMemoryTable\", @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 UpdateStockStream " + "select comp as symbol, vol as volume " + "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[] { "FB", 300L }, event.getData());
break;
case 4:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
break;
default:
AssertJUnit.assertSame(4, 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[] { "FB", 300L });
checkStockStream.send(new Object[] { "FB", 300L });
checkStockStream.send(new Object[] { "WSO2", 100L });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 4, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", false, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class UpdateTableWithCacheTestCase method updateFromTableTest3.
@Test
public void updateFromTableTest3() throws InterruptedException, SQLException {
log.info("updateFromTableTest3");
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\", @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[(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[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
checkStockStream.send(new Object[] { "IBM", 100L });
Thread.sleep(1000);
AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class UpdateTableWithCacheTestCase method updateFromTableTest7.
@Test
public void updateFromTableTest7() throws InterruptedException, SQLException {
log.info("updateFromTableTest7");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (comp string, prc float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\", @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 UpdateStockStream " + "select comp as symbol, prc as price, volume " + "update StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume " + "and price<StockTable.price) 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", 150.6f, 100L }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 190.6f, 100L }, event.getData());
break;
default:
AssertJUnit.assertSame(2, 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", 185.6f, 100L });
checkStockStream.send(new Object[] { "IBM", 150.6f, 100L });
checkStockStream.send(new Object[] { "WSO2", 175.6f, 100L });
updateStockStream.send(new Object[] { "IBM", 200f, 100L });
checkStockStream.send(new Object[] { "IBM", 190.6f, 100L });
checkStockStream.send(new Object[] { "WSO2", 155.6f, 100L });
Thread.sleep(2000);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class UpdateTableWithCacheTestCase method updateFromTableTest2.
@Test
public void updateFromTableTest2() throws InterruptedException, SQLException {
// Check for update event data in cache table when multiple conditions are true.
log.info("updateFromTableTest2");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price double, volume long); " + "define stream UpdateStockStream (symbol string, price double, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price double, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update StockTable " + " on (StockTable.symbol == symbol and 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.6, 50L });
stockStream.send(new Object[] { "IBM", 75.6, 100L });
stockStream.send(new Object[] { "WSO2", 57.6, 200L });
updateStockStream.send(new Object[] { "WSO2", 85.6, 100L });
Thread.sleep(1000);
Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
EventPrinter.print(events);
AssertJUnit.assertEquals(3, events.length);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class UpdateTableWithCacheTestCase method updateFromTableTest4.
@Test
public void updateFromTableTest4() throws InterruptedException, SQLException {
log.info("updateFromTableTest4");
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\", @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[(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[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
checkStockStream.send(new Object[] { "IBM", 100L });
Thread.sleep(1000);
AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations