use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class LossyFrequentWindowTestCase method frequentUniqueWindowTest3.
@Test
public void frequentUniqueWindowTest3() throws InterruptedException {
log.info("LossyFrequentWindow test3");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream purchase (cardNo string, price float); " + "define window purchaseWindow (cardNo string, price float) lossyFrequent(0.3,0.05,cardNo); ";
String query = "" + "@info(name = 'query0') " + "from purchase[price >= 30] " + "insert into purchaseWindow; " + "" + "@info(name = 'query1') " + "from purchaseWindow " + "select cardNo, price " + "insert all events into PotentialFraud ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += inEvents.length;
}
if (removeEvents != null) {
removeEventCount += removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("purchase");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "3224-3244-2432-4124", 73.36f });
for (int i = 0; i < 25; i++) {
inputHandler.send(new Object[] { "3234-3244-2432-4124", 73.36f });
inputHandler.send(new Object[] { "3234-3244-2432-4124", 78.36f });
inputHandler.send(new Object[] { "1234-3244-2432-123", 86.36f });
// this event will be included because we
inputHandler.send(new Object[] { "3234-3244-2432-4124", 48.36f });
// only consider cardNo
}
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("In Event count", 101, inEventCount);
AssertJUnit.assertEquals("Out Event count", 1, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class LossyFrequentWindowTestCase method testLossyFrequentUniqueWindow1.
@Test
public void testLossyFrequentUniqueWindow1() throws InterruptedException {
log.info("LossyFrequentWindow test1");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream purchase (cardNo string, price float); " + "define window purchaseWindow (cardNo string, price float) lossyFrequent(0.1,0.01); ";
String query = "" + "@info(name = 'query0') " + "from purchase[price >= 30] " + "insert into purchaseWindow; " + "" + "@info(name = 'query1') " + "from purchaseWindow " + "select cardNo, price " + "insert all events into PotentialFraud ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += inEvents.length;
}
if (removeEvents != null) {
removeEventCount += removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("purchase");
siddhiAppRuntime.start();
for (int i = 0; i < 25; i++) {
inputHandler.send(new Object[] { "3234-3244-2432-4124", 73.36f });
inputHandler.send(new Object[] { "1234-3244-2432-123", 46.36f });
inputHandler.send(new Object[] { "5768-3244-2432-5646", 48.36f });
inputHandler.send(new Object[] { "9853-3244-2432-4125", 78.36f });
}
// these events will not be picked
inputHandler.send(new Object[] { "1124-3244-2432-4126", 78.36f });
inputHandler.send(new Object[] { "1124-3244-2432-4126", 78.36f });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("In Event count", 100, inEventCount);
AssertJUnit.assertEquals("Out Event count", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class TimeBatchWindowTestCase method timeWindowBatchTest8.
@Test
public void timeWindowBatchTest8() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseEventWindow (symbol string, price float, volume int) timeBatch(2 sec , 0); ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from cseEventWindow " + "select symbol, sum(price) as sumPrice, volume " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEventCount == 0) {
AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents == null);
}
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
} else if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
// Start sending events in the beginning of a cycle
while (System.currentTimeMillis() % 2000 != 0) {
}
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(8500);
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
inputHandler.send(new Object[] { "II", 60.5f, 1 });
Thread.sleep(13000);
inputHandler.send(new Object[] { "TT", 60.5f, 1 });
inputHandler.send(new Object[] { "YY", 60.5f, 1 });
Thread.sleep(5000);
AssertJUnit.assertEquals(3, inEventCount);
AssertJUnit.assertEquals(0, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class TimeLengthWindowTestCase method testTimeLengthWindow10.
/*
Time Period < Window time
Number of Events > Window length
*/
@Test
public void testTimeLengthWindow10() throws InterruptedException {
log.info("Testing timeLength window with no of events greater than window length and time period less than " + "window time");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseEventWindow (symbol string, price float, volume int) timeLength(10 sec,5); ";
String query = "@info(name = 'query0') from cseEventStream " + "insert into cseEventWindow; " + "@info(name = 'query1') from cseEventWindow " + " select symbol,volume" + " insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("query1", 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, 10 });
Thread.sleep(500);
inputHandler.send(new Object[] { "WSO2", 60.5f, 20 });
Thread.sleep(500);
inputHandler.send(new Object[] { "IBM", 700f, 20 });
Thread.sleep(500);
inputHandler.send(new Object[] { "WSO2", 60.5f, 40 });
Thread.sleep(500);
inputHandler.send(new Object[] { "IBM", 700f, 50 });
Thread.sleep(500);
inputHandler.send(new Object[] { "WSO2", 60.5f, 60 });
Thread.sleep(500);
inputHandler.send(new Object[] { "IBM", 700f, 70 });
Thread.sleep(500);
inputHandler.send(new Object[] { "WSO2", 60.5f, 80 });
Thread.sleep(5000);
AssertJUnit.assertEquals("In event count", 8, inEventCount);
AssertJUnit.assertEquals("Remove event count", 3, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class IndexTableTestCase method indexTableTest4.
@Test
public void indexTableTest4() throws InterruptedException {
log.info("indexTableTest4");
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", 200L });
List<Object[]> expected = Arrays.asList(new Object[] { "IBM", "ABC", 70L }, new Object[] { "IBM", "GOOG", 50L });
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();
}
}
Aggregations