use of io.siddhi.core.SiddhiManager 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.SiddhiManager 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();
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class UpdateTestStoreTestCase 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\")\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 UpdateTestStoreTestCase method updateFromTableTest8.
@Test
public void updateFromTableTest8() throws InterruptedException, SQLException {
log.info("updateFromTableTest8");
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 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[] { "IBM", 57.6f, 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 TriggerTestCase method testQuery1.
@Test
public void testQuery1() throws InterruptedException {
log.info("testTrigger1 - OUT 0");
SiddhiManager siddhiManager = new SiddhiManager();
TriggerDefinition triggerDefinition = TriggerDefinition.id("cseEventStream").atEvery(Expression.Time.milliSec(500));
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineTrigger(triggerDefinition);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.shutdown();
}
Aggregations