HDFS-14784. Add more methods to WebHdfsTestUtil to support tests outside of package. Contributed by Chen Zhang.
This commit is contained in:
parent
acbea8d976
commit
494d75eb2b
@ -410,8 +410,9 @@ public void testResponseCode() throws IOException {
|
|||||||
{//test GETHOMEDIRECTORY
|
{//test GETHOMEDIRECTORY
|
||||||
final URL url = webhdfs.toUrl(GetOpParam.Op.GETHOMEDIRECTORY, root);
|
final URL url = webhdfs.toUrl(GetOpParam.Op.GETHOMEDIRECTORY, root);
|
||||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
final Map<?, ?> m = WebHdfsTestUtil.connectAndGetJson(
|
assertEquals(WebHdfsTestUtil.sendRequest(conn),
|
||||||
conn, HttpServletResponse.SC_OK);
|
HttpServletResponse.SC_OK);
|
||||||
|
final Map<?, ?> m = WebHdfsTestUtil.getAndParseResponse(conn);
|
||||||
assertEquals(webhdfs.getHomeDirectory().toUri().getPath(),
|
assertEquals(webhdfs.getHomeDirectory().toUri().getPath(),
|
||||||
m.get(Path.class.getSimpleName()));
|
m.get(Path.class.getSimpleName()));
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
|
@ -348,7 +348,7 @@ op, null, new RenewerParam(null)) {
|
|||||||
@Override
|
@Override
|
||||||
Token<DelegationTokenIdentifier> decodeResponse(Map<?, ?> json)
|
Token<DelegationTokenIdentifier> decodeResponse(Map<?, ?> json)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return JsonUtilClient.toDelegationToken(json);
|
return WebHdfsTestUtil.convertJsonToDelegationToken(json);
|
||||||
}
|
}
|
||||||
}.run();
|
}.run();
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.Map;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
@ -34,7 +36,6 @@
|
|||||||
import org.apache.hadoop.hdfs.web.resources.HttpOpParam;
|
import org.apache.hadoop.hdfs.web.resources.HttpOpParam;
|
||||||
import org.apache.hadoop.hdfs.web.resources.Param;
|
import org.apache.hadoop.hdfs.web.resources.Param;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
public class WebHdfsTestUtil {
|
public class WebHdfsTestUtil {
|
||||||
public static final Logger LOG =
|
public static final Logger LOG =
|
||||||
@ -87,10 +88,26 @@ public static URL toUrl(final WebHdfsFileSystem webhdfs,
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<?, ?> connectAndGetJson(final HttpURLConnection conn,
|
public static HttpURLConnection openConnection(URL url, Configuration conf)
|
||||||
final int expectedResponseCode) throws IOException {
|
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();
|
conn.connect();
|
||||||
Assert.assertEquals(expectedResponseCode, conn.getResponseCode());
|
return conn.getResponseCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<?, ?> getAndParseResponse(final HttpURLConnection conn)
|
||||||
|
throws IOException {
|
||||||
return WebHdfsFileSystem.jsonParse(conn, false);
|
return WebHdfsFileSystem.jsonParse(conn, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Token<DelegationTokenIdentifier> convertJsonToDelegationToken(
|
||||||
|
Map<?, ?> json) throws IOException {
|
||||||
|
return JsonUtilClient.toDelegationToken(json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user