Search in sources :

Example 26 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog 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 27 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog 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)

Example 28 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class EventBusConfigTest method unknownMessageButFlowFound.

@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void unknownMessageButFlowFound() {
    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.notify("notexist", 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 : FlowLog(com.sequenceiq.flow.domain.FlowLog) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 29 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowCancelServiceTest method testCancelFlow.

@Test
public void testCancelFlow() throws TransactionExecutionException {
    FlowLog flowLog = new FlowLog();
    flowLog.setResourceId(1L);
    flowLog.setFlowId("flowid");
    underTest.cancelFlow(flowLog);
    verify(flow2Handler, times(1)).cancelFlow(flowLog.getResourceId(), flowLog.getFlowId());
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Test(org.junit.Test)

Example 30 with FlowLog

use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.

the class FlowRetryServiceTest method retry.

@Test
public void retry() {
    FlowLog lastSuccessfulState = createFlowLog("INTERMEDIATE_STATE", StateStatus.SUCCESSFUL, 5, TestFlowEvent.TEST_FINISHED_EVENT.event());
    List<FlowLog> pendingFlowLogs = Lists.newArrayList(createFlowLog("FINISHED", StateStatus.SUCCESSFUL, 7, null), createFlowLog("NEXT_STATE", StateStatus.FAILED, 6, TestFlowEvent.TEST_FAIL_HANDLED_EVENT.event()), lastSuccessfulState, createFlowLog("FINISHED", StateStatus.SUCCESSFUL, 4, null), createFlowLog("NEXT_STATE", StateStatus.FAILED, 3, TestFlowEvent.TEST_FAIL_HANDLED_EVENT.event()), createFlowLog("INTERMEDIATE_STATE", StateStatus.SUCCESSFUL, 2, TestFlowEvent.TEST_FINISHED_EVENT.event()), createFlowLog("INIT_STATE", StateStatus.SUCCESSFUL, 1, TestFlowEvent.TEST_FLOW_EVENT.event()));
    when(flowLogRepository.findAllByResourceIdOrderByCreatedDesc(STACK_ID, PageRequest.of(0, 50))).thenReturn(pendingFlowLogs);
    underTest.retry(STACK_ID);
    verify(flow2Handler, times(1)).restartFlow(ArgumentMatchers.eq(lastSuccessfulState));
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Test(org.junit.Test)

Aggregations

FlowLog (com.sequenceiq.flow.domain.FlowLog)92 Test (org.junit.jupiter.api.Test)25 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)21 List (java.util.List)13 FlowConfiguration (com.sequenceiq.flow.core.config.FlowConfiguration)12 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)11 Mockito.times (org.mockito.Mockito.times)11 Mockito.verify (org.mockito.Mockito.verify)11 Mockito.when (org.mockito.Mockito.when)11 HelloWorldFlowConfig (com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig)10 Map (java.util.Map)10 UUID (java.util.UUID)10 Collectors (java.util.stream.Collectors)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Clock (com.sequenceiq.cloudbreak.common.service.Clock)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)9 FlowRegister (com.sequenceiq.flow.core.FlowRegister)9 SecureRandom (java.security.SecureRandom)9 Random (java.util.Random)9