io.siddhi.query.api.annotation.Annotation Java Examples

The following examples show how to use io.siddhi.query.api.annotation.Annotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractDefinition.java    From siddhi with Apache License 2.0 6 votes vote down vote up
protected String toString(String type) {
    StringBuilder definitionBuilder = new StringBuilder();
    if (annotations != null && annotations.size() > 0) {
        for (Annotation annotation : annotations) {
            definitionBuilder.append(annotation.toString());
        }
    }
    definitionBuilder.append("define ").append(type).append(" ").append(id).append(" (");
    boolean isFirst = true;
    for (Attribute attribute : attributeList) {
        if (!isFirst) {
            definitionBuilder.append(", ");
        } else {
            isFirst = false;
        }
        definitionBuilder.append(attribute.getName()).append(" ").
                append(attribute.getType().toString().toLowerCase(Locale.getDefault()));
    }
    definitionBuilder.append(")");
    return definitionBuilder.toString();
}
 
Example #2
Source File: SiddhiAppParser.java    From siddhi with Apache License 2.0 6 votes vote down vote up
private static void defineStreamDefinitions(SiddhiAppRuntimeBuilder siddhiAppRuntimeBuilder,
                                            Map<String, StreamDefinition> streamDefinitionMap,
                                            SiddhiAppContext siddhiAppContext) {
    for (StreamDefinition definition : streamDefinitionMap.values()) {
        try {
            Annotation onErrorAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_ON_ERROR,
                    definition.getAnnotations());
            if (onErrorAnnotation != null) {
                StreamJunction.OnErrorAction onErrorAction = StreamJunction.OnErrorAction.valueOf(onErrorAnnotation
                        .getElement(SiddhiConstants.ANNOTATION_ELEMENT_ACTION).toUpperCase());
                if (onErrorAction == StreamJunction.OnErrorAction.STREAM) {
                    StreamDefinition faultStreamDefinition = createFaultStreamDefinition(definition);
                    siddhiAppRuntimeBuilder.defineStream(faultStreamDefinition);
                }
            }
            siddhiAppRuntimeBuilder.defineStream(definition);
        } catch (Throwable t) {
            ExceptionUtil.populateQueryContext(t, definition, siddhiAppContext);
            throw t;
        }
    }
}
 
Example #3
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 6 votes vote down vote up
private static List<OptionHolder> createDestinationOptionHolders(Annotation distributionAnnotation,
                                                                 StreamDefinition streamDefinition,
                                                                 Sink clientTransport,
                                                                 SiddhiAppContext siddhiAppContext) {
    io.siddhi.annotation.Extension sinkExt
            = clientTransport.getClass().getAnnotation(io.siddhi.annotation.Extension.class);

    List<OptionHolder> destinationOptHolders = new ArrayList<>();
    distributionAnnotation.getAnnotations().stream()
            .filter(annotation -> annotation.getName().equalsIgnoreCase(SiddhiConstants.ANNOTATION_DESTINATION))
            .forEach(destinationAnnotation -> destinationOptHolders.add(constructOptionHolder(streamDefinition,
                    updateAnnotationRef(destinationAnnotation, SiddhiConstants.ANNOTATION_DESTINATION,
                            siddhiAppContext), sinkExt, clientTransport.getSupportedDynamicOptions(),
                    true)));
    return destinationOptHolders;
}
 
Example #4
Source File: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Partition visitPartition(@NotNull SiddhiQLParser.PartitionContext ctx) {
    Partition partition = Partition.partition();
    for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
        partition.annotation((Annotation) visit(annotationContext));
    }
    for (SiddhiQLParser.Partition_with_streamContext with_streamContext : ctx.partition_with_stream()) {
        partition.with((PartitionType) visit(with_streamContext));
    }
    for (SiddhiQLParser.QueryContext queryContext : ctx.query()) {
        partition.addQuery((Query) visit(queryContext));
    }
    populateQueryContext(partition, ctx);
    return partition;
}
 
Example #5
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery48() throws InterruptedException {
    log.info("Filter test48");

    SiddhiManager siddhiManager = new SiddhiManager();

    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("available", Attribute.Type.BOOL);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").
            filter(Expression.not(Expression.variable("price"))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("price", Expression.variable("price")).
                    select("available", Expression.variable("available"))
    );
    query.insertInto("StockQuote");

    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

}
 
