use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery17.
@Test
public void testFilterQuery17() throws InterruptedException {
log.info("Filter test17");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN, Expression.value(45))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
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, 60L });
inputHandler.send(new Object[] { "WSO2", 70f, 40L });
inputHandler.send(new Object[] { "WSO2", 44f, 200L });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery53.
@Test
public void testFilterQuery53() throws InterruptedException {
log.info("Filter test53");
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("volume"), Compare.Operator.EQUAL, Expression.value(60L))));
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, 60d });
inputHandler.send(new Object[] { "WSO2", 44f, 200d });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery70.
@Test
public void testFilterQuery70() throws InterruptedException {
log.info("Filter test70");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE).attribute("quantity", Attribute.Type.INT);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(200L))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("quantity", Expression.variable("quantity")));
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, 5 });
inputHandler.send(new Object[] { "WSO2", 70f, 60d, 2 });
inputHandler.send(new Object[] { "WSO2", 60f, 300d, 4 });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery65.
@Test
public void testFilterQuery65() throws InterruptedException {
log.info("Filter test65");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.EQUAL, Expression.value(40))));
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, 60L });
inputHandler.send(new Object[] { "WSO2", 70f, 40L });
inputHandler.send(new Object[] { "WSO2", 44f, 200L });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class SandboxTestCase method sandboxTest2.
@Test
public void sandboxTest2() throws InterruptedException {
log.info("sandbox test2");
SiddhiManager siddhiManager = new SiddhiManager();
String app = "" + "@source(type='foo')" + "@source(type='foo1')" + "@sink(type='foo1')" + "@source(type='inMemory', topic='myTopic')" + "define stream StockStream (symbol string, price float, vol long);\n" + "" + "@sink(type='foo1')" + "@sink(type='inMemory', topic='myTopic1')" + "define stream DeleteStockStream (symbol string, price float, vol long);\n" + "" + "@store(type='rdbms')" + "define table StockTable (symbol string, price float, volume long);\n" + "" + "define stream CountStockStream (symbol string);\n" + "" + "@info(name = 'query1') " + "from StockStream " + "select symbol, price, vol as volume " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream[vol>=100] " + "delete StockTable " + " on StockTable.symbol==symbol ;" + "" + "@info(name = 'query3') " + "from CountStockStream#window.length(0) join StockTable" + " on CountStockStream.symbol==StockTable.symbol " + "select CountStockStream.symbol as symbol " + "insert into CountResultsStream ;";
SiddhiApp siddhiApp = SiddhiCompiler.parse(app);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(siddhiApp);
Assert.assertEquals(siddhiAppRuntime.getSources().size(), 1);
Assert.assertEquals(siddhiAppRuntime.getSinks().size(), 1);
Assert.assertEquals(siddhiAppRuntime.getTables().size(), 1);
for (List<Source> sources : siddhiAppRuntime.getSources()) {
for (Source source : sources) {
Assert.assertTrue(source.getType().equalsIgnoreCase("inMemory"));
}
}
for (List<Sink> sinks : siddhiAppRuntime.getSinks()) {
for (Sink sink : sinks) {
Assert.assertTrue(sink.getType().equalsIgnoreCase("inMemory"));
}
}
for (Table table : siddhiAppRuntime.getTables()) {
Assert.assertTrue(table instanceof InMemoryTable);
}
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
InputHandler countStockStream = siddhiAppRuntime.getInputHandler("CountStockStream");
siddhiAppRuntime.addCallback("CountResultsStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
}
});
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
deleteStockStream.send(new Object[] { "IBM", 57.6f, 100L });
countStockStream.send(new Object[] { "WSO2" });
Thread.sleep(500);
Assert.assertEquals(count.get(), 2);
siddhiAppRuntime.shutdown();
}
Aggregations