use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class StartStopTestCase method startStopTest2.
@Test()
public void startStopTest2() throws InterruptedException {
log.info("startStop test 2");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "select 1 as eventFrom " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream2 " + "select 2 as eventFrom " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
Assert.assertEquals(events[0].getData(0), 1);
eventArrived = true;
count.incrementAndGet();
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream2");
inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
siddhiAppRuntime.shutdown();
siddhiAppRuntime.start();
inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
inputHandler.send(new Object[] { "WSO2", 55.6f, 100 });
siddhiAppRuntime.shutdown();
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(1, count.get());
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery22.
@Test
public void testFilterQuery22() throws InterruptedException {
log.info("Filter test22");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume double);";
String query = "@info(name = 'query1') from cseEventStream[volume > 12L and price < 56] 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.assertEquals(100d, inEvents[0].getData(2));
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.6f, 100d });
inputHandler.send(new Object[] { "WSO2", 57.6f, 10d });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery9.
@Test
public void testFilterQuery9() throws InterruptedException {
log.info("Filter test9");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume float);";
String query = "@info(name = 'query1') from cseEventStream[volume > 50f] 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.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery37.
@Test
public void testFilterQuery37() throws InterruptedException {
log.info("Filter test37");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume double);";
String query = "@info(name = 'query1') from cseEventStream[volume == 50d] 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);
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.5f, 40d });
inputHandler.send(new Object[] { "WSO2", 53.5f, 50d });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.input.InputHandler in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery56.
@Test
public void testFilterQuery56() throws InterruptedException {
log.info("Filter test56");
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(70))));
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();
}
Aggregations