예제 #1
0
        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();
            }
        }
        public virtual void TestWebImageViewerForAcl()
        {
            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);
                // GETACLSTATUS operation to a directory without ACL
                AclStatus acl = webhdfs.GetAclStatus(new Path("/dirWithNoAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/dirWithNoAcl"], acl);
                // GETACLSTATUS operation to a directory with a default ACL
                acl = webhdfs.GetAclStatus(new Path("/dirWithDefaultAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/dirWithDefaultAcl"], acl);
                // GETACLSTATUS operation to a file without ACL
                acl = webhdfs.GetAclStatus(new Path("/noAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/noAcl"], acl);
                // GETACLSTATUS operation to a file with a ACL
                acl = webhdfs.GetAclStatus(new Path("/withAcl"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/withAcl"], acl);
                // GETACLSTATUS operation to a file with several ACL entries
                acl = webhdfs.GetAclStatus(new Path("/withSeveralAcls"));
                NUnit.Framework.Assert.AreEqual(writtenAcls["/withSeveralAcls"], acl);
                // GETACLSTATUS operation to a invalid path
                Uri url = new Uri("http://localhost:" + port + "/webhdfs/v1/invalid/?op=GETACLSTATUS"
                                  );
                HttpURLConnection connection = (HttpURLConnection)url.OpenConnection();
                connection.SetRequestMethod("GET");
                connection.Connect();
                NUnit.Framework.Assert.AreEqual(HttpURLConnection.HttpNotFound, connection.GetResponseCode
                                                    ());
            }
            finally
            {
                // shutdown the viewer
                viewer.Close();
            }
        }