HAURLSelectorImpl implements HAURLSelector { private void reSelectUrl() throws IOException { if (reselectInProgress) { return; } synchronized (this) { if (reselectInProgress) { return; } reselectInProgress = true; try { LOG.info("Going to reselect url"); for (int i = 0; i < urls.length; i++) { String urlToCheck = urls[i]; for (int time = 0; time < MAX_RETRY_TIME; time++) { if (checkUrl(builder.build(urlToCheck))) { selectedUrl = urls[i]; LOG.info("Successfully switch to new url : " + selectedUrl); return; } LOG.info("try {} failed for {} times, sleep 5 seconds before try again. ", urlToCheck, time + 1); try { Thread.sleep(1000); } catch (InterruptedException ex) { LOG.warn("{}", ex); } } } throw new IOException("No alive url found: " + StringUtils.join(";", Arrays.asList(this.urls))); } finally { reselectInProgress = false; } } } HAURLSelectorImpl(String[] urls, Constants.CompressionType compressionType); void checkUrl(); boolean checkUrl(String urlString); @Override String getSelectedUrl();  }
@Test(expected = IOException.class) public void testReSelectUrl() throws Exception { String[] rmBasePaths = new String[]{"http: HAURLSelectorImpl haurlSelector = new HAURLSelectorImpl(rmBasePaths, Constants.CompressionType.GZIP); mockStatic(InputStreamUtils.class); when(InputStreamUtils.getInputStream("http: when(InputStreamUtils.getInputStream("http: haurlSelector.checkUrl(); }