use of org.wso2.siddhi.query.api.execution.query.input.handler.Window in project siddhi by wso2.
the class WindowDefinitionTestCase method testEventWindow7.
@Test(expectedExceptions = SiddhiParserException.class)
public void testEventWindow7() throws InterruptedException {
log.info("WindowDefinitionTestCase Test7");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "define window CheckStockWindow(symbol string) output; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.Window in project siddhi by wso2.
the class WindowDefinitionTestCase method testEventWindow4.
@Test
public void testEventWindow4() throws InterruptedException {
log.info("WindowDefinitionTestCase Test4");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "define window CheckStockWindow(symbol string) length(1) output current events; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
assertTrue(true);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.Window in project siddhi by wso2.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest13.
@Test
public void externalTimeBatchWindowTest13() throws InterruptedException {
log.info("externalTimeBatchWindow Test13");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " + "define stream twitterStream (timestamp long, user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.externalTimeBatch(timestamp, 1 sec, 0) join twitterStream#window" + ".externalTimeBatch(timestamp, 1 sec, 0) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
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 cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { 1366335804341L, "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { 1366335804341L, "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { 1366335805301L, "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { 1366335805341L, "WSO2", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { 1366335806541L, "WSO2", 57.6f, 100 });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals(2, inEventCount);
org.testng.AssertJUnit.assertEquals(1, removeEventCount);
org.testng.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 ExternalTimeBatchWindowTestCase method test05EdgeCase.
@Test
public void test05EdgeCase() throws Exception {
siddhiManager = new SiddhiManager();
// every 10 sec
SiddhiAppRuntime runtime = simpleQueryRuntime();
final AtomicInteger recCount = new AtomicInteger(0);
runtime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
AssertJUnit.assertEquals(1, inEvents.length);
recCount.incrementAndGet();
double avgCpu = (Double) inEvents[0].getData()[0];
if (recCount.get() == 1) {
AssertJUnit.assertEquals(15, avgCpu, 0);
} else if (recCount.get() == 2) {
AssertJUnit.assertEquals(85, avgCpu, 0);
}
long count = (Long) inEvents[0].getData()[1];
AssertJUnit.assertEquals(3, count);
}
});
InputHandler input = runtime.getInputHandler("jmxMetric");
runtime.start();
// external events' time stamp less than the window, should not have event recieved in call back.
long now = 0;
int length = 3;
for (int i = 0; i < length; i++) {
input.send(new Object[] { 15, now + i * 10 });
}
// if the trigger event mix with the last window, we should see the avgValue is not expected
for (int i = 0; i < length; i++) {
// the first entity of the second round
input.send(new Object[] { 85, now + 10000 + i * 10 });
}
// to trigger second round
input.send(new Object[] { 10000, now + 10 * 10000 });
// latch.await();// for debug
Thread.sleep(1000);
AssertJUnit.assertEquals(2, recCount.get());
}
use of org.wso2.siddhi.query.api.execution.query.input.handler.Window in project siddhi by wso2.
the class LengthBatchWindowTestCase method lengthBatchWindowTest1.
@Test
public void lengthBatchWindowTest1() throws InterruptedException {
log.info("Testing length batch window with no of events smaller than window size");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(4) " + "select symbol,price,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);
AssertJUnit.fail("No events should arrive");
inEventCount = inEventCount + inEvents.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(500);
AssertJUnit.assertEquals(0, inEventCount);
AssertJUnit.assertFalse(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations