Repository: hive Updated Branches: refs/heads/master ff12054fe -> 4dff5b63b
HIVE-20465: ProxyFileSystem.listStatusIterator function override required once migrated to Hadoop 3.2.0+ (denys kuzmenko, via Peter Vary) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/4dff5b63 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/4dff5b63 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/4dff5b63 Branch: refs/heads/master Commit: 4dff5b63b1fbbb4b0930309d6b93bc2aaddbc379 Parents: ff12054 Author: denys kuzmenko <[email protected]> Authored: Wed Aug 29 12:40:28 2018 +0200 Committer: Peter Vary <[email protected]> Committed: Wed Aug 29 12:40:28 2018 +0200 ---------------------------------------------------------------------- .../org/apache/hadoop/fs/ProxyFileSystem.java | 19 ++++++ .../apache/hadoop/fs/TestProxyFileSystem.java | 71 ++++++++++++++++++++ 2 files changed, 90 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/4dff5b63/shims/common/src/main/java/org/apache/hadoop/fs/ProxyFileSystem.java ---------------------------------------------------------------------- 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 608c7e0..9e52ebf 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 class ProxyFileSystem extends FilterFileSystem { return ret; } + @Override //ref. HADOOP-12502 + public RemoteIterator<FileStatus> listStatusIterator(Path f) throws IOException { + return new RemoteIterator<FileStatus>() { + private final RemoteIterator<FileStatus> 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()); http://git-wip-us.apache.org/repos/asf/hive/blob/4dff5b63/shims/common/src/main/test/org/apache/hadoop/fs/TestProxyFileSystem.java ---------------------------------------------------------------------- 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 0000000..37667bb --- /dev/null +++ b/shims/common/src/main/test/org/apache/hadoop/fs/TestProxyFileSystem.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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; + +/** + * TestProxyFileSystem + */ +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<FileStatus>() { + @Override + public boolean hasNext() { + return true; + } + + @Override + public FileStatus next() { + return fileStatus; + } + }); + + RemoteIterator<FileStatus> iterator = proxyFileSystem.listStatusIterator(targetPath); + assertThat(iterator.hasNext(), equalTo(true)); + + FileStatus resultStatus = iterator.next(); + + assertNotNull(resultStatus); + assertThat(resultStatus.getPath().toString(), equalTo("pfile:" + targetPath)); + } +}
