use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class AggregationWindowedPerSnapshotOutputRateLimiter method tryFlushEvents.
private void tryFlushEvents(ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks, ComplexEvent event) {
if (event.getTimestamp() >= scheduledTime) {
ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
for (ComplexEvent originalComplexEvent : eventList) {
ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent);
for (Integer position : aggregateAttributePositionList) {
eventCopy.getOutputData()[position] = aggregateAttributeValueMap.get(position);
}
outputEventChunk.add(eventCopy);
}
outputEventChunks.add(outputEventChunk);
scheduledTime += value;
scheduler.notifyAt(scheduledTime);
}
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class TestDebugger method testDebugger12.
@Test(dependsOnMethods = "testDebugger11")
public void testDebugger12() throws InterruptedException {
log.info("Siddi Debugger Test 12: Test debugging two queries with concurrent input");
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 * " + "insert into OutputStream1; " + "@info(name = 'query2')" + "from stockEventStream " + "select * " + "insert into OutputStream2;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("OutputStream1", new StreamCallback() {
@Override
public void receive(Event[] events) {
inEventCount.addAndGet(events.length);
}
});
siddhiAppRuntime.addCallback("OutputStream2", new StreamCallback() {
@Override
public void receive(Event[] events) {
inEventCount.addAndGet(events.length);
}
});
final InputHandler cseEventStreamInputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
final InputHandler stockEventStreamInputHandler = siddhiAppRuntime.getInputHandler("stockEventStream");
SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug();
siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN);
siddhiDebugger.acquireBreakPoint("query2", SiddhiDebugger.QueryTerminal.IN);
siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() {
private AtomicBoolean queryOneResumed = new AtomicBoolean(false);
@Override
public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) {
log.info("Query: " + queryName + ":" + queryTerminal);
log.info(event.toString());
debugEventCount.addAndGet(getCount(event));
if ("query1IN".equals(queryName)) {
try {
// Wait for 1 sec
Thread.sleep(1000);
this.queryOneResumed.set(true);
} catch (InterruptedException e) {
}
AssertJUnit.assertArrayEquals("Incorrect debug event received", new Object[] { "WSO2", 50f, 60 }, event.getOutputData());
} else if ("query2IN".equals(queryName)) {
// If query2IN is reached, query1IN must left that break point
AssertJUnit.assertTrue("Query 2 thread enterted the checkpoint before query 1 is debugged", queryOneResumed.get());
AssertJUnit.assertArrayEquals("Incorrect debug event received", new Object[] { "IBM", 45f, 80 }, event.getOutputData());
}
debugger.next();
}
});
new Thread() {
@Override
public void run() {
try {
cseEventStreamInputHandler.send(new Object[] { "WSO2", 50f, 60 });
} catch (InterruptedException e) {
}
}
}.start();
new Thread() {
@Override
public void run() {
try {
Thread.sleep(10);
stockEventStreamInputHandler.send(new Object[] { "IBM", 45f, 80 });
} catch (InterruptedException e) {
}
}
}.start();
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> {
return 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();
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class TestDebugger method testDebugger3.
@Test(dependsOnMethods = "testDebugger2")
public void testDebugger3() throws InterruptedException {
log.info("Siddi Debugger Test 3: Test next 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());
}
// next call will not reach OUT since there is a window
debugger.next();
}
});
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(() -> {
return 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();
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class TestDebugger method testDebugger2.
@Test(dependsOnMethods = "testDebugger1")
public void testDebugger2() throws InterruptedException {
log.info("Siddi Debugger Test 2: Test next traversal in a query with length batch window");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, " + "volume int);";
String query = "@info(name = 'query1')" + "from cseEventStream#window.lengthBatch(3) " + "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 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());
} else if (count == 4) {
AssertJUnit.assertEquals("Incorrect break point", "query1OUT", queryName + queryTerminal);
AssertJUnit.assertEquals("Incorrect number of events received", 3, getCount(event));
}
debugger.next();
}
});
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() == 6);
AssertJUnit.assertEquals("Invalid number of output events", 3, inEventCount.get());
AssertJUnit.assertEquals("Invalid number of debug events", 6, debugEventCount.get());
siddhiAppRuntime.shutdown();
}
use of org.ballerinalang.siddhi.core.event.ComplexEvent in project ballerina by ballerina-lang.
the class TestDebugger method testDebugger6.
@Test(dependsOnMethods = "testDebugger5")
public void testDebugger6() throws InterruptedException {
log.info("Siddi Debugger Test 6: Test play traversal in a query with length batch window");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, " + "volume int);";
String query = "@info(name = 'query1')" + "from cseEventStream#window.lengthBatch(3) " + "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 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();
}
Aggregations