use of org.ballerinalang.siddhi.query.api.SiddhiApp in project ballerina by ballerina-lang.
the class PartitionTestCase1 method testPartitionQuery5.
@Test
public void testPartitionQuery5() throws InterruptedException {
log.info("Partition test5");
final SiddhiManager siddhiManager = new SiddhiManager();
SiddhiApp siddhiApp = new SiddhiApp("plan5");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition streamDefinition1 = StreamDefinition.id("cseEventStream1").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition streamDefinition2 = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
siddhiApp.defineStream(streamDefinition1);
siddhiApp.defineStream(streamDefinition2);
Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
Query query = Query.query();
query.from(InputStream.stream("cseEventStream")).annotation(Annotation.annotation("info").element("name", "query"));
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")).annotation(Annotation.annotation("info").element("name", "query1"));
query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query1.insertInto("OutStockStream");
// //////////////////////////////////partition-2/////////////////
Partition partition1 = Partition.partition().with("cseEventStream1", Expression.variable("symbol"));
Query query2 = Query.query();
query2.from(InputStream.stream("cseEventStream1")).annotation(Annotation.annotation("info").element("name", "query2"));
query2.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query2.insertIntoInner("StockStream");
Query query3 = Query.query();
query3.from(InputStream.innerStream("StockStream")).annotation(Annotation.annotation("info").element("name", "query3"));
query3.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query3.insertInto("OutStockStream");
Query query4 = Query.query();
query4.from(InputStream.stream("StockStream")).annotation(Annotation.annotation("info").element("name", "query4"));
query4.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query4.insertInto("OutStockStream");
Query query5 = Query.query();
query5.from(InputStream.innerStream("StockStream")).annotation(Annotation.annotation("info").element("name", "query5"));
query5.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query5.insertInto("StockStream");
partition.addQuery(query);
partition.addQuery(query1);
partition.addQuery(query5);
partition1.addQuery(query2);
partition1.addQuery(query3);
siddhiApp.addPartition(partition);
siddhiApp.addPartition(partition1);
siddhiApp.addQuery(query4);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("StockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
stockStreamEventCount = stockStreamEventCount + events.length;
}
});
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
synchronized (siddhiManager) {
count.addAndGet(events.length);
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler inputHandler2 = siddhiAppRuntime.getInputHandler("cseEventStream1");
InputHandler inputHandler3 = siddhiAppRuntime.getInputHandler("StockStream");
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 });
inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
inputHandler2.send(new Object[] { "WSO21", 75.6f, 100 });
inputHandler2.send(new Object[] { "IBM1", 75.6f, 100 });
inputHandler2.send(new Object[] { "ORACLE1", 75.6f, 100 });
inputHandler3.send(new Object[] { "ABC", 75.6f, 100 });
inputHandler3.send(new Object[] { "DEF", 75.6f, 100 });
inputHandler3.send(new Object[] { "KLM", 75.6f, 100 });
inputHandler3.send(new Object[] { "ABC", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 16, count, 60000);
AssertJUnit.assertEquals(16, count.get());
Thread.sleep(100);
AssertJUnit.assertEquals(8, stockStreamEventCount);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.query.api.SiddhiApp in project ballerina by ballerina-lang.
the class PassThroughTestCase method passThroughTest3.
@Test
public void passThroughTest3() throws InterruptedException {
log.info("pass through test3");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT);
StreamDefinition cseEventStream1 = StreamDefinition.id("cseEventStream1").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("symbol")));
query.insertInto("StockQuote");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.defineStream(cseEventStream1);
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);
count += inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler inputHandler1 = siddhiAppRuntime.getInputHandler("cseEventStream1");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 100 });
inputHandler.send(new Object[] { "WSO2", 100 });
inputHandler1.send(new Object[] { "ORACLE", 100 });
inputHandler1.send(new Object[] { "ABC", 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 PassThroughTestCase method passThroughTest2.
@Test
public void passThroughTest2() throws InterruptedException {
log.info("pass through test2");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT);
StreamDefinition cseEventStream1 = StreamDefinition.id("cseEventStream1").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.defineStream(cseEventStream1);
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);
count += inEvents.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream1");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 100 });
inputHandler.send(new Object[] { "WSO2", 100 });
Thread.sleep(100);
AssertJUnit.assertEquals(0, count);
AssertJUnit.assertFalse(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.query.api.SiddhiApp in project ballerina by ballerina-lang.
the class DefineTableTestCase method testQuery1.
@Test
public void testQuery1() throws InterruptedException {
log.info("testTableDefinition1 - OUT 0");
SiddhiManager siddhiManager = new SiddhiManager();
TableDefinition tableDefinition = TableDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT);
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineTable(tableDefinition);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.query.api.SiddhiApp in project ballerina by ballerina-lang.
the class TriggerTestCase method testQuery1.
@Test
public void testQuery1() throws InterruptedException {
log.info("testTrigger1 - OUT 0");
SiddhiManager siddhiManager = new SiddhiManager();
TriggerDefinition triggerDefinition = TriggerDefinition.id("cseEventStream").atEvery(Expression.Time.milliSec(500));
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineTrigger(triggerDefinition);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.shutdown();
}
Aggregations