Example #6
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultilevelNestedAnnotations3() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition(
            "@sink(url='http://foo.com/test/{{data}}', " +
                    "   @map(type=\"\"\"xml\"\"\", " +
                    "@payload(\"\"\"{ \"time\":{{time}}}\"\"\") " +
                    "   )" +
                    ") " +
                    "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("sink")
                            .element("url", "http://foo.com/test/{{data}}")
                            .annotation(Annotation.annotation("map")
                                    .element("type", "xml")
                                    .annotation(Annotation.annotation("payload")
                                            .element("{ \"time\":{{time}}}")))),
            streamDefinition);
}
 
Example #7
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultilevelNestedAnnotations1() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition(
            "@sink(url='http://foo.com/test/{{data}}', " +
                    "   @map(type='xml', " +
                    "@payload('<test><time>{{time}}</time></test>')" +
                    "   )" +
                    ") " +
                    "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("sink")
                            .element("url", "http://foo.com/test/{{data}}")
                            .annotation(Annotation.annotation("map")
                                    .element("type", "xml")
                                    .annotation(Annotation.annotation("payload")
                                            .element("<test><time>{{time}}</time></test>")))),
            streamDefinition);
}
 
Example #8
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery106() throws InterruptedException {
    log.info("Filter test106");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute
            ("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.GREATER_THAN_EQUAL, Expression.value(100d))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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, 60L, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40L, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200L, 56});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    AssertJUnit.assertEquals(1, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #9
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery69() throws InterruptedException {
    log.info("Filter test69");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.LONG);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"),
            Compare.Operator.LESS_THAN_EQUAL, Expression.value(50))));
    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", 50d, 60L});
    inputHandler.send(new Object[]{"WSO2", 70d, 40L});
    inputHandler.send(new Object[]{"WSO2", 44d, 200L});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();

}
 
Example #10
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery101() throws InterruptedException {
    log.info("Filter test101");

    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.GREATER_THAN_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, 2, count, 100);
    AssertJUnit.assertEquals(2, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #11
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery72() throws InterruptedException {
    log.info("Filter test72");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE)
            .attribute("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"),
            Compare.Operator.LESS_THAN_EQUAL,
            Expression.value(200L))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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", 500f, 60d, 5});
    inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2});
    inputHandler.send(new Object[]{"WSO2", 60f, 300d, 4});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();

}
 
Example #12
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery66() throws InterruptedException {
    log.info("Filter test66");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.not(Expression.compare(Expression.variable
            ("volume"), Compare.Operator.EQUAL, Expression.value(40)))));
    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, 60L});
    inputHandler.send(new Object[]{"WSO2", 70f, 40L});
    inputHandler.send(new Object[]{"WSO2", 44f, 200L});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();

}
 
Example #13
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery93() throws InterruptedException {
    log.info("Filter test93");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute
            ("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.LESS_THAN, Expression.value(100f))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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, 60L, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40L, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200L, 56});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    AssertJUnit.assertEquals(2, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #14
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery91() throws InterruptedException {
    log.info("Filter test91");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE)
            .attribute("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"),
            Compare.Operator.LESS_THAN, Expression.value(15))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40d, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200d, 56});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    AssertJUnit.assertEquals(2, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #15
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery90() throws InterruptedException {
    log.info("Filter test90");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE)
            .attribute("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"),
            Compare.Operator.LESS_THAN, Expression.value(10f))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40d, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200d, 56});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    AssertJUnit.assertEquals(1, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #16
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery89() throws InterruptedException {
    log.info("Filter test89");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE)
            .attribute("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"),
            Compare.Operator.LESS_THAN, 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")).select("quantity", Expression.variable("quantity")));
    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, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40d, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200d, 56});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    AssertJUnit.assertEquals(2, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #17
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery79() throws InterruptedException {
    log.info("Filter test79");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute
            ("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.LESS_THAN_EQUAL,
            Expression.value(60L))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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", 500f, 60L, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 60L, 2});
    inputHandler.send(new Object[]{"WSO2", 60f, 300L, 4});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();
}
 
Example #18
Source File: EventTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryParser() {
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT);
    Query query = new Query();
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.NOT_EQUAL, Expression.value(50))));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")));
    query.insertInto("outputStream");
    Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
    Map<String, Table> tableMap = new HashMap<String, Table>();
    Map<String, Window> eventWindowMap = new HashMap<String, Window>();
    Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
    Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
    Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
    Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
    LockSynchronizer lockSynchronizer = new LockSynchronizer();
    streamDefinitionMap.put("cseEventStream", streamDefinition);
    streamDefinitionMap.put("outputStream", outStreamDefinition);
    SiddhiContext siddhicontext = new SiddhiContext();
    SiddhiAppContext context = new SiddhiAppContext();
    context.setSiddhiContext(siddhicontext);
    context.setIdGenerator(new IdGenerator());
    context.setSnapshotService(new SnapshotService(context));
    QueryRuntimeImpl runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap,
            windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap,
            lockSynchronizer, "1", false, SiddhiConstants.PARTITION_ID_DEFAULT);
    AssertJUnit.assertNotNull(runtime);
    AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
    AssertJUnit.assertNotNull(runtime.getSelector());
    AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
 
