use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class TestDebugger method testDebugger8.
@Test
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);
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 });
Thread.sleep(1500);
AssertJUnit.assertEquals("Invalid number of output events", 3, inEventCount.get());
AssertJUnit.assertEquals("Invalid number of debug events", 3, debugEventCount.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class TestDebugger method testDebugger9.
@Test
public void testDebugger9() throws InterruptedException {
log.info("Siddi Debugger Test 9: Test state 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 = 'query1')" + "from cseEventStream#window.length(3) " + "select symbol, price, sum(volume) as 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);
int count = debugEventCount.addAndGet(getCount(event));
if (count == 2) {
Map<String, Object> queryState = debugger.getQueryState(queryName);
log.info(queryState);
log.info(queryState.values().toArray()[0]);
StreamEvent streamEvent = null;
// Order of the query state items is unpredictable
for (Map.Entry<String, Object> entry : queryState.entrySet()) {
if (entry.getKey().startsWith("AbstractStreamProcessor")) {
streamEvent = (StreamEvent) ((Map<String, Object>) entry.getValue()).get("ExpiredEventChunk");
break;
}
}
AssertJUnit.assertArrayEquals(streamEvent.getOutputData(), new Object[] { "WSO2", 50.0f, null });
}
debugger.next();
}
});
inputHandler.send(new Object[] { "WSO2", 50f, 60 });
inputHandler.send(new Object[] { "WSO2", 70f, 40 });
Thread.sleep(100);
AssertJUnit.assertEquals("Invalid number of output events", 2, inEventCount.get());
AssertJUnit.assertEquals("Invalid number of debug events", 4, debugEventCount.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class Window method add.
/**
* Add the given ComplexEventChunk to the Window.
*
* @param complexEventChunk the event chunk to be added
*/
public void add(ComplexEventChunk complexEventChunk) {
try {
this.lockWrapper.lock();
complexEventChunk.reset();
// Convert all events to StreamEvent because StateEvents can be passed if directly received from a join
ComplexEvent complexEvents = complexEventChunk.getFirst();
StreamEvent firstEvent = streamEventFactory.newInstance();
eventConverter.convertComplexEvent(complexEvents, firstEvent);
StreamEvent currentEvent = firstEvent;
complexEvents = complexEvents.getNext();
int numberOfEvents = 0;
while (complexEvents != null) {
numberOfEvents++;
StreamEvent nextEvent = streamEventFactory.newInstance();
eventConverter.convertComplexEvent(complexEvents, nextEvent);
currentEvent.setNext(nextEvent);
currentEvent = nextEvent;
complexEvents = complexEvents.getNext();
}
try {
if (throughputTrackerInsert != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
throughputTrackerInsert.eventsIn(numberOfEvents);
latencyTrackerInsert.markIn();
}
// Send to the window windowProcessor
windowProcessor.process(new ComplexEventChunk<>(firstEvent, currentEvent));
} finally {
if (throughputTrackerInsert != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
latencyTrackerInsert.markOut();
}
}
} finally {
this.lockWrapper.unlock();
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method generateResetComplexEventChunk.
private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(int outputDataSize, StateEventFactory stateEventFactory) {
StreamEvent streamEvent = new StreamEvent(outputDataSize, 0, outputDataSize);
streamEvent.setType(ComplexEvent.Type.RESET);
StateEvent stateEvent = stateEventFactory.newInstance();
stateEvent.addEvent(0, streamEvent);
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class TestStoreForCachePreLoading method generateResetComplexEventChunk.
private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(int outputDataSize, StateEventFactory stateEventFactory) {
StreamEvent streamEvent = new StreamEvent(outputDataSize, 0, outputDataSize);
streamEvent.setType(ComplexEvent.Type.RESET);
StateEvent stateEvent = stateEventFactory.newInstance();
stateEvent.addEvent(0, streamEvent);
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
Aggregations