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) { LOG.error("Couldn't update {}. Sleeping for 1m. Error: ", downloadableFile, e); try { int period = Integer.parseInt(System.getProperty("sleep.for.download", "60000")); Thread.sleep(period); } catch (InterruptedException ie) { /* we don't care. Stupid checked exception.*/ } } return downloaded; }
@Test public void shouldFailIfMD5HeadersAreMissing() throws Exception { exception.expect(Exception.class); exception.expectMessage("Missing required headers 'Content-MD5' and 'Cruise-Server-Ssl-Port' in response."); ServerBinaryDownloader downloader = new ServerBinaryDownloader(ServerUrlGeneratorMother.generatorWithoutSubPathFor("https://localhost:" + server.getSecurePort() + "/go/hello"), null, SslVerificationMode.NONE); downloader.fetchUpdateCheckHeaders(DownloadableFile.AGENT); }
@Test public void shouldFailIfServerIsNotAvailable() throws Exception { exception.expect(UnknownHostException.class); exception.expectMessage("invalidserver"); ServerBinaryDownloader downloader = new ServerBinaryDownloader(ServerUrlGeneratorMother.generatorWithoutSubPathFor("https://invalidserver:" + server.getSecurePort() + "/go/hello"), null, SslVerificationMode.NONE); downloader.fetchUpdateCheckHeaders(DownloadableFile.AGENT); }