Search in sources :

Example 1 with VertxWebSocketClient

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

the class WebSocketClientTest method testDisconnect.

@Test
public void testDisconnect() throws Exception {
    // with
    WebSocketClient wsClient = new VertxWebSocketClient();
    CompletableFuture<Void> connect = wsClient.connect(PNC_SOCKET_URL);
    connect.get();
    // when
    CompletableFuture<Void> disconnect = wsClient.disconnect();
    // then
    assertThat(disconnect).succeedsWithin(500, TimeUnit.MILLISECONDS);
}
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 2 with VertxWebSocketClient

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

the class WebSocketClientTest method shouldReconnectAfterClosingConnection.

@Test
public void shouldReconnectAfterClosingConnection() throws Exception {
    // with
    WebSocketSessionHandler handler = new WebSocketSessionHandler();
    Undertow wsServer = withHandler(handler);
    wsServer.start();
    // when
    WebSocketClient wsClient = new VertxWebSocketClient();
    wsClient.connect("ws://localhost:8082" + NOTIFICATION_PATH).join();
    // wait a little for Undertow accept the client and increment the value
    Thread.sleep(50);
    assertThat(handler.getSessionCounter()).hasValue(1);
    // disconnect wsClient and force him to reconnect
    handler.closeSession();
    Thread.sleep(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) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with VertxWebSocketClient

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

the class WebSocketClientTest method testBuildListener.

@Test
public void testBuildListener() 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();
    AtomicInteger notificationCounter = new AtomicInteger(0);
    // when
    ListenerUnsubscriber unsubscriber = wsClient.onBuildChangedNotification((notification -> {
        notificationCounter.incrementAndGet();
        assertThat(notification).isNotNull();
        assertThat(notification.getBuild()).isNotNull();
    }), withBuildConfiguration(bc.getId()));
    buildConfigurationClient.trigger(bc.getId(), new BuildParameters());
    // then
    Thread.sleep(1000);
    unsubscriber.run();
    wsClient.disconnect().get();
    assertThat(notificationCounter).hasValueGreaterThanOrEqualTo(2);
}
Also used : BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) NOTIFICATION_PATH(org.jboss.pnc.integration.setup.RestClientConfiguration.NOTIFICATION_PATH) Handlers(io.undertow.Handlers) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) AdvancedGroupConfigurationClient(org.jboss.pnc.restclient.AdvancedGroupConfigurationClient) Arquillian(org.jboss.arquillian.junit.Arquillian) GroupBuildClient(org.jboss.pnc.client.GroupBuildClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildParameters(org.jboss.pnc.rest.api.parameters.BuildParameters) Undertow(io.undertow.Undertow) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ListenerUnsubscriber(org.jboss.pnc.restclient.websocket.ListenerUnsubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupBuild(org.jboss.pnc.dto.GroupBuild) Deployments(org.jboss.pnc.integration.setup.Deployments) Method(java.lang.reflect.Method) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) GroupBuildChangedNotificationPredicates.withGConfigId(org.jboss.pnc.restclient.websocket.predicates.GroupBuildChangedNotificationPredicates.withGConfigId) AbstractReceiveListener(io.undertow.websockets.core.AbstractReceiveListener) Category(org.junit.experimental.categories.Category) BuildChangedNotificationPredicates.withBuildCompleted(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildCompleted) Assertions.fail(org.assertj.core.api.Assertions.fail) WebSocketHttpExchange(io.undertow.websockets.spi.WebSocketHttpExchange) AdvancedBuildConfigurationClient(org.jboss.pnc.restclient.AdvancedBuildConfigurationClient) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) WebSocketConnectionCallback(io.undertow.websockets.WebSocketConnectionCallback) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ResponseUtils(org.jboss.pnc.integration.utils.ResponseUtils) ClientException(org.jboss.pnc.client.ClientException) BufferedBinaryMessage(io.undertow.websockets.core.BufferedBinaryMessage) BuildChangedNotification(org.jboss.pnc.dto.notification.BuildChangedNotification) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) GroupBuildChangedNotification(org.jboss.pnc.dto.notification.GroupBuildChangedNotification) Logger(org.slf4j.Logger) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) GroupBuildChangedNotificationPredicates.withGBuildCompleted(org.jboss.pnc.restclient.websocket.predicates.GroupBuildChangedNotificationPredicates.withGBuildCompleted) Test(org.junit.Test) IOException(java.io.IOException) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) RemoteResourceNotFoundException(org.jboss.pnc.client.RemoteResourceNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) Build(org.jboss.pnc.dto.Build) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Deployment(org.jboss.arquillian.container.test.api.Deployment) WebSocketChannel(io.undertow.websockets.core.WebSocketChannel) GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) ListenerUnsubscriber(org.jboss.pnc.restclient.websocket.ListenerUnsubscriber) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with VertxWebSocketClient

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

the class WebSocketClientTest method testRestGroupBuildFallback.

@Test
public void testRestGroupBuildFallback() 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();
    AdvancedGroupConfigurationClient groupConfigurationClient = new AdvancedGroupConfigurationClient(RestClientConfiguration.asUser());
    GroupConfiguration gc = groupConfigurationClient.getAll().iterator().next();
    // test the actual fallbackSupplier (it's private -> reflection unfortunately)
    Method supplier = groupConfigurationClient.getClass().getDeclaredMethod("fallbackSupplier", String.class);
    supplier.setAccessible(true);
    // when
    CompletableFuture<GroupBuildChangedNotification> future = wsClient.catchGroupBuildChangedNotification(() -> invokeMethod(supplier, GroupBuild.class, groupConfigurationClient, gc.getId()), withGConfigId(gc.getId()), withGBuildCompleted());
    GroupBuild groupBuild = groupConfigurationClient.trigger(gc.getId(), new GroupBuildParameters(), GroupBuildRequest.builder().build());
    // wait for GroupBuild to finish
    ResponseUtils.waitSynchronouslyFor(() -> groupBuildToFinish(groupBuild.getId()), 15, TimeUnit.SECONDS);
    // make client reconnect and use REST fallback
    handler.closeSession();
    // then
    assertThat(future).succeedsWithin(500, TimeUnit.MILLISECONDS);
    wsClient.close();
    wsServer.stop();
}
Also used : GroupBuildChangedNotification(org.jboss.pnc.dto.notification.GroupBuildChangedNotification) GroupBuild(org.jboss.pnc.dto.GroupBuild) AdvancedGroupConfigurationClient(org.jboss.pnc.restclient.AdvancedGroupConfigurationClient) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Method(java.lang.reflect.Method) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) Undertow(io.undertow.Undertow) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 5 with VertxWebSocketClient

use of org.jboss.pnc.restclient.websocket.VertxWebSocketClient 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)

Aggregations

VertxWebSocketClient (org.jboss.pnc.restclient.websocket.VertxWebSocketClient)7 WebSocketClient (org.jboss.pnc.restclient.websocket.WebSocketClient)7 ContainerTest (org.jboss.pnc.test.category.ContainerTest)7 Test (org.junit.Test)7 Undertow (io.undertow.Undertow)4 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