Search in sources :

Example 1 with BuildRecord

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);
}
Also used : TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Test(org.junit.Test)

Example 2 with BuildRecord

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());
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 3 with BuildRecord

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());
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 4 with BuildRecord

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;
}
Also used : ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildRecord(org.jboss.pnc.model.BuildRecord) Result(org.jboss.pnc.spi.coordinator.Result)

Example 5 with BuildRecord

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);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) IdRev(org.jboss.pnc.model.IdRev) BuildRecord(org.jboss.pnc.model.BuildRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BuildRecord (org.jboss.pnc.model.BuildRecord)92 Test (org.junit.Test)50 Base32LongID (org.jboss.pnc.model.Base32LongID)19 Build (org.jboss.pnc.dto.Build)15 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)15 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 Artifact (org.jboss.pnc.model.Artifact)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)13 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)13 Date (java.util.Date)12 List (java.util.List)12 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)12 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)11 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 BuildStatus (org.jboss.pnc.enums.BuildStatus)10