use of org.jboss.pnc.restclient.websocket.WebSocketClient 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);
}
use of org.jboss.pnc.restclient.websocket.WebSocketClient 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();
}
use of org.jboss.pnc.restclient.websocket.WebSocketClient 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);
}
use of org.jboss.pnc.restclient.websocket.WebSocketClient in project pnc by project-ncl.
the class WebSocketClientTest method shouldReceivePings.
@Test
public void shouldReceivePings() throws Exception {
// with
WebSocketSessionHandler handler = new WebSocketSessionHandler();
Undertow wsServer = withHandler(handler);
wsServer.start();
// when
int pingDelays = 100;
WebSocketClient wsClient = withPingDelay(pingDelays);
wsClient.connect("ws://localhost:8082" + NOTIFICATION_PATH).get();
// let the client ping in the background
Thread.sleep(pingDelays * 12);
// then
assertThat(handler.getPingCounter()).hasValueGreaterThanOrEqualTo(10);
wsClient.close();
wsServer.stop();
}
use of org.jboss.pnc.restclient.websocket.WebSocketClient 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();
}
Aggregations