Search in sources :

Example 1 with ConfigBean

use of org.kie.kogito.conf.ConfigBean in project kogito-runtimes by kiegroup.

the class SpringBootDecisionTracingConfigurationTest method testCollector.

@Test
void testCollector() {
    SpringBootTraceEventEmitter mockedEmitter = mock(SpringBootTraceEventEmitter.class);
    ConfigBean mockedConfigBean = mock(ConfigBean.class);
    Application mockedApplication = mock(Application.class);
    SpringBootDecisionTracingConfiguration config = new SpringBootDecisionTracingConfiguration("localhost:9092", "kogito-tracing-decision", 1, (short) 1);
    SpringBootDecisionTracingCollector asyncCollector = config.collector(mockedEmitter, mockedConfigBean, mockedApplication, true);
    assertTrue(asyncCollector instanceof SpringBootDecisionTracingCollectorAsync);
    SpringBootDecisionTracingCollector syncCollector = config.collector(mockedEmitter, mockedConfigBean, mockedApplication, false);
    assertFalse(syncCollector instanceof SpringBootDecisionTracingCollectorAsync);
}
Also used : ConfigBean(org.kie.kogito.conf.ConfigBean) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigBean

use of org.kie.kogito.conf.ConfigBean in project kogito-runtimes by kiegroup.

the class EventDrivenDecisionControllerTest method testSubscribe.

@Test
void testSubscribe() {
    DecisionModels decisionModelsMock = mock(DecisionModels.class);
    ConfigBean configMock = mock(ConfigBean.class);
    EventEmitter eventEmitterMock = mock(EventEmitter.class);
    EventReceiver eventReceiverMock = mock(EventReceiver.class);
    // option #1: parameters via constructor + parameterless setup
    EventDrivenDecisionController controller1 = new EventDrivenDecisionController(decisionModelsMock, configMock, eventEmitterMock, eventReceiverMock);
    controller1.subscribe();
    verify(eventReceiverMock).subscribe(any(), any());
    reset(eventReceiverMock);
    // option #2: parameterless via constructor + parameters via setup (introduced for Quarkus CDI)
    EventDrivenDecisionController controller2 = new EventDrivenDecisionController();
    controller2.init(decisionModelsMock, configMock, eventEmitterMock, eventReceiverMock);
    controller2.subscribe();
    verify(eventReceiverMock).subscribe(any(), any());
}
Also used : EventEmitter(org.kie.kogito.event.EventEmitter) ConfigBean(org.kie.kogito.conf.ConfigBean) DecisionModels(org.kie.kogito.decision.DecisionModels) EventReceiver(org.kie.kogito.event.EventReceiver) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigBean

use of org.kie.kogito.conf.ConfigBean in project kogito-runtimes by kiegroup.

the class EventDrivenRulesControllerTest method testSubscribe.

@Test
void testSubscribe() {
    ConfigBean configMock = mock(ConfigBean.class);
    EventEmitter eventEmitterMock = mock(EventEmitter.class);
    EventReceiver eventReceiverMock = mock(EventReceiver.class);
    EventUnmarshaller<Object> eventUnmarshaller = mock(EventUnmarshaller.class);
    // option #1: parameters via constructor + parameterless setup
    EventDrivenRulesController controller1 = new EventDrivenRulesController(Collections.emptySet(), configMock, eventEmitterMock, eventReceiverMock, eventUnmarshaller);
    controller1.subscribe();
    verify(eventReceiverMock).subscribe(any(), any());
    reset(eventReceiverMock);
    // option #2: parameterless via constructor + parameters via setup (introduced for Quarkus CDI)
    EventDrivenRulesController controller2 = new EventDrivenRulesController();
    controller2.init(Collections.emptySet(), configMock, eventEmitterMock, eventReceiverMock, eventUnmarshaller);
    controller2.subscribe();
    verify(eventReceiverMock).subscribe(any(), any());
}
Also used : EventEmitter(org.kie.kogito.event.EventEmitter) ConfigBean(org.kie.kogito.conf.ConfigBean) EventReceiver(org.kie.kogito.event.EventReceiver) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigBean

use of org.kie.kogito.conf.ConfigBean in project kogito-runtimes by kiegroup.

the class BaseSpringBootDecisionTracingTest method testCollector.

