use of org.jboss.pnc.spi.BuildResult 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.spi.BuildResult in project pnc by project-ncl.
the class DatastoreAdapterTest method storeResult.
private void storeResult(DatastoreAdapter datastoreAdapter, BuildStatus buildStatus, CompletionStatus completionStatus) throws DatastoreException {
BuildDriverResult buildDriverResult = mock(BuildDriverResult.class);
when(buildDriverResult.getBuildStatus()).thenReturn(buildStatus);
when(buildDriverResult.getBuildLog()).thenReturn(BUILD_LOG);
RepositoryManagerResult repositoryManagerResult = mock(RepositoryManagerResult.class);
when(repositoryManagerResult.getCompletionStatus()).thenReturn(completionStatus);
when(repositoryManagerResult.getLog()).thenReturn(REPOSITORY_MANAGER_LOG);
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(buildDriverResult), Optional.of(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
BuildTask buildTask = mockBuildTask();
datastoreAdapter.storeResult(buildTask, buildResult);
}
use of org.jboss.pnc.spi.BuildResult in project pnc by project-ncl.
the class StatusUpdatesTest method createBuildResult.
private BuildResult createBuildResult() {
IndyRepositoryManagerResult repoManagerResult = new IndyRepositoryManagerResult(Collections.emptyList(), Collections.emptyList(), RandomStringUtils.randomNumeric(4));
BuildDriverResult driverResult = new BuildDriverResult() {
@Override
public String getBuildLog() {
return "";
}
@Override
public BuildStatus getBuildStatus() {
return BuildStatus.SUCCESS;
}
@Override
public Optional<String> getOutputChecksum() {
return Optional.of("3678bbe366b11f7216bd03ad33f583d9");
}
};
return new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.empty(), Optional.of(driverResult), Optional.of(repoManagerResult), Optional.empty(), Optional.empty());
}
use of org.jboss.pnc.spi.BuildResult in project pnc by project-ncl.
the class BuildExecutionTest method buildShouldFail.
@Test
public void buildShouldFail() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException {
BuildConfiguration buildConfiguration = configurationBuilder.buildFailingConfiguration(2, "failed-build", null);
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesBase();
expectedStatuses.add(DONE_WITH_ERRORS);
// check build statuses
checkBuildStatuses(statusChangedEvents, expectedStatuses);
}
use of org.jboss.pnc.spi.BuildResult in project pnc by project-ncl.
the class BuildExecutionTest method testBuild.
@Test
public void testBuild() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException {
BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesSuccess();
// check build statuses
checkBuildStatuses(statusChangedEvents, expectedStatuses);
// check results
BuildResult buildResult = buildExecutionResultWrapper.get();
// check results: logs
BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
String buildLog = buildDriverResult.getBuildLog();
Assert.assertTrue("Invalid build log.", buildLog.contains("Finished: SUCCESS"));
// check results: artifacts
RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
Assert.assertTrue("Missing build artifacts.", repositoryManagerResult.getBuiltArtifacts().size() > 0);
Assert.assertTrue("Missing build dependencies.", repositoryManagerResult.getDependencies().size() > 0);
Artifact artifact = repositoryManagerResult.getBuiltArtifacts().iterator().next();
Assert.assertTrue("Invalid built artifact in the result.", artifact.getIdentifier().startsWith(ArtifactBuilder.IDENTIFIER_PREFIX));
}
Aggregations