Loading src/main/java/org/torproject/metrics/collector/downloader/Downloader.java +2 −4 Original line number Diff line number Diff line Loading @@ -55,8 +55,7 @@ public class Downloader { String message = huc.getResponseMessage(); if (message.contains("Servers unavailable")) { throw new IOException("404 Servers unavailable"); } else if (response == 200) { } else if (response == 200) { try (BufferedInputStream in = isDeflated ? new BufferedInputStream(new InflaterInputStream( huc.getInputStream())) Loading @@ -68,8 +67,7 @@ public class Downloader { } } return downloadedBytes.toByteArray(); } else { } else { return null; } } Loading src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java +11 −10 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ import java.io.FileWriter; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; Loading @@ -32,6 +31,7 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.TimeUnit; /** * Downloads relay descriptors from the directory authorities via HTTP. Loading Loading @@ -712,8 +712,8 @@ public class RelayDescriptorDownloader { this.downloadResourceFromAuthority(authority, "/tor/status-vote/current/consensus-microdesc"); } catch (IOException e) { logger.warn("Failed downloading consensus microdesc" + " from {}!", authority, e); logger.warn("Failed downloading consensus microdesc" + " from {}!", authority, e); } } } Loading @@ -737,8 +737,8 @@ public class RelayDescriptorDownloader { this.downloadResourceFromAuthority(authority, "/tor/status-vote/current/" + fingerprint); } catch (IOException e) { logger.warn("Failed downloading current vote" + " from {}!", authority, e); logger.warn("Failed downloading current vote" + " from {}!", authority, e); } } } Loading Loading @@ -781,8 +781,8 @@ public class RelayDescriptorDownloader { downloadedAllDescriptors; } } catch (IOException e) { logger.warn("Failed downloading all server or extra-info " + "descriptors files from {}!", authority, e); logger.warn("Failed downloading all server or extra-info " + "descriptors files from {}!", authority, e); } /* Download missing server descriptors, extra-info descriptors, * and microdescriptors if we're configured to do so. */ Loading Loading @@ -863,8 +863,8 @@ public class RelayDescriptorDownloader { break; } } catch (IOException e) { logger.warn("Failed downloading " + "descriptors files from {}!", authority, e); logger.warn("Failed downloading " + "descriptors files from {}!", authority, e); } } } Loading Loading @@ -908,7 +908,8 @@ public class RelayDescriptorDownloader { for (int i = 0; i < 6; i++) { int wait = i * 5; logger.warn("Downloaded 0 bytes from {} " + "will wait {} SECONDS to avoid DOS protections.", authority, wait); + "will wait {} SECONDS to avoid DOS protections.", authority, wait); TimeUnit.SECONDS.sleep(wait); allData = Downloader.downloadFromHttpServer(url, isCompressed); logger.warn("Downloaded {} -> ({} bytes)", fullUrl, Loading src/test/java/org/torproject/metrics/collector/downloader/DownloaderTest.java +3 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ package org.torproject.metrics.collector.downloader; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; Loading Loading @@ -84,9 +83,9 @@ public class DownloaderTest { @Test public void testExistingResource() throws Exception { URL requestedUrl = new URL("http://localhost/exists"); byte[] expectedDownloadedBytes = "content".getBytes(); HttpURLConnection urlConnection = mock(HttpURLConnection.class); httpUrlStreamHandler.addConnection(requestedUrl, urlConnection); byte[] expectedDownloadedBytes = "content".getBytes(); given(urlConnection.getResponseCode()).willReturn(200); given(urlConnection.getResponseMessage()).willReturn("OK"); given(urlConnection.getInputStream()).willReturn( Loading @@ -109,9 +108,9 @@ public class DownloaderTest { @Test public void testEmptyResource() throws Exception { URL requestedUrl = new URL("http://localhost/empty"); byte[] expectedDownloadedBytes = new byte[0]; HttpURLConnection urlConnection = mock(HttpURLConnection.class); httpUrlStreamHandler.addConnection(requestedUrl, urlConnection); byte[] expectedDownloadedBytes = new byte[0]; given(urlConnection.getResponseCode()).willReturn(200); given(urlConnection.getResponseMessage()).willReturn("OK"); given(urlConnection.getInputStream()).willReturn( Loading @@ -123,9 +122,9 @@ public class DownloaderTest { @Test(expected = SocketTimeoutException.class) public void testTimeout() throws Exception { URL requestedUrl = new URL("http://localhost/timeout"); SocketTimeoutException expectedException = new SocketTimeoutException(); HttpURLConnection urlConnection = mock(HttpURLConnection.class); httpUrlStreamHandler.addConnection(requestedUrl, urlConnection); SocketTimeoutException expectedException = new SocketTimeoutException(); given(urlConnection.getResponseCode()).willReturn(200); given(urlConnection.getResponseMessage()).willReturn("OK"); given(urlConnection.getInputStream()).willThrow(expectedException); Loading Loading
src/main/java/org/torproject/metrics/collector/downloader/Downloader.java +2 −4 Original line number Diff line number Diff line Loading @@ -55,8 +55,7 @@ public class Downloader { String message = huc.getResponseMessage(); if (message.contains("Servers unavailable")) { throw new IOException("404 Servers unavailable"); } else if (response == 200) { } else if (response == 200) { try (BufferedInputStream in = isDeflated ? new BufferedInputStream(new InflaterInputStream( huc.getInputStream())) Loading @@ -68,8 +67,7 @@ public class Downloader { } } return downloadedBytes.toByteArray(); } else { } else { return null; } } Loading
src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java +11 −10 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ import java.io.FileWriter; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; Loading @@ -32,6 +31,7 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.TimeUnit; /** * Downloads relay descriptors from the directory authorities via HTTP. Loading Loading @@ -712,8 +712,8 @@ public class RelayDescriptorDownloader { this.downloadResourceFromAuthority(authority, "/tor/status-vote/current/consensus-microdesc"); } catch (IOException e) { logger.warn("Failed downloading consensus microdesc" + " from {}!", authority, e); logger.warn("Failed downloading consensus microdesc" + " from {}!", authority, e); } } } Loading @@ -737,8 +737,8 @@ public class RelayDescriptorDownloader { this.downloadResourceFromAuthority(authority, "/tor/status-vote/current/" + fingerprint); } catch (IOException e) { logger.warn("Failed downloading current vote" + " from {}!", authority, e); logger.warn("Failed downloading current vote" + " from {}!", authority, e); } } } Loading Loading @@ -781,8 +781,8 @@ public class RelayDescriptorDownloader { downloadedAllDescriptors; } } catch (IOException e) { logger.warn("Failed downloading all server or extra-info " + "descriptors files from {}!", authority, e); logger.warn("Failed downloading all server or extra-info " + "descriptors files from {}!", authority, e); } /* Download missing server descriptors, extra-info descriptors, * and microdescriptors if we're configured to do so. */ Loading Loading @@ -863,8 +863,8 @@ public class RelayDescriptorDownloader { break; } } catch (IOException e) { logger.warn("Failed downloading " + "descriptors files from {}!", authority, e); logger.warn("Failed downloading " + "descriptors files from {}!", authority, e); } } } Loading Loading @@ -908,7 +908,8 @@ public class RelayDescriptorDownloader { for (int i = 0; i < 6; i++) { int wait = i * 5; logger.warn("Downloaded 0 bytes from {} " + "will wait {} SECONDS to avoid DOS protections.", authority, wait); + "will wait {} SECONDS to avoid DOS protections.", authority, wait); TimeUnit.SECONDS.sleep(wait); allData = Downloader.downloadFromHttpServer(url, isCompressed); logger.warn("Downloaded {} -> ({} bytes)", fullUrl, Loading
src/test/java/org/torproject/metrics/collector/downloader/DownloaderTest.java +3 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ package org.torproject.metrics.collector.downloader; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; Loading Loading @@ -84,9 +83,9 @@ public class DownloaderTest { @Test public void testExistingResource() throws Exception { URL requestedUrl = new URL("http://localhost/exists"); byte[] expectedDownloadedBytes = "content".getBytes(); HttpURLConnection urlConnection = mock(HttpURLConnection.class); httpUrlStreamHandler.addConnection(requestedUrl, urlConnection); byte[] expectedDownloadedBytes = "content".getBytes(); given(urlConnection.getResponseCode()).willReturn(200); given(urlConnection.getResponseMessage()).willReturn("OK"); given(urlConnection.getInputStream()).willReturn( Loading @@ -109,9 +108,9 @@ public class DownloaderTest { @Test public void testEmptyResource() throws Exception { URL requestedUrl = new URL("http://localhost/empty"); byte[] expectedDownloadedBytes = new byte[0]; HttpURLConnection urlConnection = mock(HttpURLConnection.class); httpUrlStreamHandler.addConnection(requestedUrl, urlConnection); byte[] expectedDownloadedBytes = new byte[0]; given(urlConnection.getResponseCode()).willReturn(200); given(urlConnection.getResponseMessage()).willReturn("OK"); given(urlConnection.getInputStream()).willReturn( Loading @@ -123,9 +122,9 @@ public class DownloaderTest { @Test(expected = SocketTimeoutException.class) public void testTimeout() throws Exception { URL requestedUrl = new URL("http://localhost/timeout"); SocketTimeoutException expectedException = new SocketTimeoutException(); HttpURLConnection urlConnection = mock(HttpURLConnection.class); httpUrlStreamHandler.addConnection(requestedUrl, urlConnection); SocketTimeoutException expectedException = new SocketTimeoutException(); given(urlConnection.getResponseCode()).willReturn(200); given(urlConnection.getResponseMessage()).willReturn("OK"); given(urlConnection.getInputStream()).willThrow(expectedException); Loading