ExtensionWebSocketClient { synchronized public CompletableFuture<Boolean> connectToSource() { if (authFuture != null && (sourceFuture == null || !sourceFuture.getNow(true))) { sourceFuture = authFuture.thenComposeAsync( (authSuccess) -> { if (authSuccess) { doConnectionToSource(); return new CompletableFuture<Boolean>(); } else { return CompletableFuture.completedFuture(false); } } ); } return sourceFuture; } ExtensionWebSocketClient(String sourceName); ExtensionWebSocketListener getListener(); String getSourceName(); CompletableFuture<Boolean> initiateFullConnection(String url, String token); synchronized CompletableFuture<Boolean> initiateWebsocketConnection(String url); CompletableFuture<Boolean> getWebsocketConnectionFuture(); void sendNotification(Object data); void sendQueryResponseEmpty(String replyAddress); void sendQueryResponse(int httpCode, String replyAddress, Map body); void sendQueryResponse(int httpCode, String replyAddress, Map[] body); void sendQueryError(String replyAddress, String messageCode, String messageTemplate, Object[] parameters); void send(Object obj); synchronized CompletableFuture<Boolean> authenticate(String user, String pass); synchronized CompletableFuture<Boolean> authenticate(String token); CompletableFuture<Boolean> getAuthenticationFuture(); synchronized CompletableFuture<Boolean> connectToSource(); CompletableFuture<Boolean> getSourceConnectionFuture(); void sourceHasDisconnected(); void setAutoReconnect(boolean value); boolean isOpen(); boolean isAuthed(); boolean isConnected(); void close(); void stop(); void useHandlersFrom(ExtensionWebSocketListener listener); void useHandlersFrom(ExtensionWebSocketClient client); void setCloseHandler(Handler<ExtensionWebSocketClient> closeHandler); void setHttpHandler(Handler<Response> httpHandler); void setPublishHandler(Handler<ExtensionServiceMessage> publishHandler); void setQueryHandler(Handler<ExtensionServiceMessage> queryHandler); void setConfigHandler(Handler<ExtensionServiceMessage> configHandler); void setAuthHandler(Handler<Response> authHandler); void setReconnectHandler(Handler<ExtensionServiceMessage> reconnectHandler); static final int QUERY_CHUNK_CODE; static final int QUERY_DATA_CODE; static final int QUERY_NODATA_CODE; }
@Test public void testConnectToSource() throws InterruptedException { client.webSocketFuture = CompletableFuture.completedFuture(true); client.authFuture = CompletableFuture.completedFuture(true); client.connectToSource(); waitUntilTrue(5 * 1000, () -> socket.receivedMessage()); assert socket.compareData("op", ExtensionServiceMessage.OP_CONNECT_EXTENSION); assert socket.compareData("resourceName", ExtensionServiceMessage.RESOURCE_NAME_SOURCES); assert socket.compareData("resourceId", srcName); }