diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java index 82853526a54..722ebad72d2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java @@ -410,8 +410,9 @@ public class TestWebHdfsFileSystemContract extends FileSystemContractBaseTest { {//test GETHOMEDIRECTORY final URL url = webhdfs.toUrl(GetOpParam.Op.GETHOMEDIRECTORY, root); final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - final Map m = WebHdfsTestUtil.connectAndGetJson( - conn, HttpServletResponse.SC_OK); + assertEquals(WebHdfsTestUtil.sendRequest(conn), + HttpServletResponse.SC_OK); + final Map m = WebHdfsTestUtil.getAndParseResponse(conn); assertEquals(webhdfs.getHomeDirectory().toUri().getPath(), m.get(Path.class.getSimpleName())); conn.disconnect(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java index f1df39c493f..0b8c201ddb2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java @@ -348,7 +348,7 @@ public class TestWebHdfsTokens { @Override Token decodeResponse(Map json) throws IOException { - return JsonUtilClient.toDelegationToken(json); + return WebHdfsTestUtil.convertJsonToDelegationToken(json); } }.run(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/WebHdfsTestUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/WebHdfsTestUtil.java index 3dae82a345f..9c39202652a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/WebHdfsTestUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/WebHdfsTestUtil.java @@ -25,6 +25,8 @@ import java.net.URL; import java.security.PrivilegedExceptionAction; import java.util.Map; +import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier; +import org.apache.hadoop.security.token.Token; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -34,7 +36,6 @@ import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.web.resources.HttpOpParam; import org.apache.hadoop.hdfs.web.resources.Param; import org.apache.hadoop.security.UserGroupInformation; -import org.junit.Assert; public class WebHdfsTestUtil { public static final Logger LOG = @@ -87,10 +88,26 @@ public class WebHdfsTestUtil { return url; } - public static Map connectAndGetJson(final HttpURLConnection conn, - final int expectedResponseCode) throws IOException { + public static HttpURLConnection openConnection(URL url, Configuration conf) + throws IOException { + URLConnectionFactory connectionFactory = + URLConnectionFactory.newDefaultURLConnectionFactory(60000, 60000, conf); + return (HttpURLConnection) connectionFactory.openConnection(url); + } + + public static int sendRequest(final HttpURLConnection conn) + throws IOException { conn.connect(); - Assert.assertEquals(expectedResponseCode, conn.getResponseCode()); + return conn.getResponseCode(); + } + + public static Map getAndParseResponse(final HttpURLConnection conn) + throws IOException { return WebHdfsFileSystem.jsonParse(conn, false); } + + public static Token convertJsonToDelegationToken( + Map json) throws IOException { + return JsonUtilClient.toDelegationToken(json); + } }