Search in sources :

Example 1 with HelloWorldFlowConfig

use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig 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));
}
Also used : Event(reactor.bus.Event) Payload(com.sequenceiq.cloudbreak.common.event.Payload) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HelloWorldFlowConfig(com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig) Test(org.junit.jupiter.api.Test)

Example 2 with HelloWorldFlowConfig

use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig 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 3 with HelloWorldFlowConfig

use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig 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)

Example 4 with HelloWorldFlowConfig

use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig in project cloudbreak by hortonworks.

the class Flow2ConfigTest method testFlowConfigurationMapInitIfAlreadyExists.

@Test
public void testFlowConfigurationMapInitIfAlreadyExists() {
    List<FlowConfiguration<?>> flowConfigs = new ArrayList<>();
    HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
    flowConfigs.add(helloWorldFlowConfig);
    flowConfigs.add(helloWorldFlowConfig);
    thrown.expect(UnsupportedOperationException.class);
    thrown.expectMessage("Event already registered: " + HelloWorldEvent.HELLOWORLD_TRIGGER_EVENT.event());
    underTest.flowConfigurationMap(flowConfigs);
}
Also used : ArrayList(java.util.ArrayList) HelloWorldFlowConfig(com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig) Test(org.junit.Test)

Example 5 with HelloWorldFlowConfig

use of com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig in project cloudbreak by hortonworks.

the class Flow2HandlerTest method testRestartFlowNoRestartActionNoFlowChainId.

@Test
public void testRestartFlowNoRestartActionNoFlowChainId() throws TransactionExecutionException {
    FlowLog flowLog = createFlowLog(null);
    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, never()).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

HelloWorldFlowConfig (com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig)9 Test (org.junit.jupiter.api.Test)6 Payload (com.sequenceiq.cloudbreak.common.event.Payload)4 ArrayList (java.util.ArrayList)4 FlowConfiguration (com.sequenceiq.flow.core.config.FlowConfiguration)3 FlowLog (com.sequenceiq.flow.domain.FlowLog)3 Test (org.junit.Test)3 FlowEventChainFactory (com.sequenceiq.flow.core.chain.FlowEventChainFactory)2 Selector (reactor.bus.selector.Selector)2 Consumer (reactor.fn.Consumer)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Event (reactor.bus.Event)1