public virtual void TestWebImageViewer() { WebImageViewer viewer = new WebImageViewer(NetUtils.CreateSocketAddr("localhost:0" )); try { viewer.InitServer(originalFsimage.GetAbsolutePath()); int port = viewer.GetPort(); // create a WebHdfsFileSystem instance URI uri = new URI("webhdfs://localhost:" + port.ToString()); Configuration conf = new Configuration(); WebHdfsFileSystem webhdfs = (WebHdfsFileSystem)FileSystem.Get(uri, conf); // verify the number of directories FileStatus[] statuses = webhdfs.ListStatus(new Path("/")); NUnit.Framework.Assert.AreEqual(NumDirs + 3, statuses.Length); // contains empty and xattr directory // verify the number of files in the directory statuses = webhdfs.ListStatus(new Path("/dir0")); NUnit.Framework.Assert.AreEqual(FilesPerDir, statuses.Length); // compare a file FileStatus status = webhdfs.ListStatus(new Path("/dir0/file0"))[0]; FileStatus expected = writtenFiles["/dir0/file0"]; CompareFile(expected, status); // LISTSTATUS operation to an empty directory statuses = webhdfs.ListStatus(new Path("/emptydir")); NUnit.Framework.Assert.AreEqual(0, statuses.Length); // LISTSTATUS operation to a invalid path Uri url = new Uri("http://localhost:" + port + "/webhdfs/v1/invalid/?op=LISTSTATUS" ); VerifyHttpResponseCode(HttpURLConnection.HttpNotFound, url); // LISTSTATUS operation to a invalid prefix url = new Uri("http://localhost:" + port + "/foo"); VerifyHttpResponseCode(HttpURLConnection.HttpNotFound, url); // GETFILESTATUS operation status = webhdfs.GetFileStatus(new Path("/dir0/file0")); CompareFile(expected, status); // GETFILESTATUS operation to a invalid path url = new Uri("http://localhost:" + port + "/webhdfs/v1/invalid/?op=GETFILESTATUS" ); VerifyHttpResponseCode(HttpURLConnection.HttpNotFound, url); // invalid operation url = new Uri("http://localhost:" + port + "/webhdfs/v1/?op=INVALID"); VerifyHttpResponseCode(HttpURLConnection.HttpBadRequest, url); // invalid method url = new Uri("http://localhost:" + port + "/webhdfs/v1/?op=LISTSTATUS"); HttpURLConnection connection = (HttpURLConnection)url.OpenConnection(); connection.SetRequestMethod("POST"); connection.Connect(); NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpBadMethod, connection.GetResponseCode ()); } finally { // shutdown the viewer viewer.Close(); } }