Search in sources :

Example 6 with BuildTask

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

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

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

the class DatastoreAdapterTest method storeResult.

private void storeResult(DatastoreAdapter datastoreAdapter, BuildStatus buildStatus, CompletionStatus completionStatus) throws DatastoreException {
    BuildDriverResult buildDriverResult = mock(BuildDriverResult.class);
    when(buildDriverResult.getBuildStatus()).thenReturn(buildStatus);
    when(buildDriverResult.getBuildLog()).thenReturn(BUILD_LOG);
    RepositoryManagerResult repositoryManagerResult = mock(RepositoryManagerResult.class);
    when(repositoryManagerResult.getCompletionStatus()).thenReturn(completionStatus);
    when(repositoryManagerResult.getLog()).thenReturn(REPOSITORY_MANAGER_LOG);
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(buildDriverResult), Optional.of(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
    BuildTask buildTask = mockBuildTask();
    datastoreAdapter.storeResult(buildTask, buildResult);
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)

Example 9 with BuildTask

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

the class DatastoreAdapterTest method mockBuildTask.

private BuildTask mockBuildTask() {
    BuildConfiguration buildConfiguration = new BuildConfiguration();
    buildConfiguration.setId(12);
    buildConfiguration.setName("Configuration.");
    buildConfiguration.setProject(new Project());
    BuildOptions buildOptions = new BuildOptions(false, true, false, false, RebuildMode.IMPLICIT_DEPENDENCY_CHECK, AlignmentPreference.PREFER_PERSISTENT);
    BuildTask buildTask = BuildTask.build(BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, 13), buildOptions, MockUser.newTestUser(1), "123", null, new Date(), null, "context-id", Optional.empty());
    buildTask.setStatus(BuildCoordinationStatus.DONE);
    return buildTask;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Project(org.jboss.pnc.model.Project) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildOptions(org.jboss.pnc.spi.BuildOptions) Date(java.util.Date)

Example 10 with BuildTask

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

the class WaitForDependencyBuildTest method shouldNotStartParentBuildWhenDependencyIsRunning.

@Test
public void shouldNotStartParentBuildWhenDependencyIsRunning() throws CoreException, TimeoutException, InterruptedException {
    // start dependency
    build(configDependency);
    Wait.forCondition(() -> buildScheduler.isBuilding(configDependency.getId()), 3, ChronoUnit.SECONDS);
    // start parent while dependency is running
    build(configParent);
    // parent should wait for dependency to complete
    BuildTask parentBuildTask = getSubmittedBuildTaskByConfigurationId(configParent.getId()).get();
    assertThat(parentBuildTask.getStatus()).isEqualTo(BuildCoordinationStatus.WAITING_FOR_DEPENDENCIES);
    // complete the dependency
    BuildTask dependencyBuildTask = getScheduledBuildTaskByConfigurationId(configDependency.getId()).get();
    buildScheduler.completeBuild(dependencyBuildTask.getId());
    // check if parent has started
    Wait.forCondition(() -> buildScheduler.isBuilding(parentBuildTask.getBuildConfigurationAudited().getId()), 3, ChronoUnit.SECONDS);
    buildScheduler.completeBuild(parentBuildTask.getId());
    waitForEmptyBuildQueue();
    List<BuildConfiguration> configsWithTasks = getBuiltConfigs();
    assertThat(configsWithTasks).isEmpty();
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Test(org.junit.Test)

Aggregations

BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)43 Test (org.junit.Test)23 BuildRecord (org.jboss.pnc.model.BuildRecord)15 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)15 Build (org.jboss.pnc.dto.Build)13 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)13 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 BuildOptions (org.jboss.pnc.spi.BuildOptions)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Inject (javax.inject.Inject)11 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)11 CoreException (org.jboss.pnc.spi.exception.CoreException)11 User (org.jboss.pnc.model.User)10 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)10 Date (java.util.Date)9 Set (java.util.Set)9 HashSet (java.util.HashSet)8 List (java.util.List)8