Search in sources :

Example 1 with AdvancedBuildConfigurationClient

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

Aggregations

Undertow (io.undertow.Undertow)1 Method (java.lang.reflect.Method)1 Build (org.jboss.pnc.dto.Build)1 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)1 GroupBuild (org.jboss.pnc.dto.GroupBuild)1 BuildChangedNotification (org.jboss.pnc.dto.notification.BuildChangedNotification)1 GroupBuildChangedNotification (org.jboss.pnc.dto.notification.GroupBuildChangedNotification)1 BuildParameters (org.jboss.pnc.rest.api.parameters.BuildParameters)1 GroupBuildParameters (org.jboss.pnc.rest.api.parameters.GroupBuildParameters)1 AdvancedBuildConfigurationClient (org.jboss.pnc.restclient.AdvancedBuildConfigurationClient)1 VertxWebSocketClient (org.jboss.pnc.restclient.websocket.VertxWebSocketClient)1 WebSocketClient (org.jboss.pnc.restclient.websocket.WebSocketClient)1 BuildChangedNotificationPredicates.withBuildConfiguration (org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration)1 ContainerTest (org.jboss.pnc.test.category.ContainerTest)1 Test (org.junit.Test)1