use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testNewSyncFlowMaintenanceActive.
@Test
public void testNewSyncFlowMaintenanceActive() {
HelloWorldFlowConfig helloWorldFlowConfig = mock(HelloWorldFlowConfig.class);
given(helloWorldFlowConfig.getFlowTriggerCondition()).willReturn(new DefaultFlowTriggerCondition());
BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(helloWorldFlowConfig);
given(helloWorldFlowConfig.createFlow(anyString(), any(), anyLong(), any())).willReturn(flow);
given(helloWorldFlowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
given(helloWorldFlowConfig.getFlowOperationType()).willReturn(OperationType.UNKNOWN);
given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(FlowTriggerConditionResult.OK);
given(flow.getCurrentState()).willReturn(flowState);
Event<Payload> event = new Event<>(payload);
event.setKey("KEY");
event.getHeaders().set(FlowConstants.FLOW_TRIGGER_USERCRN, FLOW_TRIGGER_USERCRN);
underTest.accept(event);
verify(flowConfigurationMap, times(1)).get(anyString());
verify(runningFlows, times(1)).put(eq(flow), isNull(String.class));
verify(flowLogService, times(1)).save(any(FlowParameters.class), nullable(String.class), eq("KEY"), any(Payload.class), any(), ArgumentMatchers.eq(helloWorldFlowConfig.getClass()), eq(flowState));
verify(flow, times(1)).sendEvent(anyString(), anyString(), any(), any(), eq(UNKNOWN_OP_TYPE));
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testFlowRejectedBecauseNotTriggerable.
@Test
public void testFlowRejectedBecauseNotTriggerable() {
BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
given(flowConfig.createFlow(anyString(), any(), anyLong(), any())).willReturn(flow);
given(flowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
given(flow.getCurrentState()).willReturn(flowState);
when(flowTriggerCondition.isFlowTriggerable(anyLong())).thenReturn(new FlowTriggerConditionResult("It's not triggerable!"));
Promise accepted = mock(Promise.class);
Payload mockPayload = new MockPayload(accepted);
Event<Payload> event = new Event<>(mockPayload);
event.setKey("KEY");
underTest.accept(event);
verify(accepted, times(1)).onError(any(FlowNotTriggerableException.class));
verify(flowConfigurationMap, times(1)).get(anyString());
verify(runningFlows, times(0)).put(eq(flow), isNull(String.class));
verify(flowLogService, times(0)).save(any(FlowParameters.class), nullable(String.class), eq("KEY"), any(Payload.class), any(), eq(flowConfig.getClass()), eq(flowState));
verify(runningFlows, times(0)).remove(anyString());
verify(flow, times(0)).sendEvent(anyString(), anyString(), isNull(), any(), any());
}
use of com.sequenceiq.cloudbreak.common.event.Payload 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.cloudbreak.common.event.Payload 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());
}
use of com.sequenceiq.cloudbreak.common.event.Payload 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());
}
Aggregations