Example #19
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static Annotation updateAnnotationRef(Annotation annotation, String type,
                                              SiddhiAppContext siddhiAppContext) {
    String ref = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_REF);
    if (ref != null) {
        Map<String, String> systemConfigs = siddhiAppContext.getSiddhiContext().getConfigManager()
                .extractSystemConfigs(ref);

        if (systemConfigs.size() == 0) {
            throw new SiddhiAppCreationException("The " + type + " element of the name '" + ref +
                    "' is not defined in the configurations file.",
                    annotation.getQueryContextStartIndex(),
                    annotation.getQueryContextEndIndex());
        } else {
            HashMap<String, String> newSystemConfig = new HashMap<>(systemConfigs);

            Map<String, String> collection = annotation.getElements().stream()
                    .collect(Collectors.toMap(Element::getKey, Element::getValue));
            collection.remove(SiddhiConstants.ANNOTATION_ELEMENT_REF);
            newSystemConfig.putAll(collection);

            List<Element> annotationElements = newSystemConfig.entrySet().stream()
                    .map((property) -> new Element(
                            property.getKey(),
                            property.getValue()))
                    .collect(Collectors.toList());

            annotation.setElements(annotationElements);
        }
    }
    return annotation;
}
 
Example #20
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static List<Map<String, String>> createDestinationDeploymentProperties(Annotation distributionAnnotation,
                                                                               Sink sink) {

    io.siddhi.annotation.Extension sinkExt
            = sink.getClass().getAnnotation(io.siddhi.annotation.Extension.class);

    List<Map<String, String>> destinationDeploymentProperties = new ArrayList<>();
    distributionAnnotation.getAnnotations().stream()
            .filter(annotation -> annotation.getName().equalsIgnoreCase(SiddhiConstants.ANNOTATION_DESTINATION))
            .forEach(destinationAnnotation -> destinationDeploymentProperties.add(
                    createDeploymentProperties(destinationAnnotation, sinkExt)));
    return destinationDeploymentProperties;
}
 
Example #21
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static OptionHolder constructOptionHolder(StreamDefinition streamDefinition,
                                                  Annotation annotation,
                                                  io.siddhi.annotation.Extension extension,
                                                  String[] supportedDynamicOptions,
                                                  boolean supportDeploymentOptions) {
    List<String> supportedDynamicOptionList = new ArrayList<>();
    if (supportedDynamicOptions != null) {
        supportedDynamicOptionList = Arrays.asList(supportedDynamicOptions);
    }

    Map<String, String> options = new HashMap<>();
    Map<String, String> dynamicOptions = new HashMap<>();
    for (Element element : annotation.getElements()) {
        if (element.getKey().startsWith("dep:")) {
            if (!supportDeploymentOptions) {
                throw new SiddhiAppCreationException("DeploymentOption is not supported by '" +
                        extension.namespace() + ":" + extension.name() + "', but a deployment property '" +
                        element.getKey() + "' is configured",
                        annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
            }
        }
        if (Pattern.matches("(.*?)\\{\\{.*?\\}\\}(.*?)", element.getValue())) {
            if (supportedDynamicOptionList.contains(element.getKey())) {
                dynamicOptions.put(element.getKey(), element.getValue());
            } else {
                throw new SiddhiAppCreationException("'" + element.getKey() + "' is not a supported " +
                        "DynamicOption " + "for the Extension '" + extension.namespace() + ":" + extension.name() +
                        "', it only supports following as its DynamicOptions: " + supportedDynamicOptionList,
                        annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
            }
        } else {
            options.put(element.getKey(), element.getValue());
        }
    }
    return new OptionHolder(streamDefinition, options, dynamicOptions, extension);
}
 
Example #22
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery56() throws InterruptedException {
    log.info("Filter test56");

    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(70))));
    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();

}
 
