diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java index dd69b08c934..d2550dc2f5d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegateToFileSystem.java @@ -160,7 +160,7 @@ public abstract class DelegateToFileSystem extends AbstractFileSystem { @Override public int getUriDefaultPort() { - return DELEGATE_TO_FS_DEFAULT_PORT; + return getDefaultPortIfDefined(fsImpl); } @Override diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegateToFsCheckPath.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegateToFsCheckPath.java index b1de316cf67..6030c12c16c 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegateToFsCheckPath.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegateToFsCheckPath.java @@ -33,19 +33,29 @@ import org.junit.Test; */ public class TestDelegateToFsCheckPath { @Test - public void testCheckPathWithoutDefaultPorts() throws URISyntaxException, + public void testCheckPathWithoutDefaultPort() throws URISyntaxException, IOException { URI uri = new URI("dummy://dummy-host"); - AbstractFileSystem afs = new DummyDelegateToFileSystem(uri); + AbstractFileSystem afs = new DummyDelegateToFileSystem(uri, + new UnOverrideDefaultPortFileSystem()); afs.checkPath(new Path("dummy://dummy-host")); } + @Test + public void testCheckPathWithDefaultPort() throws URISyntaxException, + IOException { + URI uri = new URI(String.format("dummy://dummy-host:%d", + OverrideDefaultPortFileSystem.DEFAULT_PORT)); + AbstractFileSystem afs = new DummyDelegateToFileSystem(uri, + new OverrideDefaultPortFileSystem()); + afs.checkPath(new Path("dummy://dummy-host/user/john/test")); + } + private static class DummyDelegateToFileSystem extends DelegateToFileSystem { - public DummyDelegateToFileSystem(URI uri) throws URISyntaxException, - IOException { - super(uri, new UnOverrideDefaultPortFileSystem(), new Configuration(), - "dummy", false); + public DummyDelegateToFileSystem(URI uri, FileSystem fs) + throws URISyntaxException, IOException { + super(uri, fs, new Configuration(), "dummy", false); } } @@ -123,4 +133,17 @@ public class TestDelegateToFsCheckPath { return null; } } + + /** + * OverrideDefaultPortFileSystem defines default port. + */ + private static class OverrideDefaultPortFileSystem + extends UnOverrideDefaultPortFileSystem { + private static final int DEFAULT_PORT = 1234; + + @Override + public int getDefaultPort() { + return DEFAULT_PORT; + } + } }