Search in sources :

Example 6 with WebSocketClient

use of org.jboss.pnc.restclient.websocket.WebSocketClient in project pnc by project-ncl.

the class WebSocketClientTest method testConnection.

@Test
public void testConnection() throws Exception {
    // with
    WebSocketClient wsClient = new VertxWebSocketClient();
    // when
    CompletableFuture<Void> future = wsClient.connect(PNC_SOCKET_URL);
    // then
    assertThat(future).succeedsWithin(500, TimeUnit.MILLISECONDS);
    wsClient.disconnect();
}
Also used : WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 7 with WebSocketClient

use of org.jboss.pnc.restclient.websocket.WebSocketClient in project pnc by project-ncl.

the class WebSocketClientTest method shouldReconnectAfterBeingUnresponsive.

@Test
public void shouldReconnectAfterBeingUnresponsive() throws Exception {
    // with
    WebSocketSessionHandler handler = new WebSocketSessionHandler();
    Undertow wsServer = withHandler(handler);
    wsServer.start();
    // set max server unresponsiveness
    int maxUnresponsiveness = 1000;
    WebSocketClient wsClient = withMaxUnresponsiveness(1000);
    // make server unresponsive
    handler.blockPongs();
    // when
    wsClient.connect("ws://localhost:8082" + NOTIFICATION_PATH).get();
    // wait maxUnresponsiveness time plus a little more to give client time to reconnect
    Thread.sleep(maxUnresponsiveness + 500);
    // then
    assertThat(handler.getSessionCounter()).hasValue(2);
    wsClient.close();
    wsServer.stop();
}
Also used : WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) Undertow(io.undertow.Undertow) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 8 with WebSocketClient

use of org.jboss.pnc.restclient.websocket.WebSocketClient in project pnc by project-ncl.

the class WebSocketClientTest method testRestBuildFallback.

@Test
public void testRestBuildFallback() throws Exception {
    // with
    WebSocketSessionHandler handler = new WebSocketSessionHandler();
    Undertow wsServer = withHandler(handler);
    wsServer.start();
    WebSocketClient wsClient = new VertxWebSocketClient();
    wsClient.connect("ws://localhost:8082" + NOTIFICATION_PATH).join();
    AdvancedBuildConfigurationClient buildConfigurationClient = new AdvancedBuildConfigurationClient(RestClientConfiguration.asUser());
    // test the actual fallbackSupplier (it's private -> reflection unfortunately)
    Method supplier = buildConfigurationClient.getClass().getDeclaredMethod("fallbackSupplier", String.class);
    supplier.setAccessible(true);
    // when
    BuildConfiguration bc = buildConfigurationClient.getAll().iterator().next();
    CompletableFuture<BuildChangedNotification> future = wsClient.catchBuildChangedNotification(() -> invokeMethod(supplier, Build.class, buildConfigurationClient, bc.getId()), withBuildConfiguration(bc.getId()), withBuildCompleted());
    buildConfigurationClient.trigger(bc.getId(), new BuildParameters());
    // make client reconnect and use REST fallback
    handler.closeSession();
    // then
    assertThat(future).succeedsWithin(1000, TimeUnit.MILLISECONDS);
    wsClient.close();
    wsServer.stop();
}
Also used : BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) AdvancedBuildConfigurationClient(org.jboss.pnc.restclient.AdvancedBuildConfigurationClient) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) BuildParameters(org.jboss.pnc.rest.api.parameters.BuildParameters) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) Method(java.lang.reflect.Method) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) BuildChangedNotification(org.jboss.pnc.dto.notification.BuildChangedNotification) GroupBuildChangedNotification(org.jboss.pnc.dto.notification.GroupBuildChangedNotification) Undertow(io.undertow.Undertow) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 9 with WebSocketClient

use of org.jboss.pnc.restclient.websocket.WebSocketClient in project pnc by project-ncl.

the class WebSocketClientTest method testNotificationCatcher.

@Test
public void testNotificationCatcher() throws Exception {
    // with
    WebSocketClient wsClient = new VertxWebSocketClient();
    wsClient.connect(PNC_SOCKET_URL).get();
    BuildConfigurationClient buildConfigurationClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    BuildConfiguration bc = buildConfigurationClient.getAll().iterator().next();
    // when
    CompletableFuture<BuildChangedNotification> future = wsClient.catchBuildChangedNotification(withBuildConfiguration(bc.getId()), withBuildCompleted());
    buildConfigurationClient.trigger(bc.getId(), new BuildParameters());
    // then
    assertThat(future).succeedsWithin(500, TimeUnit.MILLISECONDS);
    BuildChangedNotification bcn = future.get();
    assertThat(bcn).isNotNull();
    assertThat(bcn.getBuild()).isNotNull();
    assertThat(bcn.getBuild().getBuildConfigRevision().getId()).isEqualTo(bc.getId());
    assertThat(bcn.getBuild().getStatus().isFinal()).isTrue();
    wsClient.disconnect();
}
Also used : BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) BuildParameters(org.jboss.pnc.rest.api.parameters.BuildParameters) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) AdvancedBuildConfigurationClient(org.jboss.pnc.restclient.AdvancedBuildConfigurationClient) BuildChangedNotification(org.jboss.pnc.dto.notification.BuildChangedNotification) GroupBuildChangedNotification(org.jboss.pnc.dto.notification.GroupBuildChangedNotification) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

VertxWebSocketClient (org.jboss.pnc.restclient.websocket.VertxWebSocketClient)9 WebSocketClient (org.jboss.pnc.restclient.websocket.WebSocketClient)9 ContainerTest (org.jboss.pnc.test.category.ContainerTest)9 Test (org.junit.Test)9 Undertow (io.undertow.Undertow)6 GroupBuildChangedNotification (org.jboss.pnc.dto.notification.GroupBuildChangedNotification)4 GroupBuildParameters (org.jboss.pnc.rest.api.parameters.GroupBuildParameters)4 Method (java.lang.reflect.Method)3 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)3 GroupBuild (org.jboss.pnc.dto.GroupBuild)3 BuildChangedNotification (org.jboss.pnc.dto.notification.BuildChangedNotification)3 BuildParameters (org.jboss.pnc.rest.api.parameters.BuildParameters)3 AdvancedBuildConfigurationClient (org.jboss.pnc.restclient.AdvancedBuildConfigurationClient)3 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)2 Build (org.jboss.pnc.dto.Build)2 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)2 AdvancedGroupConfigurationClient (org.jboss.pnc.restclient.AdvancedGroupConfigurationClient)2 BuildChangedNotificationPredicates.withBuildConfiguration (org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration)2 Handlers (io.undertow.Handlers)1 WebSocketConnectionCallback (io.undertow.websockets.WebSocketConnectionCallback)1