use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildProviderImplTest method testGetBuilds.
@Test
public void testGetBuilds() {
// Prepare
// hit
mockBuildRecord();
// hit
mockBuildTask();
// hit
mockBuildRecord();
// hit
mockBuildTask();
// hit
mockBuildRecord();
// hit
mockBuildTask();
// hit
BuildRecord build2 = mockBuildRecord();
// hit
BuildTask build1 = mockBuildTask();
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 2, "", "", false, false, "");
Page<Build> builds = provider.getBuilds(pageInfo);
// Verify
assertEquals(8, builds.getTotalHits());
assertEquals(2, builds.getContent().size());
Iterator<Build> it = builds.getContent().iterator();
assertEquals(build1.getId(), it.next().getId());
assertEquals(BuildMapper.idMapper.toDto(build2.getId()), it.next().getId());
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildProviderImplTest method testGetBuildsPages.
@Test
public void testGetBuildsPages() {
// Prepare
BuildRecord build8 = mockBuildRecord();
BuildTask build7 = mockBuildTask();
BuildRecord build6 = mockBuildRecord();
BuildTask build5 = mockBuildTask();
BuildRecord build4 = mockBuildRecord();
BuildTask build3 = mockBuildTask();
BuildRecord build2 = mockBuildRecord();
BuildTask build1 = mockBuildTask();
testPage(0, 2, new Base32LongID(build1.getId()), build2.getId());
testPage(1, 2, new Base32LongID(build3.getId()), build4.getId());
testPage(2, 2, new Base32LongID(build5.getId()), build6.getId());
testPage(3, 2, new Base32LongID(build7.getId()), build8.getId());
testPage(1, 3, build4.getId(), new Base32LongID(build5.getId()), build6.getId());
testPage(2, 3, new Base32LongID(build7.getId()), build8.getId());
testPage(2, 10);
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildProviderImpl method getSpecific.
@Override
public Build getSpecific(String buildId) {
List<BuildTask> runningBuilds = buildCoordinator.getSubmittedBuildTasks();
Build build = runningBuilds.stream().filter(buildTask -> buildId.equals(buildTask.getId())).findAny().map(buildMapper::fromBuildTask).orElse(null);
// if build not in runningBuilds, check the database
if (build == null) {
// use findByIdFetchProperties instead of super.getSpecific to get 'BuildConfigurationAudited' object
build = mapper.toDTO(buildRecordRepository.findByIdFetchProperties(parseId(buildId)));
}
return build;
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class BuildConfigurationProviderImpl method populateBuildConfigWithLatestBuild.
private BuildConfigurationWithLatestBuild populateBuildConfigWithLatestBuild(BuildConfiguration buildConfig, List<BuildRecord> latestBuilds, List<BuildTask> runningBuilds) {
Integer bcId = mapper.getIdMapper().toEntity(buildConfig.getId());
Optional<BuildTask> latestBuildTask = runningBuilds.stream().filter(Objects::nonNull).filter(bt -> bt.getBuildConfigurationAudited().getId().equals(bcId)).max(Comparator.comparing(BuildTask::getSubmitTime));
Optional<BuildRecord> latestBuildRecord = latestBuilds.stream().filter(br -> br.getBuildConfigurationId().equals(bcId)).findFirst();
BuildRef latestBuild = latestBuildTask.map((bt -> (BuildRef) buildMapper.fromBuildTask(bt))).orElse(latestBuildRecord.map(buildMapper::toRef).orElse(null));
String latestBuildUsername = latestBuildTask.map(bt -> bt.getUser().getUsername()).orElse(latestBuildRecord.map(br -> br.getUser().getUsername()).orElse(null));
return BuildConfigurationWithLatestBuild.builderWithLatestBuild().buildConfig(buildConfig).latestBuild(latestBuild).latestBuildUsername(latestBuildUsername).build();
}
use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.
the class CancelledBuildTest method buildSingleProjectTestCase.
@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
// given
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastore);
BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastore).coordinator;
List<BuildStatusChangedEvent> receivedStatuses = new ArrayList<>();
Consumer<BuildStatusChangedEvent> onStatusUpdate = (event) -> {
receivedStatuses.add(event);
if (event.getNewStatus().equals(BuildStatus.BUILDING)) {
CompletableFuture.runAsync(() -> {
try {
// wait a bit for build execution to start
Thread.sleep(250);
coordinator.cancel(event.getBuild().getId());
} catch (CoreException | InterruptedException e) {
log.error("Unable to cancel the build.", e);
Assert.fail("Unable to cancel the build.");
}
});
}
};
// when
BuildTask buildTask = buildProject(configurationBuilder.buildConfigurationToCancel(1, "c1-java"), coordinator, onStatusUpdate);
// expect
List<BuildRecord> buildRecords = datastore.getBuildRecords();
Assert.assertEquals("Too many build records in datastore: " + buildRecords, 1, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
Assert.assertNotNull(buildRecord.getSubmitTime());
Assert.assertNotNull(buildRecord.getStartTime());
Assert.assertNotNull(buildRecord.getEndTime());
Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
String buildTaskId = buildTask.getId();
assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
}
Aggregations