use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent in project kogito-runtimes by kiegroup.
the class BaseSpringBootDecisionTracingTest method testListener.
private List<EvaluateEvent> testListener(boolean asyncEnabled, DMNRuntime runtime, DecisionModel model) {
final ApplicationEventPublisher mockedEventPublisher = mock(ApplicationEventPublisher.class);
final SpringBootDecisionTracingCollector mockedCollector = mock(SpringBootDecisionTracingCollector.class);
SpringBootDecisionTracingListener listener = new SpringBootDecisionTracingListener(mockedEventPublisher, mockedCollector, asyncEnabled);
runtime.addListener(listener);
final DMNContext context = model.newContext(getContextVariables());
model.evaluateAll(context);
ArgumentCaptor<EvaluateEvent> eventCaptor = ArgumentCaptor.forClass(EvaluateEvent.class);
if (asyncEnabled) {
verify(mockedEventPublisher, times(getEvaluationEventCount())).publishEvent(eventCaptor.capture());
verify(mockedCollector, never()).onApplicationEvent(any());
} else {
verify(mockedEventPublisher, never()).publishEvent(any());
verify(mockedCollector, times(getEvaluationEventCount())).onApplicationEvent(eventCaptor.capture());
}
return eventCaptor.getAllValues();
}
use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent in project kogito-runtimes by kiegroup.
the class BaseSpringBootDecisionTracingTest method testAsyncListenerAndCollectorWithRealEventsIsWorking.
@Test
void testAsyncListenerAndCollectorWithRealEventsIsWorking() throws IOException {
final DMNRuntime runtime = buildDMNRuntime();
final DecisionModel model = buildDecisionModel(runtime);
final List<EvaluateEvent> events = testListener(true, runtime, model);
testCollector(events, model);
}
use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent in project kogito-runtimes by kiegroup.
the class DecisionTracingCollectorTest method testInterleavedEvaluations.
private void testInterleavedEvaluations(Supplier<TerminationDetector> terminationDetectorSupplier) throws IOException {
MockDefaultAggregator aggregator = new MockDefaultAggregator();
Consumer<String> payloadConsumer = mock(Consumer.class);
DecisionTracingCollector collector = new DecisionTracingCollector(aggregator, payloadConsumer, (namespace, name) -> model, terminationDetectorSupplier, configBean);
List<EvaluateEvent> evaluateAllEvents = readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE);
List<EvaluateEvent> evaluateDecisionServiceEvents = readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE);
for (int i = 0; i < Math.max(evaluateAllEvents.size(), evaluateDecisionServiceEvents.size()); i++) {
if (i < evaluateAllEvents.size()) {
collector.addEvent(evaluateAllEvents.get(i));
}
if (i < evaluateDecisionServiceEvents.size()) {
collector.addEvent(evaluateDecisionServiceEvents.get(i));
}
}
Map<String, Pair<List<EvaluateEvent>, CloudEvent>> aggregatorCalls = aggregator.getCalls();
assertEquals(2, aggregatorCalls.size());
assertTrue(aggregatorCalls.containsKey(EVALUATE_ALL_EXECUTION_ID));
assertEquals(evaluateAllEvents.size(), aggregatorCalls.get(EVALUATE_ALL_EXECUTION_ID).getLeft().size());
assertTrue(aggregatorCalls.containsKey(EVALUATE_DECISION_SERVICE_EXECUTION_ID));
assertEquals(evaluateDecisionServiceEvents.size(), aggregatorCalls.get(EVALUATE_DECISION_SERVICE_EXECUTION_ID).getLeft().size());
ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
verify(payloadConsumer, times(2)).accept(payloadCaptor.capture());
int evaluateAllIndex = evaluateAllEvents.size() > evaluateDecisionServiceEvents.size() ? 1 : 0;
int evaluateDecisionServiceIndex = evaluateAllIndex == 1 ? 0 : 1;
List<String> payloads = payloadCaptor.getAllValues();
String expectedEvaluateAll = encodeFromCall(aggregatorCalls, EVALUATE_ALL_EXECUTION_ID);
assertEquals(expectedEvaluateAll, payloads.get(evaluateAllIndex));
String expectedEvaluateDecisionService = encodeFromCall(aggregatorCalls, EVALUATE_DECISION_SERVICE_EXECUTION_ID);
assertEquals(expectedEvaluateDecisionService, payloads.get(evaluateDecisionServiceIndex));
}
use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent in project kogito-runtimes by kiegroup.
the class DecisionTracingListenerTest method assertEvaluateDecisionServiceEvents.
private static void assertEvaluateDecisionServiceEvents(List<EvaluateEvent> evaluateEvents, String modelNamespace, String modelName, String executionId) {
assertTrue(evaluateEvents.size() >= 2);
evaluateEvents.forEach(e -> assertEventMatches(modelNamespace, modelName, executionId, e));
EvaluateEvent beforeEvent = evaluateEvents.get(0);
assertSame(EvaluateEventType.BEFORE_EVALUATE_DECISION_SERVICE, beforeEvent.getType());
assertEquals(DECISION_SERVICE_NODE_ID, beforeEvent.getNodeId());
assertEquals(DECISION_SERVICE_NODE_NAME, beforeEvent.getNodeName());
EvaluateEvent afterEvent = evaluateEvents.get(evaluateEvents.size() - 1);
assertSame(EvaluateEventType.AFTER_EVALUATE_DECISION_SERVICE, afterEvent.getType());
assertEquals(DECISION_SERVICE_NODE_ID, afterEvent.getNodeId());
assertEquals(DECISION_SERVICE_NODE_NAME, afterEvent.getNodeName());
}
use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent in project kogito-runtimes by kiegroup.
the class DecisionTracingListenerTest method testListenerWithMockedEventsIsWorking.
@Test
void testListenerWithMockedEventsIsWorking() {
DMNContextImpl context = new DMNContextImpl();
DecisionExecutionIdUtils.inject(context, () -> TEST_EXECUTION_ID_1);
DMNResultImpl result = new DMNResultImpl(new DMNModelImpl());
result.setContext(context);
BeforeEvaluateAllEvent beforeEvent = new MockBeforeEvaluateAllEvent(MOCKED_MODEL_NAMESPACE, MOCKED_MODEL_NAME, result);
AfterEvaluateAllEvent afterEvent = new MockAfterEvaluateAllEvent(MOCKED_MODEL_NAMESPACE, MOCKED_MODEL_NAME, result);
Consumer<EvaluateEvent> eventConsumer = mock(Consumer.class);
DecisionTracingListener listener = new DecisionTracingListener(eventConsumer);
listener.beforeEvaluateAll(beforeEvent);
listener.afterEvaluateAll(afterEvent);
ArgumentCaptor<EvaluateEvent> eventCaptor = ArgumentCaptor.forClass(EvaluateEvent.class);
verify(eventConsumer, times(2)).accept(eventCaptor.capture());
assertEvaluateAllEvents(eventCaptor.getAllValues(), MOCKED_MODEL_NAMESPACE, MOCKED_MODEL_NAME, TEST_EXECUTION_ID_1);
}
Aggregations