Search in sources :

Example 11 with Payload

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));
}
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 12 with Payload

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());
}
Also used : Promise(reactor.rx.Promise) FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) Event(reactor.bus.Event) Payload(com.sequenceiq.cloudbreak.common.event.Payload) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 13 with Payload

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());
}
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 14 with Payload

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());
}
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 15 with Payload

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

Aggregations

Payload (com.sequenceiq.cloudbreak.common.event.Payload)36 Test (org.junit.jupiter.api.Test)11 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 Optional (java.util.Optional)10 Inject (javax.inject.Inject)10 Event (reactor.bus.Event)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)8 List (java.util.List)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 Location (com.sequenceiq.cloudbreak.cloud.model.Location)7 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)7 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)7 FlowParameters (com.sequenceiq.flow.core.FlowParameters)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 StateContext (org.springframework.statemachine.StateContext)7 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)6