Search in sources :

Example 51 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class TestDebugger method testDebugger1.

@Test
public void testDebugger1() throws InterruptedException {
    log.info("Siddi Debugger Test 1: Test next traversal in a simple query");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, " + "volume int);";
    final String query = "@info(name = 'query 1')" + "from cseEventStream " + "select symbol, price, volume " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            inEventCount.addAndGet(events.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    siddhiDebugger.acquireBreakPoint("query 1", SiddhiDebugger.QueryTerminal.IN);
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            log.info("Query: " + queryName + ":" + queryTerminal);
            log.info(event.toString());
            int count = debugEventCount.addAndGet(getCount(event));
            if (count == 1) {
                AssertJUnit.assertEquals("Incorrect break point", "query 1IN", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[] { "WSO2", 50f, 60 }, event.getOutputData());
            } else if (count == 2) {
                AssertJUnit.assertEquals("Incorrect break point", "query 1OUT", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at OUT", new Object[] { "WSO2", 50f, 60 }, event.getOutputData());
            } else if (count == 3) {
                AssertJUnit.assertEquals("Incorrect break point", "query 1IN", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[] { "WSO2", 70f, 40 }, event.getOutputData());
            } else if (count == 4) {
                AssertJUnit.assertEquals("Incorrect break point", "query 1OUT", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at OUT", new Object[] { "WSO2", 70f, 40 }, event.getOutputData());
            }
            debugger.next();
        }
    });
    inputHandler.send(new Object[] { "WSO2", 50f, 60 });
    inputHandler.send(new Object[] { "WSO2", 70f, 40 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> inEventCount.get() == 2 && debugEventCount.get() == 4);
    AssertJUnit.assertEquals("Invalid number of output events", 2, inEventCount.get());
    AssertJUnit.assertEquals("Invalid number of debug events", 4, debugEventCount.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 52 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class TestDebugger method testDebugger5.

@Test(dependsOnMethods = "testDebugger4")
public void testDebugger5() throws InterruptedException {
    log.info("Siddi Debugger Test 5: Test play in a simple query");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, " + "volume int);";
    final String query = "@info(name = 'query1')" + "from cseEventStream " + "select symbol, price, volume " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            inEventCount.addAndGet(events.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            log.info("Query: " + queryName + ":" + queryTerminal);
            log.info(event.toString());
            int count = debugEventCount.addAndGet(getCount(event));
            if (count == 1) {
                AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[] { "WSO2", 50f, 60 }, event.getOutputData());
            } else if (count == 2) {
                AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at OUT", new Object[] { "WSO2", 70f, 40 }, event.getOutputData());
            }
            debugger.play();
        }
    });
    inputHandler.send(new Object[] { "WSO2", 50f, 60 });
    inputHandler.send(new Object[] { "WSO2", 70f, 40 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> inEventCount.get() == 2 && debugEventCount.get() == 2);
    AssertJUnit.assertEquals("Invalid number of output events", 2, inEventCount.get());
    AssertJUnit.assertEquals("Invalid number of debug events", 2, debugEventCount.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 53 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class TestDebugger method testDebugger8.

@Test(dependsOnMethods = "testDebugger7")
public void testDebugger8() throws InterruptedException {
    log.info("Siddi Debugger Test 8: Test play traversal in a query with time batch window where play call delays" + " 1 sec");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    final String query = "@info(name = 'query1')" + "from cseEventStream#window.timeBatch(1 sec) " + "select symbol, price, volume " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            inEventCount.addAndGet(events.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            log.info(event.toString());
            int count = debugEventCount.addAndGet(getCount(event));
            AssertJUnit.assertEquals("Only one event can be emitted from the window", 1, getCount(event));
            if (count != 1 && "query1IN".equals(queryName)) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
            debugger.play();
        }
    });
    inputHandler.send(new Object[] { "WSO2", 50f, 60 });
    inputHandler.send(new Object[] { "WSO2", 70f, 40 });
    inputHandler.send(new Object[] { "WSO2", 60f, 50 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> inEventCount.get() == 3 && debugEventCount.get() == 3);
    AssertJUnit.assertEquals("Invalid number of output events", 3, inEventCount.get());
    AssertJUnit.assertEquals("Invalid number of debug events", 3, debugEventCount.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 54 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class TestDebugger method testDebugger7.

@Test(dependsOnMethods = "testDebugger6")
public void testDebugger7() throws InterruptedException {
    log.info("Siddi Debugger Test 7: Test play traversal in a query with time batch window");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "@info(name = 'query1')" + "from cseEventStream#window.timeBatch(3 sec) " + "select symbol, price, volume " + "insert into OutputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            inEventCount.addAndGet(events.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            log.info("Query: " + queryName + "\t" + System.currentTimeMillis());
            log.info(event.toString());
            int count = debugEventCount.addAndGet(getCount(event));
            if (count == 1) {
                AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[] { "WSO2", 50f, 60 }, event.getOutputData());
            } else if (count == 2) {
                AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[] { "WSO2", 70f, 40 }, event.getOutputData());
            } else if (count == 3) {
                AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal);
                AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[] { "WSO2", 60f, 50 }, event.getOutputData());
            }
            debugger.play();
        }
    });
    inputHandler.send(new Object[] { "WSO2", 50f, 60 });
    inputHandler.send(new Object[] { "WSO2", 70f, 40 });
    inputHandler.send(new Object[] { "WSO2", 60f, 50 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> inEventCount.get() == 3 && debugEventCount.get() == 3);
    AssertJUnit.assertEquals("Invalid number of output events", 3, inEventCount.get());
    AssertJUnit.assertEquals("Invalid number of debug events", 3, debugEventCount.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 55 with ComplexEvent

use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.

the class TestDebugger method testDebugger11.

@Test(dependsOnMethods = "testDebugger10")
public void testDebugger11() throws InterruptedException {
    log.info("Siddi Debugger Test 11: Modify events during debug mode");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "@config(async = 'true') " + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream stockEventStream (symbol string, price float, volume int); ";
    final String query = "@info(name = 'query1')" + "from cseEventStream " + "select symbol, price, volume " + "insert into stockEventStream; " + "@info(name = 'query2')" + "from stockEventStream " + "select * " + "insert into OutputStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            inEventCount.addAndGet(events.length);
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
    siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
    siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {

        @Override
        public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
            log.info("Query: " + queryName + ":" + queryTerminal);
            log.info(event.toString());
            int count = debugEventCount.addAndGet(getCount(event));
            if ((count - 1) / 2 == 0) {
                // WSO2 in stream 1
                AssertJUnit.assertArrayEquals("Incorrect debug event received", new Object[] { "WSO2", 50f, 60 }, event.getOutputData());
            } else {
                // IBM in stream 2
                AssertJUnit.assertArrayEquals("Incorrect debug event received", new Object[] { "IBM", 50f, 60 }, event.getOutputData());
            }
            if (count == 2) {
                // Modify the event at the end of the first stream
                event.getOutputData()[0] = "IBM";
            }
            debugger.next();
        }
    });
    inputHandler.send(new Object[] { "WSO2", 50f, 60 });
    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> inEventCount.get() == 1 && debugEventCount.get() == 4);
    AssertJUnit.assertEquals("Invalid number of output events", 1, inEventCount.get());
    AssertJUnit.assertEquals("Invalid number of debug events", 4, debugEventCount.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) StreamCallback(org.ballerinalang.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)58 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)29 ArrayList (java.util.ArrayList)20 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)17 Event (org.ballerinalang.siddhi.core.event.Event)15 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)12 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)12 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)12 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)12 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)11 Test (org.testng.annotations.Test)11 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)7 AttributeProcessor (org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor)4 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 LinkedHashMap (java.util.LinkedHashMap)1 Scanner (java.util.Scanner)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1