Search in sources :

Example 6 with StreamDefinition

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);
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 7 with 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);
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 8 with 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"));
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 9 with StreamDefinition

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;
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) InsertIntoStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.InsertIntoStream) StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction) InsertIntoStreamCallback(org.ballerinalang.siddhi.core.query.output.callback.InsertIntoStreamCallback)

Example 10 with StreamDefinition

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();
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Aggregations

StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)110 Test (org.testng.annotations.Test)98 Event (org.ballerinalang.siddhi.core.event.Event)83 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)82 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)80 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)80 SiddhiApp (org.ballerinalang.siddhi.query.api.SiddhiApp)80 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)77 QueryCallback (org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)73 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)9 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)8 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)8 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)8 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)5 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)5 ArrayList (java.util.ArrayList)3 SelectiveStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3 SimpleStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter)3 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)3 ZeroStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter)3