use of org.wso2.siddhi.query.api.execution.query.input.handler.Window in project siddhi by wso2.
the class LenghtBatchWindowTestCase method testLengthBatchWindow6.
@Test
public void testLengthBatchWindow6() throws InterruptedException {
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(4); ";
String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow; " + "@info(name = 'query2') from cseWindow " + "select symbol,sum(price) as sumPrice,volume " + "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) {
AssertJUnit.assertEquals("Events cannot be expired", false, event.isExpired());
inEventCount++;
if (inEventCount == 1) {
AssertJUnit.assertEquals(100.0, event.getData(1));
} else if (inEventCount == 2) {
AssertJUnit.assertEquals(240.0, event.getData(1));
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 10f, 0 });
inputHandler.send(new Object[] { "WSO2", 20f, 1 });
inputHandler.send(new Object[] { "IBM", 30f, 0 });
inputHandler.send(new Object[] { "WSO2", 40f, 1 });
inputHandler.send(new Object[] { "IBM", 50f, 0 });
inputHandler.send(new Object[] { "WSO2", 60f, 1 });
inputHandler.send(new Object[] { "WSO2", 60f, 1 });
inputHandler.send(new Object[] { "IBM", 70f, 0 });
inputHandler.send(new Object[] { "WSO2", 80f, 1 });
Thread.sleep(500);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(2, inEventCount);
AssertJUnit.assertTrue(eventArrived);
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.Window in project siddhi by wso2.
the class LenghtBatchWindowTestCase method testLengthBatchWindow9.
@Test
public void testLengthBatchWindow9() throws InterruptedException {
log.info("LengthBatchWindow Test9");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); " + "define window cseEventWindow (symbol string, price float, volume int) lengthBatch(2); " + "define window twitterWindow (user string, tweet string, company string) lengthBatch(2); ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from twitterStream " + "insert into twitterWindow; " + "" + "@info(name = 'query2') " + "from cseEventWindow join twitterWindow " + "on cseEventWindow.symbol == twitterWindow.company " + "select cseEventWindow.symbol as symbol, twitterWindow.tweet, cseEventWindow.price " + "insert into outputStream ;";
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) {
inEventCount += (inEvents.length);
}
if (removeEvents != null) {
removeEventCount += (removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
cseEventStreamHandler.send(new Object[] { "IBM", 59.6f, 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(500);
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(1000);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertEquals(0, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.Window in project siddhi by wso2.
the class LenghtBatchWindowTestCase method testLengthBatchWindow7.
@Test
public void testLengthBatchWindow7() throws InterruptedException {
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(4); ";
String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow; " + "@info(name = 'query2') from cseWindow " + "select symbol,sum(price) as sumPrice,volume " + "insert 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);
AssertJUnit.assertEquals("Events cannot be expired", false, removeEvents != null);
for (Event event : inEvents) {
inEventCount++;
if (inEventCount == 1) {
AssertJUnit.assertEquals(100.0, event.getData(1));
} else if (inEventCount == 2) {
AssertJUnit.assertEquals(240.0, event.getData(1));
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 10f, 0 });
inputHandler.send(new Object[] { "WSO2", 20f, 1 });
inputHandler.send(new Object[] { "IBM", 30f, 0 });
inputHandler.send(new Object[] { "WSO2", 40f, 1 });
inputHandler.send(new Object[] { "IBM", 50f, 0 });
inputHandler.send(new Object[] { "WSO2", 60f, 1 });
inputHandler.send(new Object[] { "WSO2", 60f, 1 });
inputHandler.send(new Object[] { "IBM", 70f, 0 });
inputHandler.send(new Object[] { "WSO2", 80f, 1 });
Thread.sleep(500);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(2, inEventCount);
AssertJUnit.assertTrue(eventArrived);
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.Window 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.execution.query.input.handler.Window 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