use of org.jboss.pnc.common.util.ObjectWrapper in project pnc by project-ncl.
the class BuildEnvironmentTest method shouldReportErrorInCaseOfPodCreationFailure.
@Test
public void shouldReportErrorInCaseOfPodCreationFailure() throws ExecutorException, InterruptedException, TimeoutException {
BuildConfiguration buildConfiguration = configurationBuilder.build(123, "Pod creation failure");
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, true);
checkBuildStatuses(statusChangedEvents, Arrays.asList(BUILD_ENV_SETTING_UP, BUILD_ENV_WAITING, BUILD_ENV_SETUP_COMPLETE_WITH_ERROR, // supported yet
DONE_WITH_ERRORS));
assertNoState(statusChangedEvents, BUILD_ENV_SETUP_COMPLETE_SUCCESS);
assertNoState(statusChangedEvents, BUILD_SETTING_UP);
}
use of org.jboss.pnc.common.util.ObjectWrapper in project pnc by project-ncl.
the class BuildEnvironmentTest method runBuild.
private void runBuild(BuildConfiguration buildConfiguration, Set<BuildExecutionStatusChangedEvent> statusChangedEvents, ObjectWrapper<BuildResult> buildExecutionResultWrapper, boolean keepAliveOnFailure) throws ExecutorException {
DefaultBuildExecutor executor = null;
try {
executor = new DefaultBuildExecutor(repositoryManagerFactory, buildDriverFactory, environmentDriverFactory, new Configuration(), null);
} catch (ConfigurationParseException e) {
log.error(e.toString());
}
Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
log.debug("Received execution status update {}.", statusChangedEvent);
statusChangedEvents.add(statusChangedEvent);
if (statusChangedEvent.getNewStatus().isCompleted()) {
BuildResult buildResult = statusChangedEvent.getBuildResult().get();
buildExecutionResultWrapper.set(buildResult);
}
};
BuildExecutionConfiguration buildExecutionConfiguration = new DefaultBuildExecutionConfiguration("1", "build-content-id", "1", buildConfiguration.getBuildScript(), buildConfiguration.getId().toString(), buildConfiguration.getName(), buildConfiguration.getRepositoryConfiguration().getInternalUrl(), buildConfiguration.getScmRevision(), null, buildConfiguration.getRepositoryConfiguration().getExternalUrl(), buildConfiguration.getRepositoryConfiguration().isPreBuildSyncEnabled(), buildConfiguration.getBuildType(), buildConfiguration.getBuildEnvironment().getSystemImageId(), buildConfiguration.getBuildEnvironment().getSystemImageRepositoryUrl(), buildConfiguration.getBuildEnvironment().getSystemImageType(), keepAliveOnFailure, null, buildConfiguration.getGenericParameters(), false, null, buildConfiguration.isBrewPullActive(), buildConfiguration.getDefaultAlignmentParams(), AlignmentPreference.PREFER_TEMPORARY);
executor.startBuilding(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent, "");
}
use of org.jboss.pnc.common.util.ObjectWrapper in project pnc by project-ncl.
the class BuildExecutionBase method runBuild.
protected void runBuild(BuildConfiguration buildConfiguration, Set<BuildExecutionStatusChangedEvent> statusChangedEvents, ObjectWrapper<BuildResult> buildExecutionResultWrapper, Consumer<BuildExecutionStatusChangedEvent> onStatusUpdate, BuildExecutor executor) throws ExecutorException {
Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent = (statusChangedEvent) -> {
log.debug("Received execution status update {}.", statusChangedEvent);
statusChangedEvents.add(statusChangedEvent);
onStatusUpdate.accept(statusChangedEvent);
if (statusChangedEvent.getNewStatus().isCompleted()) {
BuildResult buildResult = statusChangedEvent.getBuildResult().get();
buildExecutionResultWrapper.set(buildResult);
}
};
BuildExecutionConfiguration buildExecutionConfiguration = new DefaultBuildExecutionConfiguration("1", "build-content-id", "1", buildConfiguration.getBuildScript(), buildConfiguration.getId().toString(), buildConfiguration.getName(), buildConfiguration.getRepositoryConfiguration().getInternalUrl(), buildConfiguration.getScmRevision(), null, buildConfiguration.getRepositoryConfiguration().getExternalUrl(), buildConfiguration.getRepositoryConfiguration().isPreBuildSyncEnabled(), buildConfiguration.getBuildType(), buildConfiguration.getBuildEnvironment().getSystemImageId(), buildConfiguration.getBuildEnvironment().getSystemImageRepositoryUrl(), buildConfiguration.getBuildEnvironment().getSystemImageType(), false, null, buildConfiguration.getGenericParameters(), false, null, buildConfiguration.isBrewPullActive(), buildConfiguration.getDefaultAlignmentParams(), AlignmentPreference.PREFER_TEMPORARY);
executor.startBuilding(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent, "");
}
use of org.jboss.pnc.common.util.ObjectWrapper in project pnc by project-ncl.
the class BuildExecutionCancellationTest method testBuild.
@Test(timeout = 3000)
public void testBuild() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException, ConfigurationParseException {
BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
DefaultBuildExecutor executor = new DefaultBuildExecutor(repositoryManagerFactory, buildDriverFactory, environmentDriverFactory, new Configuration(), null);
Consumer<BuildExecutionStatusChangedEvent> cancel = (e) -> {
if (BuildExecutionStatus.BUILD_WAITING.equals(e.getNewStatus())) {
try {
log.info("Cancelling build ...");
Thread.sleep(100);
executor.cancel(e.getBuildTaskId());
} catch (ExecutorException | InterruptedException e0) {
e0.printStackTrace();
}
}
};
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, cancel, executor);
List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesBase();
expectedStatuses.add(BuildExecutionStatus.CANCELLED);
// check build statuses
checkBuildStatuses(statusChangedEvents, expectedStatuses);
// check results
BuildResult buildResult = buildExecutionResultWrapper.get();
BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
Assert.assertEquals(BuildStatus.CANCELLED, buildDriverResult.getBuildStatus());
}
use of org.jboss.pnc.common.util.ObjectWrapper in project pnc by project-ncl.
the class StatusUpdatesTest method buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState.
@Test
@InSequence(10)
public void buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState() throws DatastoreException, InterruptedException, CoreException {
ObjectWrapper<BuildSetStatusChangedEvent> receivedBuildSetStatusChangedEvent = new ObjectWrapper<>();
Consumer<BuildSetStatusChangedEvent> statusUpdateListener = receivedBuildSetStatusChangedEvent::set;
testCDIBuildSetStatusChangedReceiver.addBuildSetStatusChangedEventListener(statusUpdateListener);
User user = User.Builder.newBuilder().id(1).username("test-user-1").build();
Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> {
}).getBuildTasks();
buildTasks.forEach((bt) -> {
buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE);
buildCoordinator.completeBuild(bt, createBuildResult());
});
this.waitForConditionWithTimeout(() -> buildTasks.stream().allMatch(task -> task.getStatus().isCompleted()), 4);
Assert.assertNotNull("Did not receive build set status update.", receivedBuildSetStatusChangedEvent.get());
Assert.assertEquals(BuildSetStatus.DONE, receivedBuildSetStatusChangedEvent.get().getNewStatus());
}
Aggregations