use of org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent 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);
}
use of org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent in project pnc by project-ncl.
the class ProcessProgressNotificationTest method shouldSubscribeToProcessUpdatesNotification.
@Test
public void shouldSubscribeToProcessUpdatesNotification() throws Exception {
// given
Integer taskId = 1;
Build build = BuildMock.newBuild(taskId, BuildStatus.SUCCESS, "Build1");
BuildStatusChangedEvent buildStatusChangedEvent = new DefaultBuildStatusChangedEvent(build, BuildStatus.NEW, build.getStatus());
// when
buildStatusNotificationEvent.fire(buildStatusChangedEvent);
ProgressUpdatesRequest progressUpdatesRequest = new ProgressUpdatesRequest(Action.SUBSCRIBE, "component-build", taskId.toString());
String text = JsonOutputConverterMapper.apply(new TypedMessage<>(MessageType.PROCESS_UPDATES, progressUpdatesRequest));
logger.info("Sending test message:" + text);
asyncRemote.sendText(text);
waitForMessages(1);
// then
logger.info("Received: " + notificationCollector.getMessages().get(0));
assertTrue(notificationCollector.getMessages().get(0).startsWith("{\"oldStatus\":\"NEW\",\"build\":{\"id\":\"1\",\"submitTime\":null,\"startTime\":null,\"endTime\":null,\"progress\":null,\"status\":\"SUCCESS\","));
}
use of org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent in project pnc by project-ncl.
the class DefaultBuildCoordinator method updateBuildTaskStatus.
private void updateBuildTaskStatus(BuildTask task, BuildCoordinationStatus status, String statusDescription) {
BuildCoordinationStatus oldStatus = task.getStatus();
// REJECTED_ALREADY_BUILT -> DONE
if (status.isCompleted() && !oldStatus.isCompleted()) {
markFinished(task, status, statusDescription);
} else {
task.setStatus(status);
task.setStatusDescription(statusDescription);
}
Build build = buildMapper.fromBuildTask(task);
BuildStatusChangedEvent buildStatusChanged = new DefaultBuildStatusChangedEvent(build, BuildStatus.fromBuildCoordinationStatus(oldStatus), BuildStatus.fromBuildCoordinationStatus(status));
log.debug("Updated build task {} status to {}; old coord status: {}, new coord status: {}", task.getId(), buildStatusChanged, oldStatus, status);
userLog.info("Build status updated to {}; previous: {}", status, oldStatus);
BuildStatus oldBuildStatus = BuildStatus.fromBuildCoordinationStatus(oldStatus);
BuildStatus newBuildStatus = BuildStatus.fromBuildCoordinationStatus(status);
if ((oldBuildStatus != newBuildStatus) && !(oldBuildStatus.isFinal() && newBuildStatus.isFinal())) {
// only fire notification when BuildStatus changes
// and avoid firing the notification when old and new statuses are final (NCL-5885)
buildStatusChangedEventNotifier.fire(buildStatusChanged);
log.debug("Fired buildStatusChangedEventNotifier after task {} status update to {}.", task.getId(), status);
}
}
Aggregations