@SuppressWarnings("unchecked")
private void testCollector(List<EvaluateEvent> events, DecisionModel model) throws IOException {
    final DecisionModels mockedDecisionModels = mock(DecisionModels.class);
    when(mockedDecisionModels.getDecisionModel(getTestModelNameSpace(), getTestModelName())).thenReturn(model);
    final Application mockedApplication = mock(Application.class);
    when(mockedApplication.get(any())).thenReturn(mockedDecisionModels);
    final ConfigBean configBean = new StaticConfigBean(TEST_SERVICE_URL, true, null);
    final KafkaTemplate<String, String> mockedTemplate = mock(KafkaTemplate.class);
    final SpringBootTraceEventEmitter eventEmitter = new SpringBootTraceEventEmitter(mockedTemplate, TEST_KAFKA_TOPIC);
    SpringBootDecisionTracingCollector collector = new SpringBootDecisionTracingCollector(eventEmitter, configBean, mockedApplication);
    events.forEach(collector::onApplicationEvent);
    ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
    verify(mockedTemplate).send(eq(TEST_KAFKA_TOPIC), payloadCaptor.capture());
    CloudEvent cloudEvent = CloudEventUtils.decode(payloadCaptor.getValue()).orElseThrow(() -> new IllegalStateException("Can't decode CloudEvent"));
    assertEquals(TEST_EXECUTION_ID, cloudEvent.getId());
    assertNotNull(cloudEvent.getData());
    TraceEvent traceEvent = MAPPER.readValue(cloudEvent.getData().toBytes(), TraceEvent.class);
    assertNotNull(traceEvent);
    assertEquals(TEST_SERVICE_URL, traceEvent.getHeader().getResourceId().getServiceUrl());
}
Also used : StaticConfigBean(org.kie.kogito.conf.StaticConfigBean) ConfigBean(org.kie.kogito.conf.ConfigBean) StaticConfigBean(org.kie.kogito.conf.StaticConfigBean) DecisionModels(org.kie.kogito.decision.DecisionModels) Application(org.kie.kogito.Application) CloudEvent(io.cloudevents.CloudEvent) TraceEvent(org.kie.kogito.tracing.event.trace.TraceEvent)

Example 5 with ConfigBean

use of org.kie.kogito.conf.ConfigBean in project kogito-runtimes by kiegroup.

the class BaseQuarkusDecisionTracingTest method testCollector.

private void testCollector(List<EvaluateEvent> events, DecisionModel model) throws IOException {
    AssertSubscriber<String> subscriber = AssertSubscriber.create(1);
    final DecisionModels mockedDecisionModels = mock(DecisionModels.class);
    when(mockedDecisionModels.getDecisionModel(getTestModelNameSpace(), getTestModelName())).thenReturn(model);
    final Application mockedApplication = mock(Application.class);
    when(mockedApplication.get(any())).thenReturn(mockedDecisionModels);
    final ConfigBean configBean = new StaticConfigBean(TEST_SERVICE_URL, true, null);
    final QuarkusTraceEventEmitter eventEmitter = new QuarkusTraceEventEmitter();
    QuarkusDecisionTracingCollector collector = new QuarkusDecisionTracingCollector(eventEmitter, configBean, mockedApplication);
    eventEmitter.getEventPublisher().subscribe(subscriber);
    events.forEach(collector::onEvent);
    subscriber.assertNotTerminated();
    List<String> items = subscriber.getItems();
    assertEquals(1, items.size());
    CloudEvent cloudEvent = CloudEventUtils.decode(items.get(0)).orElseThrow(() -> new IllegalStateException("Can't decode CloudEvent"));
    assertEquals(TEST_EXECUTION_ID, cloudEvent.getId());
    assertNotNull(cloudEvent.getData());
    TraceEvent traceEvent = MAPPER.readValue(cloudEvent.getData().toBytes(), TraceEvent.class);
    assertNotNull(traceEvent);
    assertEquals(TEST_SERVICE_URL, traceEvent.getHeader().getResourceId().getServiceUrl());
}
Also used : StaticConfigBean(org.kie.kogito.conf.StaticConfigBean) ConfigBean(org.kie.kogito.conf.ConfigBean) StaticConfigBean(org.kie.kogito.conf.StaticConfigBean) DecisionModels(org.kie.kogito.decision.DecisionModels) Application(org.kie.kogito.Application) CloudEvent(io.cloudevents.CloudEvent) TraceEvent(org.kie.kogito.tracing.event.trace.TraceEvent)

Aggregations

ConfigBean (org.kie.kogito.conf.ConfigBean)6 Test (org.junit.jupiter.api.Test)4 Application (org.kie.kogito.Application)3 DecisionModels (org.kie.kogito.decision.DecisionModels)3 EventEmitter (org.kie.kogito.event.EventEmitter)3 EventReceiver (org.kie.kogito.event.EventReceiver)3 CloudEvent (io.cloudevents.CloudEvent)2 StaticConfigBean (org.kie.kogito.conf.StaticConfigBean)2 TraceEvent (org.kie.kogito.tracing.event.trace.TraceEvent)2 PredictionModels (org.kie.kogito.prediction.PredictionModels)1