use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class DefineStreamTestCase method testAnnotatingStreamDefinition3.
@Test
public void testAnnotatingStreamDefinition3() {
Element element = new Element("name", "query1");
String annotationString = "[@map( type = \"xml\", namespace = \"h=uri, a=uri\", @attributes( \"//h:time\", " + "\"//h:data\"))]";
String elementString = "name = \"query1\"";
Annotation 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 streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).annotation(annotation.element(element));
annotation.setName("sink");
AssertJUnit.assertEquals(annotationString, annotation.getAnnotations().toString());
AssertJUnit.assertEquals(annotationString, annotation.getAnnotations("map").toString());
AssertJUnit.assertEquals("sink", annotation.getName());
AssertJUnit.assertEquals("http", annotation.getElement("type"));
AssertJUnit.assertEquals("name", element.getKey());
AssertJUnit.assertEquals("query1", element.getValue());
AssertJUnit.assertEquals(elementString, element.toString());
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class DefineStreamTestCase method testStreamDefinition5.
@Test
public void testStreamDefinition5() {
StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
String[] list = new String[] { "symbol", "price", "volume" };
AssertJUnit.assertEquals(Arrays.toString(list), Arrays.toString(streamDefinition.getAttributeNameArray()));
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class DefineStreamTestCase method testStreamDefinition4.
@Test
public void testStreamDefinition4() {
String attributeList = "[Attribute{id='symbol', type=STRING}, Attribute{id='price', type=INT}," + " Attribute{id='volume', type=FLOAT}]";
StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
AssertJUnit.assertEquals(attributeList, streamDefinition.getAttributeList().toString());
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class DefineStreamTestCase method testStreamIdNull.
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testStreamIdNull() {
StreamDefinition streamDefinition = StreamDefinition.id(null);
SiddhiApp.siddhiApp("Test").defineStream(streamDefinition);
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class SiddhiAppRuntimeBuilder method addQuery.
public String addQuery(QueryRuntimeImpl queryRuntime) {
QueryRuntime oldQueryRuntime = queryProcessorMap.put(queryRuntime.getQueryId(), queryRuntime);
if (oldQueryRuntime != null) {
throw new SiddhiAppCreationException("Multiple queries with name '" + queryRuntime.getQueryId() + "' defined in Siddhi App '" + siddhiAppContext.getName() + "'", queryRuntime.getQuery().getQueryContextStartIndex(), queryRuntime.getQuery().getQueryContextEndIndex());
}
StreamRuntime streamRuntime = queryRuntime.getStreamRuntime();
for (SingleStreamRuntime singleStreamRuntime : streamRuntime.getSingleStreamRuntimes()) {
ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
if (processStreamReceiver.toStream()) {
StreamJunction streamJunction = streamJunctionMap.get(processStreamReceiver.getStreamId());
if (streamJunction != null) {
streamJunction.subscribe(processStreamReceiver);
} else {
throw new SiddhiAppCreationException("Expecting a stream, but provided '" + processStreamReceiver.getStreamId() + "' is not a stream");
}
}
}
OutputCallback outputCallback = queryRuntime.getOutputCallback();
if (outputCallback != null && outputCallback instanceof InsertIntoStreamCallback) {
InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) outputCallback;
StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
streamDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(streamDefinition.getId()));
StreamJunction outputStreamJunction = streamJunctionMap.get(streamDefinition.getId());
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
streamJunctionMap.putIfAbsent(streamDefinition.getId(), outputStreamJunction);
}
insertIntoStreamCallback.init(streamJunctionMap.get(insertIntoStreamCallback.getOutputStreamDefinition().getId()));
} else if (outputCallback != null && outputCallback instanceof InsertIntoWindowCallback) {
InsertIntoWindowCallback insertIntoWindowCallback = (InsertIntoWindowCallback) outputCallback;
StreamDefinition streamDefinition = insertIntoWindowCallback.getOutputStreamDefinition();
windowDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, windowDefinitionMap.get(streamDefinition.getId()));
StreamJunction outputStreamJunction = streamJunctionMap.get(streamDefinition.getId());
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
streamJunctionMap.putIfAbsent(streamDefinition.getId(), outputStreamJunction);
}
insertIntoWindowCallback.getWindow().setPublisher(streamJunctionMap.get(insertIntoWindowCallback.getOutputStreamDefinition().getId()).constructPublisher());
}
return queryRuntime.getQueryId();
}
Aggregations