Example #23
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static Extension constructExtension(StreamDefinition streamDefinition, String typeName, String typeValue,
                                           Annotation annotation, String defaultNamespace) {
    String[] namespaceAndName = typeValue.split(SiddhiConstants.EXTENSION_SEPARATOR);
    String namespace;
    String name;
    if (namespaceAndName.length == 1) {
        namespace = defaultNamespace;
        name = namespaceAndName[0];
    } else if (namespaceAndName.length == 2) {
        namespace = namespaceAndName[0];
        name = namespaceAndName[1];
    } else {
        throw new SiddhiAppCreationException("Malformed '" + typeName + "' annotation type '" + typeValue + "' "
                + "provided, for annotation '" + annotation + "' on stream '" + streamDefinition.getId() + "', "
                + "it should be either '<namespace>:<name>' or '<name>'",
                annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
    }
    return new Extension() {
        @Override
        public String getNamespace() {
            return namespace;
        }

        @Override
        public String getName() {
            return name;
        }
    };
}
 
Example #24
Source File: DefinitionParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static void validateSourceMapperCompatibility(StreamDefinition streamDefinition, String sourceType,
                                                      String mapType, Source source, SourceMapper sourceMapper,
                                                      Annotation sourceAnnotation) {
    Class[] inputEventClasses = sourceMapper.getSupportedInputEventClasses();
    Class[] outputEventClasses = source.getOutputEventClasses();

    //skipping validation for unknown output types
    if (outputEventClasses == null || outputEventClasses.length == 0) {
        return;
    }

    boolean matchingSinkAndMapperClasses = false;
    for (Class inputEventClass : inputEventClasses) {
        for (Class outputEventClass : outputEventClasses) {
            if (inputEventClass.isAssignableFrom(outputEventClass)) {
                matchingSinkAndMapperClasses = true;
                break;
            }
        }
        if (matchingSinkAndMapperClasses) {
            break;
        }
    }
    if (!matchingSinkAndMapperClasses) {
        throw new SiddhiAppCreationException("At stream '" + streamDefinition.getId() + "', source '" + sourceType
                + "' produces incompatible '" + Arrays.deepToString(outputEventClasses) +
                "' classes, while it's source mapper '" + mapType + "' can only consume '" +
                Arrays.deepToString(inputEventClasses) + "' classes.",
                sourceAnnotation.getQueryContextStartIndex(), sourceAnnotation.getQueryContextEndIndex());
    }
}
 
Example #25
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery108() throws InterruptedException {
    log.info("Filter test108");

    SiddhiManager siddhiManager = new SiddhiManager();

    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").
            filter(Expression.compare(Expression.variable("price"),
                    Compare.Operator.EQUAL,
                    Expression.value("WS"))
            )
    );
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("price", Expression.variable("price")).
                    select("volume", Expression.variable("volume"))
    );
    query.insertInto("StockQuote");

    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

}
 
Example #26
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery78() throws InterruptedException {
    log.info("Filter test78");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.LESS_THAN_EQUAL, Expression.value(50))));
    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, 60L});
    inputHandler.send(new Object[]{"WSO2", 70f, 40L});
    inputHandler.send(new Object[]{"WSO2", 44f, 200L});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    siddhiAppRuntime.shutdown();
}
 
Example #27
Source File: CacheTable.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private boolean checkConditionToRouteToCache(Expression condition, MatchingMetaInfoHolder matchingMetaInfoHolder) {
    List<String> primaryKeysArray = new ArrayList<>();
    Annotation primaryKeys = getAnnotation("PrimaryKey", tableDefinition.getAnnotations());
    if (primaryKeys == null) {
        return false;
    }
    List<Element> keys = primaryKeys.getElements();
    for (Element element : keys) {
        primaryKeysArray.add(element.getValue());
    }
    recursivelyCheckConditionToRouteToCache(condition, primaryKeysArray, matchingMetaInfoHolder);
    return primaryKeysArray.size() == 0;
}
 
Example #28
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery51() throws InterruptedException {
    log.info("Filter test51");

    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("volume"),
            Compare.Operator.EQUAL, Expression.value(60f))));
    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();


}
 
Example #29
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery62() throws InterruptedException {
    log.info("Filter test62");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute
            ("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.EQUAL,
            Expression.value(200L))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    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, 60L, 5});
    inputHandler.send(new Object[]{"WSO2", 70f, 60L, 2});
    inputHandler.send(new Object[]{"WSO2", 60f, 200L, 4});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    siddhiAppRuntime.shutdown();

}
 
Example #30
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@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());

}