use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class ProjectWithDependenciesBuildTest method buildProjectTestCase.
@Test
public void buildProjectTestCase() throws Exception {
clearSemaphores();
// given
testCDIBuildSetStatusChangedReceiver.addBuildSetStatusChangedEventListener(this::collectEvent);
DatastoreMock datastoreMock = new DatastoreMock();
TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
// when
BuildCoordinatorBeans coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock);
buildProjects(configurationBuilder.buildConfigurationSet(BUILD_SET_ID), coordinator.coordinator);
// expect
List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
log.trace("Found build records: {}", buildRecords.stream().map(br -> "Br.id: " + br.getId() + ", " + br.getBuildConfigurationAudited().getId().toString()).collect(Collectors.joining("; ")));
Assert.assertEquals("Wrong datastore results count.", 5, buildRecords.size());
BuildRecord buildRecord = buildRecords.get(0);
String buildLog = buildRecord.getBuildLog();
Assert.assertTrue("Invalid build log.", buildLog.contains("Finished: SUCCESS"));
assertArtifactsPresent(buildRecord.getBuiltArtifacts());
assertArtifactsPresent(buildRecord.getDependencies());
BuildConfigSetRecord buildConfigSetRecord = datastoreMock.getBuildConfigSetRecords().get(0);
Assert.assertNotNull("End time not set! Record: " + buildConfigSetRecord, buildConfigSetRecord.getEndTime());
Assert.assertTrue(buildConfigSetRecord.getEndTime().getTime() > buildConfigSetRecord.getStartTime().getTime());
Assert.assertEquals(BuildStatus.SUCCESS, buildConfigSetRecord.getStatus());
String events = eventsReceived.stream().map(Object::toString).collect(Collectors.joining("; "));
Assert.assertEquals("Invalid number of received events. Received events: " + events, 2, eventsReceived.size());
Wait.forCondition(coordinator.queue::isEmpty, 1, ChronoUnit.SECONDS, "Not empty build queue: " + coordinator.queue);
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class ProjectWithFailedDependenciesBuildTest method checkDatabaseForResult.
@Test
@InSequence(20)
public void checkDatabaseForResult() {
List<BuildRecord> buildRecords = datastore.getBuildRecords();
Assert.assertEquals("Wrong datastore results count. Got records: " + buildRecords, 2, buildRecords.size());
Assert.assertEquals(BuildStatus.FAILED, buildRecords.get(0).getStatus());
Assert.assertEquals(BuildStatus.REJECTED_FAILED_DEPENDENCIES, buildRecords.get(1).getStatus());
BuildConfigSetRecord buildConfigSetRecord = datastore.getBuildConfigSetRecords().get(0);
Assert.assertNotNull("End time is null.", buildConfigSetRecord.getEndTime());
Assert.assertTrue(buildConfigSetRecord.getEndTime().getTime() > buildConfigSetRecord.getStartTime().getTime());
Assert.assertEquals(BuildStatus.FAILED, buildConfigSetRecord.getStatus());
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class ProjectWithFailedTransitiveDependenciesBuildTest method checkDatabaseForResult.
@Test
@InSequence(20)
public void checkDatabaseForResult() {
List<BuildRecord> buildRecords = datastore.getBuildRecords();
Assert.assertEquals("Wrong datastore results count. Got records: " + buildRecords, 3, buildRecords.size());
Assert.assertEquals(BuildStatus.FAILED, buildRecords.get(0).getStatus());
Assert.assertEquals(BuildStatus.REJECTED_FAILED_DEPENDENCIES, buildRecords.get(1).getStatus());
BuildConfigSetRecord buildConfigSetRecord = datastore.getBuildConfigSetRecords().get(0);
Assert.assertNotNull("End time is null.", buildConfigSetRecord.getEndTime());
Assert.assertTrue(buildConfigSetRecord.getEndTime().getTime() > buildConfigSetRecord.getStartTime().getTime());
Assert.assertEquals(BuildStatus.FAILED, buildConfigSetRecord.getStatus());
Assert.assertTrue("Build queue should be empty.", buildQueue.isEmpty());
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class TemporaryBuildsCleanerAsyncInvoker method deleteTemporaryBuild.
/**
* Deletes a single temporary build.
*
* @param buildRecordId ID of the build to be deleted
* @param authToken Bearer token
* @param onComplete Operation to be executed after deletion operation
* @return True if the build exists and deletion started otherwise, false is build doesn't exist
* @throws ValidationException Thrown when build cannot be deleted
*/
public boolean deleteTemporaryBuild(Base32LongID buildRecordId, String authToken, Consumer<Result> onComplete) throws ValidationException {
BuildRecord buildRecord = buildRecordRepository.findByIdFetchAllProperties(buildRecordId);
if (buildRecord == null) {
return false;
}
if (!buildRecord.isTemporaryBuild()) {
throw new ValidationException("Only deletion of the temporary builds is allowed");
}
executorService.submit(() -> {
try {
Result result = temporaryBuildsCleaner.deleteTemporaryBuild(buildRecordId, authToken);
onComplete.accept(result);
} catch (ValidationException e) {
logger.error("Failed to delete temporary buildRecord.id: " + buildRecordId + ".", e);
onComplete.accept(new Result(buildRecordId.toString(), ResultStatus.FAILED, "Failed to delete temporary buildRecord."));
}
});
return true;
}
use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.
the class DefaultBuildCoordinatorTest method shouldCreateNoRebuildRequiredRecords.
@Test
public void shouldCreateNoRebuildRequiredRecords() throws CoreException, TimeoutException, InterruptedException {
when(datastore.requiresRebuild(any(BuildConfigurationAudited.class), any(Boolean.class), any(Boolean.class), nullable(AlignmentPreference.class), anySet())).thenReturn(false);
BuildConfigurationAudited bca1 = new BuildConfigurationAudited();
IdRev idRev1 = new IdRev(BC_1.getId(), BC_1.getId() * 1000 + 1);
bca1.setIdRev(idRev1);
bca1.setId(idRev1.getId());
bca1.setRev(idRev1.getRev());
bca1.setProject(PROJECT);
when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_1.getId())).thenReturn(bca1);
BuildConfigurationAudited bca3 = new BuildConfigurationAudited();
IdRev idRev3 = new IdRev(BC_3.getId(), BC_3.getId() * 1000 + 1);
bca3.setIdRev(idRev3);
bca3.setId(idRev3.getId());
bca3.setRev(idRev3.getRev());
bca3.setProject(PROJECT);
when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_3.getId())).thenReturn(bca3);
Set<BuildConfiguration> buildConfigs = new HashSet<>();
buildConfigs.add(BC_1);
buildConfigs.add(BC_3);
when(datastore.getBuildConfigurations(any())).thenReturn(buildConfigs);
Set<BuildRecord> storedRecords = new HashSet<>();
when(datastore.storeRecordForNoRebuild(any())).thenAnswer(new SaveRecordForNoRebuildAnswer(storedRecords));
BuildSetTask bsTask = coordinator.build(BCS, USER, BUILD_OPTIONS);
coordinator.start();
assertThat(bsTask.getBuildConfigSetRecord().get().getStatus()).isEqualTo(BuildStatus.NO_REBUILD_REQUIRED);
Wait.forCondition(() -> storedRecords.size() == 2, 3, ChronoUnit.SECONDS);
assertThat(storedRecords.size()).isEqualTo(2);
}
Aggregations