use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class TimeLengthWindowTestCase method testTimeLengthWindow3.
/*
Time Period < Window time
Number of Events > Window length
*/
@Test
public void testTimeLengthWindow3() 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 sensorStream = "define stream sensorStream (id string, sensorValue float); " + "define window sensorWindow (id string, sensorValue float) timeLength(10 sec,4); ";
String query = "@info(name = 'query0') from sensorStream " + "insert into sensorWindow; " + "@info(name = 'query1') from sensorWindow " + " select id,sensorValue" + " insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(sensorStream + 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 = inEventCount + inEvents.length;
}
if (removeEvents != null) {
AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("sensorStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "id1", 10d });
Thread.sleep(500);
inputHandler.send(new Object[] { "id2", 20d });
Thread.sleep(500);
inputHandler.send(new Object[] { "id3", 30d });
Thread.sleep(500);
inputHandler.send(new Object[] { "id4", 40d });
Thread.sleep(500);
inputHandler.send(new Object[] { "id5", 50d });
Thread.sleep(500);
inputHandler.send(new Object[] { "id6", 60d });
Thread.sleep(500);
inputHandler.send(new Object[] { "id7", 70d });
Thread.sleep(500);
inputHandler.send(new Object[] { "id8", 80d });
Thread.sleep(2000);
AssertJUnit.assertEquals(8, inEventCount);
AssertJUnit.assertEquals(4, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.window.Window 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.core.window.Window in project siddhi by wso2.
the class TimeWindowTestCase method testTimeWindow1.
@Test
public void testTimeWindow1() throws InterruptedException {
log.info("TimeWindow Test1");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseEventWindow (symbol string, price float, volume int) time(2 sec) output all events; ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from cseEventWindow " + "select symbol,price,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) {
inEventCount = inEventCount + inEvents.length;
}
if (removeEvents != null) {
AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount);
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(4000);
AssertJUnit.assertEquals(2, inEventCount);
AssertJUnit.assertEquals(2, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class WindowDefinitionTestCase method testEventWindow6.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testEventWindow6() throws InterruptedException {
log.info("WindowDefinitionTestCase Test6");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "define window CheckStockWindow(symbol string, val int) sum(val); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class WindowDefinitionTestCase method testEventWindow5.
@Test(expectedExceptions = SiddhiParserException.class)
public void testEventWindow5() throws InterruptedException {
log.info("WindowDefinitionTestCase Test5");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "define window CheckStockWindow(symbol string) length(1) output; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
siddhiAppRuntime.shutdown();
}
Aggregations