Search in sources :

Example 1 with BuildStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildStatusChangedEvent in project pnc by project-ncl.

the class ProjectBuilder method buildProject.

void buildProject(BuildConfiguration buildConfiguration, BuildCoordinator buildCoordinator) throws BuildConflictException, InterruptedException, CoreException {
    List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
    BuildTask buildTask = buildProject(buildConfiguration, buildCoordinator, receivedStatuses::add);
    assertAllStatusUpdateReceived(receivedStatuses, buildTask.getId());
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with BuildStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildStatusChangedEvent in project pnc by project-ncl.

the class ProjectBuilder method buildProject.

BuildTask buildProject(BuildConfiguration buildConfiguration, BuildCoordinator buildCoordinator, Consumer<BuildStatusChangedEvent> onStatusUpdate, BuildOptions buildOptions) throws BuildConflictException, InterruptedException, CoreException {
    log.debug("Building project {}", buildConfiguration.getName());
    List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
    Consumer<BuildStatusChangedEvent> onStatusUpdateInternal = (statusUpdate) -> {
        receivedStatuses.add(statusUpdate);
        onStatusUpdate.accept(statusUpdate);
    };
    // Defines a number of callbacks, which are executed after buildStatus update
    final Semaphore semaphore = registerReleaseListenersAndAcquireSemaphore(onStatusUpdateInternal, N_STATUS_UPDATES_PER_TASK);
    BuildSetTask taskSet = buildCoordinator.build(buildConfiguration, MockUser.newTestUser(1), buildOptions);
    Set<BuildTask> buildTasks = taskSet.getBuildTasks();
    assertThat(buildTasks).hasSize(1);
    BuildTask buildTask = buildTasks.iterator().next();
    log.info("Started build task {}", buildTask);
    assertBuildStartedSuccessfully(buildTask);
    waitForStatusUpdates(N_STATUS_UPDATES_PER_TASK, semaphore, "");
    return buildTask;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) Inject(javax.inject.Inject) TestCDIBuildSetStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildSetStatusChangedReceiver) Assert.fail(org.junit.Assert.fail) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Before(org.junit.Before) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) TestCDIBuildStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildStatusChangedReceiver) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) MockUser(org.jboss.pnc.mock.model.MockUser) CoreException(org.jboss.pnc.spi.exception.CoreException) Dependent(javax.enterprise.context.Dependent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArtifactBuilder(org.jboss.pnc.mock.model.builders.ArtifactBuilder) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Semaphore(java.util.concurrent.Semaphore) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 3 with BuildStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildStatusChangedEvent in project pnc by project-ncl.

the class ProjectBuilder method assertStatusUpdateReceived.

void assertStatusUpdateReceived(List<BuildStatusChangedEvent> receivedStatusEvents, BuildStatus status, String buildTaskId) {
    boolean received = false;
    for (BuildStatusChangedEvent receivedStatusEvent : receivedStatusEvents) {
        if (receivedStatusEvent.getBuild().getId().equals(buildTaskId) && receivedStatusEvent.getNewStatus().equals(status)) {
            received = true;
            break;
        }
    }
    assertTrue("Did not receive update for status: " + status + " for BuildTaskId: " + buildTaskId, received);
}
Also used : BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent)

Example 4 with BuildStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildStatusChangedEvent 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 5 with BuildStatusChangedEvent

use of org.jboss.pnc.spi.events.BuildStatusChangedEvent in project pnc by project-ncl.

the class WebSocketsNotificationTest method shouldReceiveBuildStatusChangeNotification.

@Test
@InSequence(2)
public void shouldReceiveBuildStatusChangeNotification() throws Exception {
    // given
    Build build = BuildMock.newBuild(BuildStatus.SUCCESS, "Build1");
    BuildStatusChangedEvent buildStatusChangedEvent = new DefaultBuildStatusChangedEvent(build, BuildStatus.NEW, build.getStatus());
    String buildString = mapperProvider.getMapper().writeValueAsString(build);
    String expectedJsonResponse = "{\"oldStatus\":\"NEW\",\"build\":" + buildString + ",\"job\":\"BUILD\",\"notificationType\":\"BUILD_STATUS_CHANGED\",\"progress\":\"FINISHED\",\"oldProgress\":\"PENDING\",\"message\":null}";
    // when
    buildStatusNotificationEvent.fire(buildStatusChangedEvent);
    // then
    Wait.forCondition(() -> isReceived(expectedJsonResponse), 15, ChronoUnit.SECONDS);
}
Also used : GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)17 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)9 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)9 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)9 Test (org.junit.Test)9 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)7 BuildOptions (org.jboss.pnc.spi.BuildOptions)7 Inject (javax.inject.Inject)6 BuildStatus (org.jboss.pnc.enums.BuildStatus)6 BuildRecord (org.jboss.pnc.model.BuildRecord)6 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 List (java.util.List)5 Consumer (java.util.function.Consumer)5 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)5 CoreException (org.jboss.pnc.spi.exception.CoreException)5 Set (java.util.Set)4 Deployment (org.jboss.arquillian.container.test.api.Deployment)4