use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class IndexTableTestCase method indexTableTest20.
@Test
public void indexTableTest20() throws InterruptedException {
log.info("indexTableTest20");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define stream DeleteStockStream (symbol string, price float, volume long);" + "@Index('volume') " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream " + "delete StockTable " + " on StockTable.volume <= volume;" + "" + "@info(name = 'query3') " + "from CheckStockStream join StockTable " + "select StockTable.symbol, StockTable.volume " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
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) {
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 200L });
stockStream.send(new Object[] { "BAR", 55.6f, 150L });
stockStream.send(new Object[] { "IBM", 55.6f, 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
deleteStockStream.send(new Object[] { "IBM", 77.6f, 150L });
checkStockStream.send(new Object[] { "FOO", 100L });
List<Object[]> expected1 = Arrays.asList(new Object[] { "IBM", 100L }, new Object[] { "BAR", 150L }, new Object[] { "WSO2", 200L });
List<Object[]> expected2 = new ArrayList<Object[]>();
expected2.add(new Object[] { "WSO2", 200L });
SiddhiTestHelper.waitForEvents(100, 4, inEventCount, 60000);
AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList.subList(0, 3), expected1));
AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList.subList(3, 4), expected2));
AssertJUnit.assertEquals("Number of success events", 4, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class IndexTableTestCase method indexTableTest6.
@Test
public void indexTableTest6() throws InterruptedException {
log.info("indexTableTest6");
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);" + "@Index('volume') " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream join StockTable " + " on StockTable.volume > CheckStockStream.volume " + "select CheckStockStream.symbol, StockTable.symbol as tableSymbol, StockTable.volume " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
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) {
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
}
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, 200L });
stockStream.send(new Object[] { "GOOG", 50.6f, 50L });
stockStream.send(new Object[] { "ABC", 5.6f, 70L });
checkStockStream.send(new Object[] { "IBM", 50L });
List<Object[]> expected = Arrays.asList(new Object[] { "IBM", "WSO2", 200L }, new Object[] { "IBM", "ABC", 70L });
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList, expected));
AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class IndexTableTestCase method indexTableTest9.
// Update Test
@Test
public void indexTableTest9() throws InterruptedException {
log.info("indexTableTest9");
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);" + "@Index('symbol') " + "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.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream join StockTable " + " on CheckStockStream.symbol==StockTable.symbol " + "select CheckStockStream.symbol, StockTable.volume " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
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) {
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
}
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 });
List<Object[]> expected = Arrays.asList(new Object[] { "IBM", 100L }, new Object[] { "WSO2", 100L }, new Object[] { "IBM", 200L }, new Object[] { "WSO2", 100L });
SiddhiTestHelper.waitForEvents(100, 4, inEventCount, 60000);
AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
AssertJUnit.assertEquals("Number of success events", 4, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class IndexTableTestCase method indexTableTest28.
@Test
public void indexTableTest28() throws InterruptedException {
log.info("indexTableTest28");
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);" + "@PrimaryKey('symbol') " + "@Index('price','volume') " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream join StockTable " + " on CheckStockStream.symbol==StockTable.symbol " + "select CheckStockStream.symbol, StockTable.volume " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
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) {
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
}
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", 55.6f, 100L });
checkStockStream.send(new Object[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
List<Object[]> expected = Arrays.asList(new Object[] { "IBM", 100L }, new Object[] { "WSO2", 100L });
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class IndexTableTestCase method indexTableTest1.
@Test
public void indexTableTest1() throws InterruptedException {
log.info("indexTableTest1");
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);" + "@Index('symbol') " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream join StockTable " + " on CheckStockStream.symbol==StockTable.symbol " + "select CheckStockStream.symbol, StockTable.volume " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
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) {
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
}
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", 55.6f, 100L });
checkStockStream.send(new Object[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
List<Object[]> expected = Arrays.asList(new Object[] { "IBM", 100L }, new Object[] { "WSO2", 100L });
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get());
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
Aggregations