use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method checkPackageVersionsNotOk.
@Test
public void checkPackageVersionsNotOk() {
FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(flowEvent.name()).thenReturn(EVENT_NAME);
ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), 1L, statedImage);
when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
when(state.getId()).thenReturn(StackImageUpdateState.CHECK_PACKAGE_VERSIONS_STATE);
when(stackImageUpdateService.checkPackageVersions(any(Stack.class), any(StatedImage.class))).thenReturn(CheckResult.failed(""));
checkPackageVersionsAction.setFailureEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT);
checkPackageVersionsAction.execute(stateContext);
verify(stackImageUpdateService, times(1)).checkPackageVersions(any(Stack.class), any(StatedImage.class));
verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event()), any(Event.class));
verify(eventBus, times(0)).notify(eq(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT.event()), any(Event.class));
}
use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method checkImageVersionNotOk.
@Test
public void checkImageVersionNotOk() {
FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(flowEvent.name()).thenReturn(EVENT_NAME);
StackImageUpdateTriggerEvent payload = new StackImageUpdateTriggerEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_EVENT.event(), 1L, "imageId");
when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
when(state.getId()).thenReturn(StackImageUpdateState.CHECK_IMAGE_VERSIONS_STATE);
when(stackImageUpdateService.isCbVersionOk(any(Stack.class))).thenReturn(false);
checkImageAction.setFailureEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT);
checkImageAction.execute(stateContext);
verify(flowMessageService, times(1)).fireEventAndLog(anyLong(), eq(Status.UPDATE_IN_PROGRESS.name()), eq(ResourceEvent.STACK_IMAGE_UPDATE_STARTED));
verify(stackImageUpdateService, times(0)).getNewImageIfVersionsMatch(any(Stack.class), anyString(), eq(null), eq(null));
verify(eventBus, times(0)).notify(eq(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event()), any(Event.class));
verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT.event()), any(Event.class));
}
use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method prepareImageAction.
@Test
public void prepareImageAction() {
FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(flowEvent.name()).thenReturn(EVENT_NAME);
StackEvent payload = new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), 1L);
when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
when(state.getId()).thenReturn(StackImageUpdateState.IMAGE_PREPARE_STATE);
prepareImageAction.execute(stateContext);
verify(stackCreationService, times(1)).prepareImage(any(Stack.class), eq(variables));
verify(eventBus, times(1)).notify(eq(CloudPlatformRequest.selector(PrepareImageRequest.class)), any(Event.class));
}
use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method finishAction.
@Test
public void finishAction() {
FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
when(stateContext.getEvent()).thenReturn(flowEvent);
when(flowEvent.name()).thenReturn(EVENT_NAME);
CloudPlatformResult payload = new CloudPlatformResult(1L);
when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
when(state.getId()).thenReturn(StackImageUpdateState.STACK_IMAGE_UPDATE_FINISHED);
finishAction.execute(stateContext);
verify(flowMessageService, times(1)).fireEventAndLog(anyLong(), eq(Status.AVAILABLE.name()), eq(ResourceEvent.STACK_IMAGE_UPDATE_FINISHED));
}
use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.
the class FlowSelectors method assertUniquenessInFlowEventNames.
public void assertUniquenessInFlowEventNames(String packagePrefix) {
Reflections reflections = new Reflections(packagePrefix, new SubTypesScanner());
Set<Class<? extends FlowEvent>> eventClasses = reflections.getSubTypesOf(FlowEvent.class);
assertThat(eventClasses).withFailMessage("No FlowEvent subtypes found in package %s. Please check your 'packagePrefix' parameter.", packagePrefix).isNotEmpty();
Map<String, List<String>> names = new HashMap<>();
eventClasses.forEach(enumClass -> Arrays.stream(enumClass.getEnumConstants()).forEach(item -> names.compute(item.event(), (eventName, enumList) -> enumList == null ? new ArrayList<>(Arrays.asList(enumClass.getSimpleName())) : addToListAndReturn(enumList, enumClass.getSimpleName()))));
Map<String, List<String>> duplicates = names.entrySet().stream().filter(e -> e.getValue().size() > 1).collect(Collectors.toMap(Entry::getKey, Entry::getValue, this::mergeLists, TreeMap::new));
assertThat(duplicates).withFailMessage(() -> printDuplicates(duplicates)).isEmpty();
}
Aggregations