diff --git a/shims/common/src/main/java/org/apache/hadoop/fs/ProxyFileSystem.java b/shims/common/src/main/java/org/apache/hadoop/fs/ProxyFileSystem.java index 608c7e0578..9e52ebf3e0 100644 --- a/shims/common/src/main/java/org/apache/hadoop/fs/ProxyFileSystem.java +++ b/shims/common/src/main/java/org/apache/hadoop/fs/ProxyFileSystem.java @@ -207,6 +207,25 @@ public boolean deleteOnExit(Path f) throws IOException { return ret; } + @Override //ref. HADOOP-12502 + public RemoteIterator listStatusIterator(Path f) throws IOException { + return new RemoteIterator() { + private final RemoteIterator orig = + ProxyFileSystem.super.listStatusIterator(swizzleParamPath(f)); + + @Override + public boolean hasNext() throws IOException { + return orig.hasNext(); + } + + @Override + public FileStatus next() throws IOException { + FileStatus ret = orig.next(); + return swizzleFileStatus(ret, false); + } + }; + } + @Override public Path getHomeDirectory() { return swizzleReturnPath(super.getHomeDirectory()); diff --git a/shims/common/src/main/test/org/apache/hadoop/fs/TestProxyFileSystem.java b/shims/common/src/main/test/org/apache/hadoop/fs/TestProxyFileSystem.java new file mode 100644 index 0000000000..d381212c6d --- /dev/null +++ b/shims/common/src/main/test/org/apache/hadoop/fs/TestProxyFileSystem.java @@ -0,0 +1,50 @@ +package org.apache.hadoop.fs; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.Paths; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class TestProxyFileSystem { + + @Test + public void testListStatusIterator() throws IOException { + FileStatus fileStatus = mock(FileStatus.class); + Path targetPath = new Path(Paths.get("").toAbsolutePath().toString()); + + FileSystem fileSystem = mock(FileSystem.class); + when(fileSystem.getUri()).thenReturn(URI.create("file:///")); + + ProxyFileSystem proxyFileSystem = new ProxyFileSystem(fileSystem, URI.create("pfile:///")); + when(fileStatus.getPath()).thenReturn(targetPath); + + when(fileSystem.listStatusIterator(any(Path.class))).thenReturn( + new RemoteIterator() { + @Override + public boolean hasNext(){ + return true; + } + + @Override + public FileStatus next() { + return fileStatus; + } + }); + + RemoteIterator iterator = proxyFileSystem.listStatusIterator(targetPath); + assertThat(iterator.hasNext(), equalTo(true)); + + FileStatus resultStatus = iterator.next(); + + assertNotNull(resultStatus); + assertThat(resultStatus.getPath().toString(), equalTo("pfile:" + targetPath)); + } +}