Search in sources :

Example 1 with ProgressUpdatesRequest

use of org.jboss.pnc.notification.ProgressUpdatesRequest 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\","));
}
Also used : 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) ProgressUpdatesRequest(org.jboss.pnc.notification.ProgressUpdatesRequest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with ProgressUpdatesRequest

use of org.jboss.pnc.notification.ProgressUpdatesRequest in project pnc by project-ncl.

the class WsUpdatesClient method subscribeBlocking.

public void subscribeBlocking(String topic, String filter, Consumer<String> onMessage) throws IOException, DeploymentException {
    ProgressUpdatesRequest progressUpdatesRequest = ProgressUpdatesRequest.subscribe(topic, filter);
    UpdatesMessageHandler updatesMessageHandler = new UpdatesMessageHandler(onMessage);
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    String uri = "ws://localhost:8080" + NOTIFICATION_PATH;
    Session session = container.connectToServer(updatesMessageHandler, URI.create(uri));
    RemoteEndpoint.Basic asyncRemote = session.getBasicRemote();
    asyncRemote.sendText(toJson(progressUpdatesRequest));
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) RemoteEndpoint(javax.websocket.RemoteEndpoint) ProgressUpdatesRequest(org.jboss.pnc.notification.ProgressUpdatesRequest) Session(javax.websocket.Session)

Aggregations

ProgressUpdatesRequest (org.jboss.pnc.notification.ProgressUpdatesRequest)2 RemoteEndpoint (javax.websocket.RemoteEndpoint)1 Session (javax.websocket.Session)1 WebSocketContainer (javax.websocket.WebSocketContainer)1 Build (org.jboss.pnc.dto.Build)1 DefaultBuildStatusChangedEvent (org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent)1 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)1 ContainerTest (org.jboss.pnc.test.category.ContainerTest)1 Test (org.junit.Test)1