Search in sources :

Example 6 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class CancelledBuildTest method cancelBuildingConfigSetTestCase.

@Test(timeout = 5_000)
public void cancelBuildingConfigSetTestCase() throws Exception {
    // given
    DatastoreMock datastoreMock = new DatastoreMock();
    TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
    BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock).coordinator;
    BuildConfigurationSet configurationSet = configurationBuilder.buildConfigurationSetForCancel(1);
    List<BuildStatusChangedEvent> receivedStatuses = new ArrayList<>();
    Consumer<BuildStatusChangedEvent> onStatusUpdate = (event) -> {
        receivedStatuses.add(event);
        if (event.getBuild().getBuildConfigRevision().getId().equals("2") && event.getNewStatus().equals(BuildStatus.BUILDING)) {
            CompletableFuture.runAsync(() -> {
                try {
                    // wait a bit for build execution to start
                    Thread.sleep(250);
                    // we need to get buildConfigSet id to cancel BuildGroup, it is not provided by event class
                    // directly, so we need to dit it up from buildTaskId that event provides
                    log.info("Cancelling ...");
                    coordinator.cancelSet(getBuildConfigSetId(coordinator, event.getBuild().getId()));
                } catch (CoreException | InterruptedException e) {
                    log.error("Unable to cancel the build.", e);
                    Assert.fail("Unable to cancel the build.");
                }
            });
        }
    };
    // when
    BuildSetTask buildSetTask = buildProjects(configurationSet, coordinator, onStatusUpdate, 2);
    // expect
    List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
    Assert.assertEquals("Incorrect number of build records in datastore: " + buildRecords, 3, buildRecords.size());
    for (BuildRecord buildRecord : buildRecords) {
        Assert.assertNotNull(buildRecord.getSubmitTime());
        switch(buildRecord.getBuildConfigurationId()) {
            case 1:
                Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
                continue;
            case 2:
                Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
                break;
            case 3:
                Assert.assertEquals(BuildStatus.SUCCESS, buildRecord.getStatus());
                break;
            default:
                Assert.fail("Invalid build configuration ID");
                break;
        }
        Assert.assertNotNull(buildRecord.getStartTime());
        Assert.assertNotNull(buildRecord.getEndTime());
    }
    // 3 is independent, 2 is dependent on 3, 1 is dependent on 2
    for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
        String buildTaskId = buildTask.getId();
        switch(buildTask.getBuildConfigurationAudited().getId()) {
            case 1:
                // Building status is skipped (cancelled before it can start building)
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
                break;
            case 2:
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
                break;
            case 3:
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.SUCCESS, buildTaskId);
                break;
            default:
                break;
        }
    }
}
Also used : BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Logger(org.slf4j.Logger) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Assert(org.junit.Assert) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArrayList(java.util.ArrayList) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test)

Example 7 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class DatastoreAdapterTest method shouldStoreRepositoryManagerError.

@Test
public void shouldStoreRepositoryManagerError() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    BuildStatus buildStatus = BuildStatus.SUCCESS;
    CompletionStatus completionStatus = CompletionStatus.FAILED;
    // when
    storeResult(datastoreAdapter, buildStatus, completionStatus);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(BuildStatus.FAILED, buildRecord.getStatus());
    Assert.assertTrue(buildRecord.getBuildLog().contains(BUILD_LOG));
    Assert.assertTrue(buildRecord.getBuildLog().contains(REPOSITORY_MANAGER_LOG));
}
Also used : CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildStatus(org.jboss.pnc.enums.BuildStatus) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 8 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class DatastoreAdapterTest method shouldStoreNoRequiredRebuild.

@Test
public void shouldStoreNoRequiredRebuild() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    // when
    datastoreAdapter.storeRecordForNoRebuild(mockBuildTask());
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(BuildStatus.NO_REBUILD_REQUIRED, buildRecord.getStatus());
}
Also used : DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 9 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class MultipleProjectsBuildTest method checkDatabaseForResult.

@Test
@InSequence(20)
public void checkDatabaseForResult() {
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals("Wrong datastore results count.", N_PROJECTS, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    String buildLog = buildRecord.getBuildLog();
    Assert.assertTrue("Invalid build log: " + buildLog, buildLog.contains("Finished: SUCCESS"));
    assertArtifactsPresent(buildRecord.getBuiltArtifacts());
    assertArtifactsPresent(buildRecord.getDependencies());
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 10 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class SkippingBuiltConfigsTest method shouldRerunTheSameBuildConfigurationSetIfRebuildAllIsSpecified.

@Test
public void shouldRerunTheSameBuildConfigurationSetIfRebuildAllIsSpecified() throws Exception {
    // when
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setRebuildMode(RebuildMode.FORCE);
    // first build
    coordinator.build(configSet, user, buildOptions);
    waitForEmptyBuildQueue();
    // forced rebuild build
    coordinator.build(configSet, user, buildOptions);
    waitForEmptyBuildQueue();
    // then
    List<BuildRecord> buildRecords = getNonRejectedBuildRecords();
    logRecords(buildRecords);
    assertThat(buildRecords.size()).isEqualTo(2 * configSet.getBuildConfigurations().size());
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildRecord(org.jboss.pnc.model.BuildRecord) 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