|
@@ -19,6 +19,7 @@
|
|
package org.apache.hadoop.fs.http.client;
|
|
package org.apache.hadoop.fs.http.client;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.BlockLocation;
|
|
import org.apache.hadoop.fs.BlockStoragePolicySpi;
|
|
import org.apache.hadoop.fs.BlockStoragePolicySpi;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
import org.apache.hadoop.fs.ContentSummary;
|
|
import org.apache.hadoop.fs.ContentSummary;
|
|
@@ -73,6 +74,10 @@ import org.apache.hadoop.test.TestHdfsHelper;
|
|
import org.apache.hadoop.test.TestJetty;
|
|
import org.apache.hadoop.test.TestJetty;
|
|
import org.apache.hadoop.test.TestJettyHelper;
|
|
import org.apache.hadoop.test.TestJettyHelper;
|
|
import org.apache.hadoop.util.Lists;
|
|
import org.apache.hadoop.util.Lists;
|
|
|
|
+
|
|
|
|
+import org.json.simple.JSONObject;
|
|
|
|
+import org.json.simple.parser.ContainerFactory;
|
|
|
|
+import org.json.simple.parser.JSONParser;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Assume;
|
|
import org.junit.Assume;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
@@ -101,11 +106,11 @@ import java.util.regex.Pattern;
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
+import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
@RunWith(value = Parameterized.class)
|
|
@RunWith(value = Parameterized.class)
|
|
public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
-
|
|
|
|
protected abstract Path getProxiedFSTestDir();
|
|
protected abstract Path getProxiedFSTestDir();
|
|
|
|
|
|
protected abstract String getProxiedFSURI();
|
|
protected abstract String getProxiedFSURI();
|
|
@@ -191,7 +196,7 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
|
|
|
|
protected void testGet() throws Exception {
|
|
protected void testGet() throws Exception {
|
|
FileSystem fs = getHttpFSFileSystem();
|
|
FileSystem fs = getHttpFSFileSystem();
|
|
- Assert.assertNotNull(fs);
|
|
|
|
|
|
+ assertNotNull(fs);
|
|
URI uri = new URI(getScheme() + "://" +
|
|
URI uri = new URI(getScheme() + "://" +
|
|
TestJettyHelper.getJettyURL().toURI().getAuthority());
|
|
TestJettyHelper.getJettyURL().toURI().getAuthority());
|
|
assertEquals(fs.getUri(), uri);
|
|
assertEquals(fs.getUri(), uri);
|
|
@@ -1201,7 +1206,7 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
ALLOW_SNAPSHOT, DISALLOW_SNAPSHOT, DISALLOW_SNAPSHOT_EXCEPTION,
|
|
ALLOW_SNAPSHOT, DISALLOW_SNAPSHOT, DISALLOW_SNAPSHOT_EXCEPTION,
|
|
FILE_STATUS_ATTR, GET_SNAPSHOT_DIFF, GET_SNAPSHOTTABLE_DIRECTORY_LIST,
|
|
FILE_STATUS_ATTR, GET_SNAPSHOT_DIFF, GET_SNAPSHOTTABLE_DIRECTORY_LIST,
|
|
GET_SNAPSHOT_LIST, GET_SERVERDEFAULTS, CHECKACCESS, SETECPOLICY,
|
|
GET_SNAPSHOT_LIST, GET_SERVERDEFAULTS, CHECKACCESS, SETECPOLICY,
|
|
- SATISFYSTORAGEPOLICY, GET_SNAPSHOT_DIFF_LISTING
|
|
|
|
|
|
+ SATISFYSTORAGEPOLICY, GET_SNAPSHOT_DIFF_LISTING, GETFILEBLOCKLOCATIONS
|
|
}
|
|
}
|
|
|
|
|
|
private void operation(Operation op) throws Exception {
|
|
private void operation(Operation op) throws Exception {
|
|
@@ -1341,6 +1346,9 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
case GET_SNAPSHOT_DIFF_LISTING:
|
|
case GET_SNAPSHOT_DIFF_LISTING:
|
|
testGetSnapshotDiffListing();
|
|
testGetSnapshotDiffListing();
|
|
break;
|
|
break;
|
|
|
|
+ case GETFILEBLOCKLOCATIONS:
|
|
|
|
+ testGetFileBlockLocations();
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -1959,6 +1967,37 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void testGetFileBlockLocations() throws Exception {
|
|
|
|
+ BlockLocation[] blockLocations;
|
|
|
|
+ Path testFile;
|
|
|
|
+ if (!this.isLocalFS()) {
|
|
|
|
+ FileSystem fs = this.getHttpFSFileSystem();
|
|
|
|
+ testFile = new Path(getProxiedFSTestDir(), "singleBlock.txt");
|
|
|
|
+ DFSTestUtil.createFile(fs, testFile, 1, (short) 1, 0L);
|
|
|
|
+ if (fs instanceof HttpFSFileSystem) {
|
|
|
|
+ HttpFSFileSystem httpFS = (HttpFSFileSystem) fs;
|
|
|
|
+ blockLocations = httpFS.getFileBlockLocations(testFile, 0, 1);
|
|
|
|
+ assertNotNull(blockLocations);
|
|
|
|
+
|
|
|
|
+ // verify HttpFSFileSystem.toBlockLocations()
|
|
|
|
+ String jsonString = JsonUtil.toJsonString(blockLocations);
|
|
|
|
+ JSONParser parser = new JSONParser();
|
|
|
|
+ JSONObject jsonObject = (JSONObject) parser.parse(jsonString, (ContainerFactory) null);
|
|
|
|
+ BlockLocation[] deserializedLocation = HttpFSFileSystem.toBlockLocations(jsonObject);
|
|
|
|
+ assertEquals(blockLocations.length, deserializedLocation.length);
|
|
|
|
+ for (int i = 0; i < blockLocations.length; i++) {
|
|
|
|
+ assertEquals(blockLocations[i].toString(), deserializedLocation[i].toString());
|
|
|
|
+ }
|
|
|
|
+ } else if (fs instanceof WebHdfsFileSystem) {
|
|
|
|
+ WebHdfsFileSystem webHdfsFileSystem = (WebHdfsFileSystem) fs;
|
|
|
|
+ blockLocations = webHdfsFileSystem.getFileBlockLocations(testFile, 0, 1);
|
|
|
|
+ assertNotNull(blockLocations);
|
|
|
|
+ } else {
|
|
|
|
+ Assert.fail(fs.getClass().getSimpleName() + " doesn't support access");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void testGetSnapshotDiffListing() throws Exception {
|
|
private void testGetSnapshotDiffListing() throws Exception {
|
|
if (!this.isLocalFS()) {
|
|
if (!this.isLocalFS()) {
|
|
// Create a directory with snapshot allowed
|
|
// Create a directory with snapshot allowed
|