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());
}
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;
}
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);
}
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;
}
}
}
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);
}
Aggregations