use of org.ballerinalang.siddhi.query.api.SiddhiApp in project ballerina by ballerina-lang.
the class PassThroughTestCase method passThroughTest1.
@Test
public void passThroughTest1() throws InterruptedException {
log.info("pass through test1");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT);
Query query = new Query();
query.from(InputStream.stream("cseEventStream"));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("StockQuote");
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(inEvents);
AssertJUnit.assertTrue("IBM".equals(inEvents[0].getData(0)) || "WSO2".equals(inEvents[0].getData(0)));
count += inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 100 });
inputHandler.send(new Object[] { "WSO2", 100 });
Thread.sleep(100);
AssertJUnit.assertEquals(2, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.query.api.SiddhiApp in project ballerina by ballerina-lang.
the class FunctionTestCase method functionTest1.
// Coalesce
@Test
public void functionTest1() throws InterruptedException {
log.info("function test 1");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price1", Attribute.Type.FLOAT).attribute("price2", Attribute.Type.FLOAT);
Query query = new Query();
query.from(InputStream.stream("cseEventStream"));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.function("coalesce", Expression.variable("price1"), Expression.variable("price2"))));
query.insertInto("StockQuote");
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);
eventArrived = true;
for (Event inEvent : inEvents) {
count++;
if (count == 1) {
AssertJUnit.assertEquals(55.6f, inEvent.getData()[1]);
} else if (count == 2) {
AssertJUnit.assertEquals(65.7f, inEvent.getData()[1]);
} else if (count == 3) {
AssertJUnit.assertEquals(23.6f, inEvent.getData()[1]);
} else if (count == 4) {
AssertJUnit.assertEquals(34.6f, inEvent.getData()[1]);
} else if (count == 5) {
AssertJUnit.assertNull(inEvent.getData()[1]);
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 55.6f, 70.6f });
inputHandler.send(new Object[] { "WSO2", 65.7f, 12.8f });
inputHandler.send(new Object[] { "WSO2", 23.6f, null });
inputHandler.send(new Object[] { "WSO2", null, 34.6f });
inputHandler.send(new Object[] { "WSO2", null, null });
Thread.sleep(100);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations