use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.
the class DefineStreamTestCase method testCreatingStreamDefinition2.
@Test
public void testCreatingStreamDefinition2() {
StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream StockStream ( symbol " + "string, price int, volume double, data Object );");
StreamDefinition api = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.DOUBLE).attribute("data", Attribute.Type.OBJECT);
AssertJUnit.assertEquals(api, streamDefinition);
}
use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.
the class DefineStreamTestCase method testMultilevelNestedAnnotations2.
@Test
public void testMultilevelNestedAnnotations2() throws SiddhiParserException {
StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("" + "@source(" + " type='http', " + " context='/test', " + " transport='http,https', " + " @map(" + " type='xml', " + " namespace = \"h=uri, a=uri\", " + " @attributes(" + " '//h:time', " + " '//h:data'" + " )" + " )" + ") " + "define stream fooStream (id int, name string);");
AssertJUnit.assertEquals(StreamDefinition.id("fooStream").attribute("id", Attribute.Type.INT).attribute("name", Attribute.Type.STRING).annotation(Annotation.annotation("source").element("type", "http").element("context", "/test").element("transport", "http,https").annotation(Annotation.annotation("map").element("type", "xml").element("namespace", "h=uri, a=uri").annotation(Annotation.annotation("attributes").element("//h:time").element("//h:data")))), streamDefinition);
}
use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.
the class DefineStreamTestCase method testAttribute.
@Test
public void testAttribute() {
StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
AssertJUnit.assertEquals(1, streamDefinition.getAttributePosition("price"));
AssertJUnit.assertEquals(Attribute.Type.FLOAT, streamDefinition.getAttributeType("volume"));
}
use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.
the class PartitionRuntime method addQuery.
public QueryRuntime addQuery(QueryRuntime metaQueryRuntime) {
Query query = metaQueryRuntime.getQuery();
if (query.getOutputStream() instanceof InsertIntoStream && metaQueryRuntime.getOutputCallback() instanceof InsertIntoStreamCallback) {
InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) metaQueryRuntime.getOutputCallback();
StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
String id = streamDefinition.getId();
if (((InsertIntoStream) query.getOutputStream()).isInnerStream()) {
metaQueryRuntime.setToLocalStream(true);
localStreamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, localStreamDefinitionMap.get(id));
StreamJunction outputStreamJunction = localStreamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
localStreamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(localStreamJunctionMap.get(id));
} else {
streamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(id));
StreamJunction outputStreamJunction = streamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
streamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(streamJunctionMap.get(id));
}
}
metaQueryRuntimeMap.put(metaQueryRuntime.getQueryId(), metaQueryRuntime);
return metaQueryRuntime;
}
use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.
the class JunctionTestCase method junctionToReceiverTest.
@Test
public void junctionToReceiverTest() throws InterruptedException {
log.info("junction to receiver");
StreamDefinition streamA = StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("parallel"));
StreamJunction streamJunctionA = new StreamJunction(streamA, executorService, 1024, siddhiAppContext);
StreamJunction.Publisher streamPublisherA = streamJunctionA.constructPublisher();
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] streamEvents) {
count += streamEvents.length;
eventArrived = true;
}
};
streamJunctionA.subscribe(streamCallback);
streamJunctionA.startProcessing();
streamPublisherA.send(new StreamEvent(2, 2, 2));
streamPublisherA.send(new StreamEvent(2, 2, 2));
Thread.sleep(100);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(2, count);
streamJunctionA.stopProcessing();
}
Aggregations