public boolean downloadIfNecessary(final DownloadableFile downloadableFile) {
        boolean updated = false;
        boolean downloaded = false;
        while (!updated) try {
            fetchUpdateCheckHeaders(downloadableFile);
            if (downloadableFile.doesNotExist() || !downloadableFile.isChecksumEquals(getMd5())) {
                PerfTimer timer = PerfTimer.start("Downloading new " + downloadableFile + " with md5 signature: " + md5);
                downloaded = download(downloadableFile);
                timer.stop();
            }
            updated = true;
        } catch (Exception e) {
            try {
                int period = Integer.parseInt(System.getProperty("sleep.for.download", DEFAULT_FAILED_DOWNLOAD_SLEEP_MS));
                LOG.error("Couldn't update {}. Sleeping for {}s. Error: ", downloadableFile, TimeUnit.SECONDS.convert(period, TimeUnit.MILLISECONDS), e);
                Thread.sleep(period);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
        }
        return downloaded;
    }
@Test
    public void shouldDownloadAgentJarFile() {
        ServerBinaryDownloader downloader = new ServerBinaryDownloader(new GoAgentServerHttpClientBuilder(null, SslVerificationMode.NONE, null, null, null), ServerUrlGeneratorMother.generatorFor("localhost", server.getPort()));
        assertThat(DownloadableFile.AGENT.doesNotExist(), is(true));
        downloader.downloadIfNecessary(DownloadableFile.AGENT);
        assertThat(DownloadableFile.AGENT.getLocalFile().exists(), is(true));
    }