Search in sources :

Example 6 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.

the class DefaultBuildCoordinatorTest method testBuildBuildConfiguration.

@Test
public void testBuildBuildConfiguration() throws BuildConflictException, CoreException {
    assertTrue("Test assumes that we build with dependencies", BUILD_OPTIONS.isBuildDependencies());
    BuildConfigurationAudited bca = mockDatastoreWithBCAudited(BC_1, 5);
    BuildConfigurationAudited bcaDep = mockDatastoreWithBCAudited(BC_2, 2);
    BuildSetTask buildSetTask = coordinator.build(BC_1, USER, BUILD_OPTIONS);
    assertEquals(2, buildSetTask.getBuildTasks().size());
    assertNotNull(buildSetTask.getBuildTask(bca));
    assertNotNull(buildSetTask.getBuildTask(bcaDep));
    assertSame(BUILD_OPTIONS, buildSetTask.getBuildOptions());
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test)

Example 7 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask 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)

Example 8 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask 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 9 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.

the class ConfigurationsTest method dependsOnItselfConfigurationTestCase.

// TODO test is not run as expected exception is thrown
@Test(expected = PersistenceException.class)
// configurationBuilder.build...
@InSequence(10)
public void dependsOnItselfConfigurationTestCase() throws Exception {
    BuildConfiguration buildConfiguration = configurationBuilder.buildConfigurationWhichDependsOnItself();
    User user = User.Builder.newBuilder().id(1).build();
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setBuildDependencies(false);
    BuildSetTask taskSet = buildCoordinator.build(buildConfiguration, user, buildOptions);
    Set<BuildTask> buildTasks = taskSet.getBuildTasks();
    assertThat(buildTasks).hasSize(1);
    BuildTask buildTask = buildTasks.iterator().next();
    Assert.assertEquals(BuildCoordinationStatus.REJECTED, buildTask.getStatus());
    Assert.assertTrue("Invalid status description: " + buildTask.getStatusDescription(), buildTask.getStatusDescription().contains("itself"));
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 10 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.

the class ConfigurationsTest method cycleConfigurationTestCase.

// TODO test is not run as expected exception is thrown
@Test(expected = PersistenceException.class)
// configurationBuilder.build...
@InSequence(15)
public void cycleConfigurationTestCase() throws Exception {
    BuildConfigurationSet buildConfigurationSet = configurationBuilder.buildConfigurationSetWithCycleDependency();
    User user = User.Builder.newBuilder().id(1).build();
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setRebuildMode(RebuildMode.FORCE);
    BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, user, buildOptions);
    Assert.assertEquals(BuildSetStatus.REJECTED, buildSetTask.getStatus());
    Assert.assertTrue("Invalid status description: " + buildSetTask.getStatusDescription(), buildSetTask.getStatusDescription().contains("Cycle dependencies found"));
}
Also used : BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) User(org.jboss.pnc.model.User) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)30 Test (org.junit.Test)15 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)12 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)11 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)10 BuildOptions (org.jboss.pnc.spi.BuildOptions)10 HashSet (java.util.HashSet)6 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)6 User (org.jboss.pnc.model.User)6 BuildSetStatus (org.jboss.pnc.spi.BuildSetStatus)6 CoreException (org.jboss.pnc.spi.exception.CoreException)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 List (java.util.List)5 Set (java.util.Set)5 BuildStatus (org.jboss.pnc.enums.BuildStatus)5 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)5 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)5 Collections (java.util.Collections)4