use of io.siddhi.core.SiddhiAppRuntime in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery50.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery50() throws InterruptedException {
log.info("Filter test50");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
String query = "@info(name = 'query1') from cseEventStream[volume] select symbol,price,volume insert into " + "outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
use of io.siddhi.core.SiddhiAppRuntime in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery54.
@Test
public void testFilterQuery54() throws InterruptedException {
log.info("Filter test54");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.value(50d))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50f, 60d });
inputHandler.send(new Object[] { "WSO2", 70f, 40d });
inputHandler.send(new Object[] { "WSO2", 44f, 200d });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiAppRuntime in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery12.
@Test
public void testFilterQuery12() throws InterruptedException {
log.info("Filter test12");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume double);";
String query = "@info(name = 'query1') from cseEventStream[volume > 45] select symbol,price 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);
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50f, 60d });
inputHandler.send(new Object[] { "WSO2", 70f, 40d });
inputHandler.send(new Object[] { "WSO2", 44f, 200d });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiAppRuntime in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery13.
@Test
public void testFilterQuery13() throws InterruptedException {
log.info("Filter test13");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume float);";
String query = "@info(name = 'query1') from cseEventStream[volume > 50d] select symbol,price 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);
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50f, 60f });
inputHandler.send(new Object[] { "WSO2", 70f, 40f });
inputHandler.send(new Object[] { "WSO2", 44f, 200f });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.SiddhiAppRuntime in project siddhi by wso2.
the class LogicalPatternTestCase method testQuery5.
@Test
public void testQuery5() throws InterruptedException {
log.info("testPatternLogical5 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price > 20] -> e2=Stream2[price > e1.price] and e3=Stream2['IBM' == symbol] " + "select e1.symbol as symbol1, e2.price as price2, e3.price as price3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + 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;
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 72.7f, 72.7f }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 72.7f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 75.7f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations