Search in sources :

Example 16 with EvaluateEvent

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();
}
Also used : ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DMNContext(org.kie.dmn.api.core.DMNContext) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)

Example 17 with EvaluateEvent

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);
}
Also used : DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Test(org.junit.jupiter.api.Test)

Example 18 with EvaluateEvent

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));
}
Also used : MockDefaultAggregator(org.kie.kogito.tracing.decision.mock.MockDefaultAggregator) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Pair(org.kie.dmn.feel.util.Pair)

Example 19 with EvaluateEvent

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());
}
Also used : EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)

Example 20 with EvaluateEvent

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);
}
Also used : DMNResultImpl(org.kie.dmn.core.impl.DMNResultImpl) MockAfterEvaluateAllEvent(org.kie.kogito.tracing.decision.mock.MockAfterEvaluateAllEvent) MockBeforeEvaluateAllEvent(org.kie.kogito.tracing.decision.mock.MockBeforeEvaluateAllEvent) AfterEvaluateAllEvent(org.kie.dmn.api.core.event.AfterEvaluateAllEvent) MockAfterEvaluateAllEvent(org.kie.kogito.tracing.decision.mock.MockAfterEvaluateAllEvent) MockBeforeEvaluateAllEvent(org.kie.kogito.tracing.decision.mock.MockBeforeEvaluateAllEvent) BeforeEvaluateAllEvent(org.kie.dmn.api.core.event.BeforeEvaluateAllEvent) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) DMNContextImpl(org.kie.dmn.core.impl.DMNContextImpl) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Test(org.junit.jupiter.api.Test)

Aggregations

EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)28 Test (org.junit.jupiter.api.Test)17 TraceEvent (org.kie.kogito.tracing.event.trace.TraceEvent)16 CloudEvent (io.cloudevents.CloudEvent)15 List (java.util.List)10 Collections (java.util.Collections)9 Collectors (java.util.stream.Collectors)9 DMNModel (org.kie.dmn.api.core.DMNModel)9 EvaluateEventType (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType)9 InternalMessageType (org.kie.kogito.tracing.decision.message.InternalMessageType)9 TraceEventType (org.kie.kogito.tracing.event.trace.TraceEventType)9 IOException (java.io.IOException)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)6 Assertions.assertSame (org.junit.jupiter.api.Assertions.assertSame)6 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)6 Assertions.fail (org.junit.jupiter.api.Assertions.fail)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)6 ArrayList (java.util.ArrayList)4