Search in sources :

Example 16 with SiddhiDebugger

use of org.wso2.siddhi.core.debugger.SiddhiDebugger in project siddhi by wso2.

the class TestDebugger method testDebugger7.

@Test
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);
            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 });
    Thread.sleep(3500);
    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.wso2.siddhi.core.stream.input.InputHandler) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 17 with SiddhiDebugger

use of org.wso2.siddhi.core.debugger.SiddhiDebugger in project siddhi by wso2.

the class ProcessStreamReceiver method receive.

@Override
public void receive(Event event) {
    if (event != null) {
        StreamEvent borrowedEvent = streamEventPool.borrowEvent();
        streamEventConverter.convertEvent(event, borrowedEvent);
        if (siddhiDebugger != null) {
            siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, borrowedEvent);
        }
        process(new ComplexEventChunk<StreamEvent>(borrowedEvent, borrowedEvent, this.batchProcessingAllowed));
    }
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 18 with SiddhiDebugger

use of org.wso2.siddhi.core.debugger.SiddhiDebugger in project siddhi by wso2.

the class ProcessStreamReceiver method receive.

@Override
public void receive(ComplexEvent complexEvents) {
    if (siddhiDebugger != null) {
        siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, complexEvents);
    }
    StreamEvent firstEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertComplexEvent(complexEvents, firstEvent);
    StreamEvent currentEvent = firstEvent;
    complexEvents = complexEvents.getNext();
    while (complexEvents != null) {
        StreamEvent nextEvent = streamEventPool.borrowEvent();
        streamEventConverter.convertComplexEvent(complexEvents, nextEvent);
        currentEvent.setNext(nextEvent);
        currentEvent = nextEvent;
        complexEvents = complexEvents.getNext();
    }
    process(new ComplexEventChunk<StreamEvent>(firstEvent, currentEvent, this.batchProcessingAllowed));
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 19 with SiddhiDebugger

use of org.wso2.siddhi.core.debugger.SiddhiDebugger in project siddhi by wso2.

the class ProcessStreamReceiver method receive.

@Override
public void receive(long timestamp, Object[] data) {
    StreamEvent borrowedEvent = streamEventPool.borrowEvent();
    streamEventConverter.convertData(timestamp, data, borrowedEvent);
    // Send to debugger
    if (siddhiDebugger != null) {
        siddhiDebugger.checkBreakPoint(queryName, SiddhiDebugger.QueryTerminal.IN, borrowedEvent);
    }
    process(new ComplexEventChunk<StreamEvent>(borrowedEvent, borrowedEvent, this.batchProcessingAllowed));
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)17 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)13 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)13 Event (org.wso2.siddhi.core.event.Event)13 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)13 Test (org.testng.annotations.Test)12 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)12 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)5 Map (java.util.Map)2 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SiddhiDebugger (org.wso2.siddhi.core.debugger.SiddhiDebugger)1 QueryRuntime (org.wso2.siddhi.core.query.QueryRuntime)1 StoreQueryRuntime (org.wso2.siddhi.core.query.StoreQueryRuntime)1 StreamRuntime (org.wso2.siddhi.core.query.input.stream.StreamRuntime)1 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 OutputCallback (org.wso2.siddhi.core.query.output.callback.OutputCallback)1