diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2015-11-12 11:28:01 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-11-21 00:21:27 +0100 |
commit | fe85311b3a66d8cc7e7a66d4f0e01f88acbf1c0a (patch) | |
tree | d927adc10daf4b24d14a7e52898e5d526269c183 /org.eclipse.jgit.test | |
parent | a6bcc988e06d4ef041e9c0efe7232cc4a5648374 (diff) | |
download | jgit-fe85311b3a66d8cc7e7a66d4f0e01f88acbf1c0a.tar.gz jgit-fe85311b3a66d8cc7e7a66d4f0e01f88acbf1c0a.zip |
Avoid UnknownHostException in WalkEncryptionTest
Prevent that WalkEncryptionTest fails when it can't determine the public
IP address using http://checkip.amazonws.com. Also set timeouts when
determining IP address in order to prevent long wait times during tests.
Change-Id: I1d2fe09f99df2a5f75f8077811a72fb2271cdddb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java index 90d78e4b62..ac2bfd12f9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java @@ -43,6 +43,20 @@ package org.eclipse.jgit.transport; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.UTF_8; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.permitLongTests; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.policySetup; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.product; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.proxySetup; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.publicAddress; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.reportPolicy; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.securityProviderName; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.textWrite; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.transferStream; +import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.verifyFileContent; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -59,7 +73,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; +import java.net.SocketTimeoutException; import java.net.URL; +import java.net.URLConnection; +import java.net.UnknownHostException; import java.nio.charset.Charset; import java.nio.file.Files; import java.security.GeneralSecurityException; @@ -94,8 +111,6 @@ import org.junit.runners.Suite; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.*; - /** * Amazon S3 encryption pipeline test. * @@ -401,14 +416,22 @@ public class WalkEncryptionTest { * @throws Exception */ static String publicAddress() throws Exception { - String service = "http://checkip.amazonaws.com"; - URL url = new URL(service); - BufferedReader reader = new BufferedReader( - new InputStreamReader(url.openStream())); try { - return reader.readLine(); - } finally { - reader.close(); + String service = "http://checkip.amazonaws.com"; + URL url = new URL(service); + URLConnection c = url.openConnection(); + c.setConnectTimeout(500); + c.setReadTimeout(500); + BufferedReader reader = new BufferedReader( + new InputStreamReader(c.getInputStream())); + try { + return reader.readLine(); + } finally { + reader.close(); + } + } catch (UnknownHostException | SocketTimeoutException e) { + return "Can't reach http://checkip.amazonaws.com to" + + " determine public address"; } } |