Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
Metrics
Collector
Commits
828f016a
Commit
828f016a
authored
Jan 13, 2022
by
Hiro
🏄
Browse files
Fix tests and checks
parent
36e8f916
Pipeline
#23579
passed with stage
in 3 minutes
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/torproject/metrics/collector/downloader/Downloader.java
View file @
828f016a
...
...
@@ -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
()))
...
...
@@ -68,8 +67,7 @@ public class Downloader {
}
}
return
downloadedBytes
.
toByteArray
();
}
else
{
}
else
{
return
null
;
}
}
...
...
src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
View file @
828f016a
...
...
@@ -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
;
...
...
@@ -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.
...
...
@@ -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
);
}
}
}
...
...
@@ -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
);
}
}
}
...
...
@@ -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. */
...
...
@@ -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
);
}
}
}
...
...
@@ -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
,
...
...
src/test/java/org/torproject/metrics/collector/downloader/DownloaderTest.java
View file @
828f016a
...
...
@@ -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
;
...
...
@@ -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
(
...
...
@@ -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
(
...
...
@@ -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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment