public void GetListing_Always_PerformsGetListingRequestAndReturnsListOfCdfsFileStatus() { // Arrange var restResponse = new RestResponse <List <CdfsFileStatus> >(); restResponse.StatusCode = HttpStatusCode.OK; var listOfCdfsFileStatus = new List <CdfsFileStatus> { }; restResponse.Content = JsonConvert.SerializeObject(listOfCdfsFileStatus); var restRequest = new RestRequest("/ClientProtocol/GetListing", Method.GET); restRequest.AddParameter(filePath, testFilePath); _mockRestClient.Setup(x => x.Execute <List <CdfsFileStatus> >(It.IsAny <RestRequest>())).Returns(restResponse); var sut = new ClientProtocol(_mockRestClient.Object); // Act var result = sut.GetListing(testFilePath); // Assert _mockRestClient.Verify(x => x.Execute <List <CdfsFileStatus> >(It.Is <RestRequest>(r => VerifyRestRequest(restRequest, r)))); Assert.AreEqual(result, listOfCdfsFileStatus); }
/// <exception cref="System.IO.IOException"/> public Void Run() { ClientProtocol nn = this._enclosing.CreateNameNodeProxy(); doc.Declaration(); doc.StartTag("listing"); foreach (KeyValuePair <string, string> m in root) { doc.Attribute(m.Key, m.Value); } HdfsFileStatus @base = nn.GetFileInfo(filePath); if ((@base != null) && @base.IsDir()) { ListPathsServlet.WriteInfo(@base.GetFullPath(new Path(path)), @base, doc); } Stack <string> pathstack = new Stack <string>(); pathstack.Push(path); while (!pathstack.Empty()) { string p = pathstack.Pop(); try { byte[] lastReturnedName = HdfsFileStatus.EmptyName; DirectoryListing thisListing; do { System.Diagnostics.Debug.Assert(lastReturnedName != null); thisListing = nn.GetListing(p, lastReturnedName, false); if (thisListing == null) { if (lastReturnedName.Length == 0) { DfsServlet.Log.Warn("ListPathsServlet - Path " + p + " does not exist"); } break; } HdfsFileStatus[] listing = thisListing.GetPartialListing(); foreach (HdfsFileStatus i in listing) { Path fullpath = i.GetFullPath(new Path(p)); string localName = fullpath.GetName(); if (exclude.Matcher(localName).Matches() || !filter.Matcher(localName).Matches()) { continue; } if (recur && i.IsDir()) { pathstack.Push(new Path(p, localName).ToUri().GetPath()); } ListPathsServlet.WriteInfo(fullpath, i, doc); } lastReturnedName = thisListing.GetLastName(); }while (thisListing.HasMore()); } catch (IOException re) { this._enclosing.WriteXml(re, p, doc); } } return(null); }