Siddhi中出现“-> not for ...”的错误?

时间:2018-12-11 07:46:12

标签: siddhi

我将以下测试用例添加到AbsentWithEveryPatternTestCase.java中,但是测试失败了,我认为应该可以成功。那么,是否存在“-> not for ...”模式的错误?

@Test
public void testQuery7() throws InterruptedException {
    log.info("Test the query every e1 -> not e1 for 1 sec with e1 only");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "@app:playback(idle.time = '10 milliseconds', increment = '10 milliseconds') " +
            "define stream Stream1 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from every e1=Stream1[price>20] -> not Stream1[symbol==e1.symbol and price>e1.price] for 1sec " +
            "select e1.symbol as symbol " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"GOOG"});

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");

    siddhiAppRuntime.start();

    stream1.send(1544512385000L, new Object[]{"WSO2", 55.6f, 100});
    stream1.send(1544512385100L, new Object[]{"GOOG", 55.6f, 100});
    stream1.send(1544512385800L, new Object[]{"WSO2", 55.7f, 100});
    stream1.send(1544512386200L, new Object[]{"GOOG", 55.6f, 100});

    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}

1 个答案:

答案 0 :(得分:0)

您的断言失败了,因为在发送输入之后您没有时间来处理事件。查询无法工作的方式是,对于每个传入事件,它将在时间内等待检查事件的发生,然后在经过一段时间后发出事件。因此,您应该等待并让模式查询进行处理。最简单的方法是在发送后添加线程休眠。

Style

推荐的方法是在悉达语中使用waitForEvent utilityHere是该示例。

另外要注意的是,您的查询将生成3个输出事件,因为最后3个输入事件之后没有价格较高的另一个事件。