use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.
the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForDirectory.
@Test
public void testGetContentSummaryForDirectory() throws Exception {
try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
viewer.initServer(originalFsimage.getAbsolutePath());
int port = viewer.getPort();
URL url = new URL("http://localhost:" + port + "/webhdfs/v1/parentDir/?op=GETCONTENTSUMMARY");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
// create a WebHdfsFileSystem instance
URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
Configuration conf = new Configuration();
WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
ContentSummary summary = webfs.getContentSummary(new Path("/parentDir/"));
verifyContentSummary(summaryFromDFS, summary);
}
}
use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.
the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForSymlink.
@Test
public void testGetContentSummaryForSymlink() throws Exception {
try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
viewer.initServer(originalFsimage.getAbsolutePath());
int port = viewer.getPort();
// create a WebHdfsFileSystem instance
URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
Configuration conf = new Configuration();
WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
ContentSummary summary = webfs.getContentSummary(new Path("/link1"));
verifyContentSummary(symLinkSummaryFromDFS, summary);
}
}
use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.
the class TestOfflineImageViewerForXAttr method testWithWebHdfsFileSystem.
@Test
public void testWithWebHdfsFileSystem() throws Exception {
try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
viewer.initServer(originalFsimage.getAbsolutePath());
int port = viewer.getPort();
// create a WebHdfsFileSystem instance
URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
Configuration conf = new Configuration();
WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
List<String> names = webhdfs.listXAttrs(new Path("/dir1"));
assertTrue(names.contains("user.attr1"));
assertTrue(names.contains("user.attr2"));
String value = new String(webhdfs.getXAttr(new Path("/dir1"), "user.attr1"));
assertEquals("value1", value);
value = new String(webhdfs.getXAttr(new Path("/dir1"), "USER.attr1"));
assertEquals("value1", value);
Map<String, byte[]> contentMap = webhdfs.getXAttrs(new Path("/dir1"), names);
assertEquals("value1", new String(contentMap.get("user.attr1")));
assertEquals("value2", new String(contentMap.get("user.attr2")));
}
}
use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.
the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForDirContainsSymlink.
@Test
public void testGetContentSummaryForDirContainsSymlink() throws Exception {
try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
viewer.initServer(originalFsimage.getAbsolutePath());
int port = viewer.getPort();
// create a WebHdfsFileSystem instance
URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
Configuration conf = new Configuration();
WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
ContentSummary summary = webfs.getContentSummary(new Path("/dirForLinks/"));
verifyContentSummary(symLinkSummaryForDirContainsFromDFS, summary);
}
}
use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.
the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForFile.
@Test
public void testGetContentSummaryForFile() throws Exception {
try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
viewer.initServer(originalFsimage.getAbsolutePath());
int port = viewer.getPort();
URL url = new URL("http://localhost:" + port + "/webhdfs/v1/parentDir/file1?op=GETCONTENTSUMMARY");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
// create a WebHdfsFileSystem instance
URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
Configuration conf = new Configuration();
WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
ContentSummary summary = webfs.getContentSummary(new Path("/parentDir/file1"));
verifyContentSummary(fileSummaryFromDFS, summary);
}
}
Aggregations