Search in sources :

Example 1 with MockDefaultAggregator

use of org.kie.kogito.tracing.decision.mock.MockDefaultAggregator 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)

Aggregations

Pair (org.kie.dmn.feel.util.Pair)1 EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)1 MockDefaultAggregator (org.kie.kogito.tracing.decision.mock.MockDefaultAggregator)1