private ServerInfo getServerInfo(SockJsUrlInfo sockJsUrlInfo, @Nullable HttpHeaders headers) { URI infoUrl = sockJsUrlInfo.getInfoUrl(); ServerInfo info = this.serverInfoCache.get(infoUrl); if (info == null) { long start = System.currentTimeMillis(); String response = this.infoReceiver.executeInfoRequest(infoUrl, headers); long infoRequestTime = System.currentTimeMillis() - start; info = new ServerInfo(response, infoRequestTime); this.serverInfoCache.put(infoUrl, info); } return info; }
private ArgumentCaptor<HttpHeaders> setupInfoRequest(boolean webSocketEnabled) { ArgumentCaptor<HttpHeaders> headersCaptor = ArgumentCaptor.forClass(HttpHeaders.class); when(this.infoReceiver.executeInfoRequest(any(), headersCaptor.capture())).thenReturn( "{\"entropy\":123," + "\"origins\":[\"*:*\"]," + "\"cookie_needed\":true," + "\"websocket\":" + webSocketEnabled + "}"); return headersCaptor; }
@Test public void connectSockJsInfo() throws Exception { setupInfoRequest(true); this.sockJsClient.doHandshake(handler, URL); verify(this.infoReceiver, times(1)).executeInfoRequest(any(), any()); }
@Test public void connectSockJsInfoCached() throws Exception { setupInfoRequest(true); this.sockJsClient.doHandshake(handler, URL); this.sockJsClient.doHandshake(handler, URL); this.sockJsClient.doHandshake(handler, URL); verify(this.infoReceiver, times(1)).executeInfoRequest(any(), any()); }
@Test public void connectInfoRequestFailure() throws URISyntaxException { HttpServerErrorException exception = new HttpServerErrorException(HttpStatus.SERVICE_UNAVAILABLE); given(this.infoReceiver.executeInfoRequest(any(), any())).willThrow(exception); this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback); verify(this.connectCallback).onFailure(exception); assertFalse(this.webSocketTransport.invoked()); assertFalse(this.xhrTransport.invoked()); }
private ServerInfo getServerInfo(SockJsUrlInfo sockJsUrlInfo, @Nullable HttpHeaders headers) { URI infoUrl = sockJsUrlInfo.getInfoUrl(); ServerInfo info = this.serverInfoCache.get(infoUrl); if (info == null) { long start = System.currentTimeMillis(); String response = this.infoReceiver.executeInfoRequest(infoUrl, headers); long infoRequestTime = System.currentTimeMillis() - start; info = new ServerInfo(response, infoRequestTime); this.serverInfoCache.put(infoUrl, info); } return info; }
private ServerInfo getServerInfo(SockJsUrlInfo sockJsUrlInfo, @Nullable HttpHeaders headers) { URI infoUrl = sockJsUrlInfo.getInfoUrl(); ServerInfo info = this.serverInfoCache.get(infoUrl); if (info == null) { long start = System.currentTimeMillis(); String response = this.infoReceiver.executeInfoRequest(infoUrl, headers); long infoRequestTime = System.currentTimeMillis() - start; info = new ServerInfo(response, infoRequestTime); this.serverInfoCache.put(infoUrl, info); } return info; }