use of org.wso2.siddhi.query.api.expression.condition.In 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 org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class LenghtBatchWindowTestCase method testLengthBatchWindow3.
@Test
public void testLengthBatchWindow3() throws InterruptedException {
log.info("Testing length batch window with no of events greater than window size");
final int length = 2;
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseWindow (symbol string, price float, volume int) lengthBatch(" + length + ") output " + "all events; ";
String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" + "@info(name = 'query2') from cseWindow insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
if ((count / length) % 2 == 1) {
removeEventCount++;
AssertJUnit.assertEquals("Remove event order", removeEventCount, event.getData(2));
if (removeEventCount == 1) {
AssertJUnit.assertEquals("Expired event triggering position", length, inEventCount);
}
} else {
inEventCount++;
AssertJUnit.assertEquals("In event order", inEventCount, event.getData(2));
}
count++;
}
AssertJUnit.assertEquals("No of emitted events at window expiration", inEventCount - length, removeEventCount);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(500);
AssertJUnit.assertEquals("In event count", 6, inEventCount);
AssertJUnit.assertEquals("Remove event count", 4, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class LenghtBatchWindowTestCase method testLengthBatchWindow2.
@Test
public void testLengthBatchWindow2() throws InterruptedException {
log.info("Testing length batch window with no of events greater than window size");
final int length = 4;
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseWindow (symbol string, price float, volume int) lengthBatch(" + length + "); ";
String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" + "@info(name = 'query2') from cseWindow insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count++;
AssertJUnit.assertEquals("In event order", count, event.getData(2));
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(500);
AssertJUnit.assertEquals("Total event count", 4, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class LenghtWindowTestCase method testLengthWindow2.
@Test
public void testLengthWindow2() throws InterruptedException {
log.info("Testing length window with no of events greater than window size");
final int length = 4;
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseWindow (symbol string, price float, volume int) length(" + length + ") output all " + "events; ";
String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" + "@info(name = 'query2') from cseWindow insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
eventArrived = true;
for (Event event : events) {
if (count >= length && count % 2 == 0) {
removeEventCount++;
AssertJUnit.assertEquals("Remove event order", removeEventCount, event.getData(2));
AssertJUnit.assertEquals("Expired event triggering position", inEventCount + 1, length + removeEventCount);
} else {
inEventCount++;
AssertJUnit.assertEquals("In event order", inEventCount, event.getData(2));
}
count++;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(500);
AssertJUnit.assertEquals("In event count", 6, inEventCount);
AssertJUnit.assertEquals("Remove event count", 2, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class LenghtWindowTestCase method testLengthWindow3.
@Test
public void testLengthWindow3() throws InterruptedException {
log.info("Testing length window with no of events greater than window size");
final int length = 4;
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseWindow (symbol string, price float, volume int) length(" + length + ") output all " + "events; ";
String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" + "@info(name = 'query2') from cseWindow insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + 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) {
if (event.isExpired()) {
removeEventCount++;
} else {
inEventCount++;
}
}
}
if (removeEvents != null) {
for (Event event : removeEvents) {
if (event.isExpired()) {
removeEventCount++;
} else {
inEventCount++;
}
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(500);
AssertJUnit.assertEquals("In event count", 6, inEventCount);
AssertJUnit.assertEquals("Remove event count", 2, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations