Search in sources :

Example 1 with FlowLogDBService

use of com.sequenceiq.flow.service.flowlog.FlowLogDBService in project cloudbreak by hortonworks.

the class EventBusConfigTest method uncaughtErrorButFlowNotFound.

@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void uncaughtErrorButFlowNotFound() {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowId("123");
    when(flowLogDBService.getLastFlowLog("123")).thenReturn(Optional.empty());
    Event.Headers headers = new Event.Headers();
    headers.set("FLOW_ID", "123");
    eventBus.on(Selectors.regex("exampleselector"), (Consumer<Event<? extends Payload>>) event -> {
        throw new RuntimeException("uncaught exception");
    });
    eventBus.notify("exampleselector", new Event<>(headers, null));
    verify(flowLogDBService, timeout(2000).times(1)).getLastFlowLog("123");
    verify(applicationFlowInformation, times(0)).handleFlowFail(any());
    verify(flowLogDBService, times(0)).updateLastFlowLogStatus(any(), anyBoolean());
    verify(flowLogDBService, times(0)).finalize(any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DirtiesContext(org.springframework.test.annotation.DirtiesContext) FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) RunWith(org.junit.runner.RunWith) Mockito.times(org.mockito.Mockito.times) EventBus(reactor.bus.EventBus) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.verify(org.mockito.Mockito.verify) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) Mockito.timeout(org.mockito.Mockito.timeout) Selectors(reactor.bus.selector.Selectors) ApplicationFlowInformation(com.sequenceiq.flow.core.ApplicationFlowInformation) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Event(reactor.bus.Event) Optional(java.util.Optional) FlowLogDBService(com.sequenceiq.flow.service.flowlog.FlowLogDBService) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Consumer(reactor.fn.Consumer) MockBean(org.springframework.boot.test.mock.mockito.MockBean) FlowLog(com.sequenceiq.flow.domain.FlowLog) Event(reactor.bus.Event) Payload(com.sequenceiq.cloudbreak.common.event.Payload) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 2 with FlowLogDBService

use of com.sequenceiq.flow.service.flowlog.FlowLogDBService in project cloudbreak by hortonworks.

the class EventBusConfigTest method uncaughtErrorButFlowFound.

@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void uncaughtErrorButFlowFound() {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowId("123");
    when(flowLogDBService.getLastFlowLog("123")).thenReturn(Optional.of(flowLog));
    Event.Headers headers = new Event.Headers();
    headers.set("FLOW_ID", "123");
    eventBus.on(Selectors.regex("exampleselector"), (Consumer<Event<? extends Payload>>) event -> {
        throw new RuntimeException("uncaught exception");
    });
    eventBus.notify("exampleselector", new Event<>(headers, null));
    verify(flowLogDBService, timeout(2000).times(1)).getLastFlowLog("123");
    verify(applicationFlowInformation, timeout(1000).times(1)).handleFlowFail(flowLog);
    verify(flowLogDBService, timeout(1000).times(1)).updateLastFlowLogStatus(flowLog, true);
    verify(flowLogDBService, timeout(1000).times(1)).finalize(flowLog.getFlowId());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DirtiesContext(org.springframework.test.annotation.DirtiesContext) FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) RunWith(org.junit.runner.RunWith) Mockito.times(org.mockito.Mockito.times) EventBus(reactor.bus.EventBus) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.verify(org.mockito.Mockito.verify) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) Mockito.timeout(org.mockito.Mockito.timeout) Selectors(reactor.bus.selector.Selectors) ApplicationFlowInformation(com.sequenceiq.flow.core.ApplicationFlowInformation) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Event(reactor.bus.Event) Optional(java.util.Optional) FlowLogDBService(com.sequenceiq.flow.service.flowlog.FlowLogDBService) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Consumer(reactor.fn.Consumer) MockBean(org.springframework.boot.test.mock.mockito.MockBean) FlowLog(com.sequenceiq.flow.domain.FlowLog) Event(reactor.bus.Event) Payload(com.sequenceiq.cloudbreak.common.event.Payload) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

Payload (com.sequenceiq.cloudbreak.common.event.Payload)2 ApplicationFlowInformation (com.sequenceiq.flow.core.ApplicationFlowInformation)2 FlowLog (com.sequenceiq.flow.domain.FlowLog)2 FlowLogDBService (com.sequenceiq.flow.service.flowlog.FlowLogDBService)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 Test (org.junit.jupiter.api.Test)2 RunWith (org.junit.runner.RunWith)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)2 Mockito.timeout (org.mockito.Mockito.timeout)2 Mockito.times (org.mockito.Mockito.times)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockBean (org.springframework.boot.test.mock.mockito.MockBean)2 DirtiesContext (org.springframework.test.annotation.DirtiesContext)2 SpringRunner (org.springframework.test.context.junit4.SpringRunner)2 Event (reactor.bus.Event)2 EventBus (reactor.bus.EventBus)2