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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations