HDFS-12193. Fix style issues in HttpFS tests. Contributed by Zoran Dimitrijevic
This commit is contained in:
parent
94ca52ae9e
commit
c98201b5d8
@ -73,6 +73,9 @@
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
|
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main test class for HttpFSServer.
|
||||||
|
*/
|
||||||
public class TestHttpFSServer extends HFSTestCase {
|
public class TestHttpFSServer extends HFSTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -82,15 +85,20 @@ public void server() throws Exception {
|
|||||||
String dir = TestDirHelper.getTestDir().getAbsolutePath();
|
String dir = TestDirHelper.getTestDir().getAbsolutePath();
|
||||||
|
|
||||||
Configuration httpfsConf = new Configuration(false);
|
Configuration httpfsConf = new Configuration(false);
|
||||||
HttpFSServerWebApp server = new HttpFSServerWebApp(dir, dir, dir, dir, httpfsConf);
|
HttpFSServerWebApp server = new HttpFSServerWebApp(dir, dir, dir, dir,
|
||||||
|
httpfsConf);
|
||||||
server.init();
|
server.init();
|
||||||
server.destroy();
|
server.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock groups.
|
||||||
|
*/
|
||||||
public static class MockGroups implements Service, Groups {
|
public static class MockGroups implements Service, Groups {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(org.apache.hadoop.lib.server.Server server) throws ServiceException {
|
public void init(org.apache.hadoop.lib.server.Server server)
|
||||||
|
throws ServiceException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -112,8 +120,10 @@ public Class getInterface() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serverStatusChange(org.apache.hadoop.lib.server.Server.Status oldStatus,
|
public void serverStatusChange(
|
||||||
org.apache.hadoop.lib.server.Server.Status newStatus) throws ServiceException {
|
org.apache.hadoop.lib.server.Server.Status oldStatus,
|
||||||
|
org.apache.hadoop.lib.server.Server.Status newStatus)
|
||||||
|
throws ServiceException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -300,25 +310,30 @@ public void instrumentation() throws Exception {
|
|||||||
createHttpFSServer(false, false);
|
createHttpFSServer(false, false);
|
||||||
|
|
||||||
URL url = new URL(TestJettyHelper.getJettyURL(),
|
URL url = new URL(TestJettyHelper.getJettyURL(),
|
||||||
MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation", "nobody"));
|
MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation",
|
||||||
|
"nobody"));
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_UNAUTHORIZED);
|
Assert.assertEquals(conn.getResponseCode(),
|
||||||
|
HttpURLConnection.HTTP_UNAUTHORIZED);
|
||||||
|
|
||||||
url = new URL(TestJettyHelper.getJettyURL(),
|
url = new URL(TestJettyHelper.getJettyURL(),
|
||||||
MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation",
|
MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation",
|
||||||
HadoopUsersConfTestHelper.getHadoopUsers()[0]));
|
HadoopUsersConfTestHelper.getHadoopUsers()[0]));
|
||||||
conn = (HttpURLConnection) url.openConnection();
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
|
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(conn.getInputStream()));
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
reader.close();
|
reader.close();
|
||||||
Assert.assertTrue(line.contains("\"counters\":{"));
|
Assert.assertTrue(line.contains("\"counters\":{"));
|
||||||
|
|
||||||
url = new URL(TestJettyHelper.getJettyURL(),
|
url = new URL(TestJettyHelper.getJettyURL(),
|
||||||
MessageFormat.format("/webhdfs/v1/foo?user.name={0}&op=instrumentation",
|
MessageFormat.format(
|
||||||
|
"/webhdfs/v1/foo?user.name={0}&op=instrumentation",
|
||||||
HadoopUsersConfTestHelper.getHadoopUsers()[0]));
|
HadoopUsersConfTestHelper.getHadoopUsers()[0]));
|
||||||
conn = (HttpURLConnection) url.openConnection();
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
|
Assert.assertEquals(conn.getResponseCode(),
|
||||||
|
HttpURLConnection.HTTP_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -330,10 +345,12 @@ public void testHdfsAccess() throws Exception {
|
|||||||
|
|
||||||
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
||||||
URL url = new URL(TestJettyHelper.getJettyURL(),
|
URL url = new URL(TestJettyHelper.getJettyURL(),
|
||||||
MessageFormat.format("/webhdfs/v1/?user.name={0}&op=liststatus", user));
|
MessageFormat.format("/webhdfs/v1/?user.name={0}&op=liststatus",
|
||||||
|
user));
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
|
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(conn.getInputStream()));
|
||||||
reader.readLine();
|
reader.readLine();
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
@ -369,10 +386,12 @@ public void testGlobFilter() throws Exception {
|
|||||||
|
|
||||||
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
||||||
URL url = new URL(TestJettyHelper.getJettyURL(),
|
URL url = new URL(TestJettyHelper.getJettyURL(),
|
||||||
MessageFormat.format("/webhdfs/v1/tmp?user.name={0}&op=liststatus&filter=f*", user));
|
MessageFormat.format(
|
||||||
|
"/webhdfs/v1/tmp?user.name={0}&op=liststatus&filter=f*", user));
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
|
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(conn.getInputStream()));
|
||||||
reader.readLine();
|
reader.readLine();
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
@ -384,8 +403,7 @@ public void testGlobFilter() throws Exception {
|
|||||||
* @param perms The permission field, if any (may be null)
|
* @param perms The permission field, if any (may be null)
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private void createWithHttp ( String filename, String perms )
|
private void createWithHttp(String filename, String perms) throws Exception {
|
||||||
throws Exception {
|
|
||||||
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
||||||
// Remove leading / from filename
|
// Remove leading / from filename
|
||||||
if (filename.charAt(0) == '/') {
|
if (filename.charAt(0) == '/') {
|
||||||
@ -534,7 +552,7 @@ private Map<String, byte[]> getXAttrs(String statusJson) throws Exception {
|
|||||||
return xAttrs;
|
return xAttrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Decode xattr value from string */
|
/** Decode xattr value from string. */
|
||||||
private byte[] decodeXAttrValue(String value) throws IOException {
|
private byte[] decodeXAttrValue(String value) throws IOException {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return XAttrCodec.decodeValue(value);
|
return XAttrCodec.decodeValue(value);
|
||||||
@ -623,8 +641,9 @@ public void testXAttrs() throws Exception {
|
|||||||
Assert.assertEquals(0, xAttrs.size());
|
Assert.assertEquals(0, xAttrs.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Params for setting an xAttr */
|
/** Params for setting an xAttr. */
|
||||||
public static String setXAttrParam(String name, byte[] value) throws IOException {
|
public static String setXAttrParam(String name, byte[] value)
|
||||||
|
throws IOException {
|
||||||
return "xattr.name=" + name + "&xattr.value=" + XAttrCodec.encodeValue(
|
return "xattr.name=" + name + "&xattr.value=" + XAttrCodec.encodeValue(
|
||||||
value, XAttrCodec.HEX) + "&encoding=hex&flag=create";
|
value, XAttrCodec.HEX) + "&encoding=hex&flag=create";
|
||||||
}
|
}
|
||||||
@ -791,7 +810,9 @@ public void testOpenOffsetLength() throws Exception {
|
|||||||
|
|
||||||
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
||||||
URL url = new URL(TestJettyHelper.getJettyURL(),
|
URL url = new URL(TestJettyHelper.getJettyURL(),
|
||||||
MessageFormat.format("/webhdfs/v1/tmp/foo?user.name={0}&op=open&offset=1&length=2", user));
|
MessageFormat.format(
|
||||||
|
"/webhdfs/v1/tmp/foo?user.name={0}&op=open&offset=1&length=2",
|
||||||
|
user));
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
|
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
|
||||||
InputStream is = conn.getInputStream();
|
InputStream is = conn.getInputStream();
|
||||||
@ -814,7 +835,8 @@ public void testPutNoOperation() throws Exception {
|
|||||||
conn.setDoInput(true);
|
conn.setDoInput(true);
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
conn.setRequestMethod("PUT");
|
conn.setRequestMethod("PUT");
|
||||||
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
|
Assert.assertEquals(conn.getResponseCode(),
|
||||||
|
HttpURLConnection.HTTP_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -229,6 +229,7 @@ private void putCmd(String filename, String command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Test without ACLs.
|
||||||
* Ensure that
|
* Ensure that
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>GETFILESTATUS and LISTSTATUS work happily</li>
|
* <li>GETFILESTATUS and LISTSTATUS work happily</li>
|
||||||
|
Loading…
Reference in New Issue
Block a user