use of io.siddhi.query.api.SiddhiApp 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.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery48.
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery48() {
log.info("Partition test48");
SiddhiApp siddhiApp = new SiddhiApp("plan48");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
FunctionDefinition functionDefinition = new FunctionDefinition();
siddhiApp.defineFunction(functionDefinition.id("e1").type(null));
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery49.
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery49() {
log.info("Partition test49");
SiddhiApp siddhiApp = new SiddhiApp("plan49");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
FunctionDefinition functionDefinition = new FunctionDefinition();
siddhiApp.defineFunction(functionDefinition.id("e1").type(Attribute.Type.STRING).body(null));
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery43.
public void testPartitionQuery43() throws InterruptedException {
log.info("Partition test43");
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiApp siddhiApp = new SiddhiApp("plan43");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
Query query = Query.query();
query.from(InputStream.stream("cseEventStream"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query.insertIntoInner("StockStream", OutputStream.OutputEventType.CURRENT_EVENTS);
Query query1 = Query.query();
query1.from(InputStream.innerStream("StockStream"));
query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query1.insertInto("OutStockStream", OutputStream.OutputEventType.CURRENT_EVENTS);
partition.addQuery(query);
partition.addQuery(query1);
siddhiApp.addPartition(partition);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(4, count.get());
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery3.
@Test
public void testPartitionQuery3() throws InterruptedException {
log.info("Partition test3");
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiApp siddhiApp = new SiddhiApp("plan3");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
Query query = Query.query();
query.from(InputStream.stream("cseEventStream"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query.insertIntoInner("StockStream");
Query query1 = Query.query();
query1.from(InputStream.innerStream("StockStream"));
query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query1.insertInto("OutStockStream");
partition.addQuery(query);
partition.addQuery(query1);
siddhiApp.addPartition(partition);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(4, count.get());
}
Aggregations