use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class SetUpdateOrInsertInMemoryTableTestCase method updateFromTableTest5.
@Test
public void updateFromTableTest5() throws InterruptedException, SQLException {
log.info("SET-InMemory-update-or-insert test case 5: assignment expression containing an output attribute " + "with a basic arithmatic operation.");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "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 " + "set StockTable.price = price + 100 " + " on StockTable.symbol == symbol ;";
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[] { "IBM", 100f, 100L });
Thread.sleep(1000);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class SetUpdateOrInsertInMemoryTableTestCase method updateFromTableTest4.
@Test
public void updateFromTableTest4() throws InterruptedException, SQLException {
log.info("SET-InMemory-update-or-insert test case 4: using one of the output attribute values in the " + "select clause as the assignment expression.");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "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 price, symbol, volume " +
"update or insert into StockTable " + "set StockTable.price = price + 100 " + " on StockTable.symbol == symbol ;";
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[] { "IBM", 100f, 100L });
Thread.sleep(1000);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class InTestStoreTestCase method insertIntoTestStoreTest1.
@Test
public void insertIntoTestStoreTest1() throws InterruptedException, SQLException {
// Configure siddhi to insert events data to table only from specific fields of the stream.
log.info("insertIntoTestStoreTest1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckInStockStream (symbol string); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, volume long); ";
String query1 = "" + "@info(name = 'query1') " + "from StockStream\n" + "select symbol, volume\n" + "insert into StockTable ;";
String query2 = "" + "@info(name = 'query2') " + "from CheckInStockStream[StockTable.symbol == symbol in StockTable]\n" + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query1 + query2);
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" });
break;
}
}
eventArrived = true;
}
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkInStockStream = siddhiAppRuntime.getInputHandler("CheckInStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
checkInStockStream.send(new Object[] { "WSO2" });
Assert.assertEquals(true, eventArrived, "Event arrived");
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class JoinTestStoreTestCase method testTableJoinQuery8.
@Test
public void testTableJoinQuery8() throws InterruptedException, SQLException {
log.info("testTableJoinQuery8 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float); " + "define stream CheckStockStream (symbol string); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, price float); ";
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 " + "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" });
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 });
stockStream.send(new Object[] { "IBM", 75.6f });
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.SiddhiManager in project siddhi by wso2.
the class JoinTestStoreTestCase method testTableJoinQuery9.
@Test
public void testTableJoinQuery9() throws InterruptedException, SQLException {
log.info("testTableJoinQuery9 - OUT 2");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "@connection(maxWait = '4000')" + "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 " + "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;
case 2:
Assert.assertEquals(event.getData(), new Object[] { "WSO2", "IBM", 10L });
break;
default:
Assert.assertSame(inEventCount, 2);
}
}
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, 2, "Number of success events");
Assert.assertEquals(removeEventCount, 0, "Number of remove events");
Assert.assertEquals(eventArrived, true, "Event arrived");
siddhiAppRuntime.shutdown();
}
Aggregations