Search in sources :

Example 21 with FlowLog

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

the class Flow2HandlerTest method testExistingFlow.

@Test
public void testExistingFlow() {
    FlowLog lastFlowLog = new FlowLog();
    lastFlowLog.setNextEvent("KEY");
    Optional<FlowLog> flowLogOptional = Optional.of(lastFlowLog);
    BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
    given(runningFlows.get(anyString())).willReturn(flow);
    given(flow.getCurrentState()).willReturn(flowState);
    given(flow.getFlowId()).willReturn(FLOW_ID);
    given(flowLogService.getLastFlowLog(FLOW_ID)).willReturn(flowLogOptional);
    dummyEvent.setKey("KEY");
    ArgumentCaptor<FlowParameters> flowParamsCaptor = ArgumentCaptor.forClass(FlowParameters.class);
    underTest.accept(dummyEvent);
    verify(flowLogService, times(1)).save(flowParamsCaptor.capture(), nullable(String.class), eq("KEY"), any(Payload.class), anyMap(), nullable(Class.class), eq(flowState));
    verify(flow, times(1)).sendEvent(eq("KEY"), isNull(), any(), any(), any());
    FlowParameters flowParameters = flowParamsCaptor.getValue();
    assertEquals(FLOW_ID, flowParameters.getFlowId());
    assertNull(flowParameters.getFlowTriggerUserCrn());
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 22 with FlowLog

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

the class Flow2HandlerTest method testFinalizedFlow.

@Test
public void testFinalizedFlow() {
    FlowLog lastFlowLog = new FlowLog();
    lastFlowLog.setFinalized(true);
    Optional<FlowLog> flowLogOptional = Optional.of(lastFlowLog);
    BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
    given(runningFlows.get(anyString())).willReturn(flow);
    given(flow.getCurrentState()).willReturn(flowState);
    given(flow.getFlowId()).willReturn(FLOW_ID);
    given(flowLogService.getLastFlowLog(FLOW_ID)).willReturn(flowLogOptional);
    dummyEvent.setKey("KEY");
    ArgumentCaptor<FlowParameters> flowParamsCaptor = ArgumentCaptor.forClass(FlowParameters.class);
    underTest.accept(dummyEvent);
    verify(flowLogService, times(1)).save(flowParamsCaptor.capture(), nullable(String.class), eq("KEY"), any(Payload.class), anyMap(), nullable(Class.class), eq(flowState));
    verify(flow, times(1)).sendEvent(eq("KEY"), isNull(), any(), any(), any());
    FlowParameters flowParameters = flowParamsCaptor.getValue();
    assertEquals(FLOW_ID, flowParameters.getFlowId());
    assertNull(flowParameters.getFlowTriggerUserCrn());
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 23 with FlowLog

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

the class Flow2HandlerTest method testRestartFlow.

@Test
public void testRestartFlow() throws TransactionExecutionException {
    FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID);
    Payload payload = new TestPayload(STACK_ID);
    flowLog.setPayloadType(ClassValue.of(TestPayload.class));
    flowLog.setPayload(JsonWriter.objectToJson(payload));
    when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
    HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
    ReflectionTestUtils.setField(helloWorldFlowConfig, "defaultRestartAction", defaultRestartAction);
    setUpFlowConfigCreateFlow(helloWorldFlowConfig);
    List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
    ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
    underTest.restartFlow(FLOW_ID);
    ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class);
    ArgumentCaptor<FlowParameters> flowParamsCaptor = ArgumentCaptor.forClass(FlowParameters.class);
    verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID);
    verify(flowLogService, never()).terminate(STACK_ID, FLOW_ID);
    verify(defaultRestartAction, times(1)).restart(flowParamsCaptor.capture(), eq(FLOW_CHAIN_ID), eq(NEXT_EVENT), payloadCaptor.capture());
    Payload captorValue = payloadCaptor.getValue();
    assertEquals(STACK_ID, captorValue.getResourceId());
    FlowParameters flowParameters = flowParamsCaptor.getValue();
    assertEquals(FLOW_ID, flowParameters.getFlowId());
    assertEquals(FLOW_TRIGGER_USERCRN, flowParameters.getFlowTriggerUserCrn());
}
Also used : FlowConfiguration(com.sequenceiq.flow.core.config.FlowConfiguration) FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) HelloWorldFlowConfig(com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig) Test(org.junit.jupiter.api.Test)

Example 24 with FlowLog

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

the class Flow2HandlerTest method testExistingFlowRepeatedState.

@Test
public void testExistingFlowRepeatedState() {
    BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
    given(runningFlows.get(anyString())).willReturn(flow);
    given(flow.getCurrentState()).willReturn(flowState);
    given(flow.getFlowId()).willReturn(FLOW_ID);
    Map<Object, Object> variables = Map.of("repeated", 2);
    given(flow.getVariables()).willReturn(variables);
    FlowLog lastFlowLog = new FlowLog();
    lastFlowLog.setNextEvent("KEY");
    Optional<FlowLog> flowLogOptional = Optional.of(lastFlowLog);
    given(flowLogService.getLastFlowLog(FLOW_ID)).willReturn(flowLogOptional);
    given(flowLogService.repeatedFlowState(lastFlowLog, "KEY")).willReturn(true);
    dummyEvent.setKey("KEY");
    underTest.accept(dummyEvent);
    verify(flowLogService, times(1)).updateLastFlowLogPayload(lastFlowLog, payload, variables);
    verify(flow, times(1)).sendEvent(eq("KEY"), isNull(), any(), any(), any());
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Test(org.junit.jupiter.api.Test)

Example 25 with FlowLog

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

the class Flow2HandlerTest method testRestartFlowNoRestartAction.

@Test
public void testRestartFlowNoRestartAction() throws TransactionExecutionException {
    FlowLog flowLog = createFlowLog(FLOW_CHAIN_ID);
    Payload payload = new TestPayload(STACK_ID);
    flowLog.setPayloadType(ClassValue.of(TestPayload.class));
    flowLog.setPayload(JsonWriter.objectToJson(payload));
    when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
    HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
    setUpFlowConfigCreateFlow(helloWorldFlowConfig);
    List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
    ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
    underTest.restartFlow(FLOW_ID);
    verify(flowChainHandler, times(1)).restoreFlowChain(FLOW_CHAIN_ID);
    verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID);
    verify(defaultRestartAction, never()).restart(any(), any(), any(), any());
}
Also used : FlowConfiguration(com.sequenceiq.flow.core.config.FlowConfiguration) FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) HelloWorldFlowConfig(com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig) Test(org.junit.jupiter.api.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