From 7017e13a55846180e1d9bb2c9cdd5f4f6383c5a8 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 5 Feb 2016 16:44:38 -0800 Subject: [PATCH 01/11] Rename TFSTest to AbstractFileSystemTest --- .../hadoop/{TFSTest.java => AbstractFileSystemTest.java} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename core/client-internal/src/test/java/alluxio/hadoop/{TFSTest.java => AbstractFileSystemTest.java} (97%) diff --git a/core/client-internal/src/test/java/alluxio/hadoop/TFSTest.java b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java similarity index 97% rename from core/client-internal/src/test/java/alluxio/hadoop/TFSTest.java rename to core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java index 6dfd41890eff..64fcddcde567 100644 --- a/core/client-internal/src/test/java/alluxio/hadoop/TFSTest.java +++ b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java @@ -54,8 +54,11 @@ * See https://code.google.com/p/powermock/wiki/FAQ. */ @PowerMockIgnore("javax.security.*") -public class TFSTest { - private static final Logger LOG = LoggerFactory.getLogger(TFSTest.class.getName()); +/** + * Tests for {@link AbstractFileSystem}. + */ +public class AbstractFileSystemTest { + private static final Logger LOG = LoggerFactory.getLogger(AbstractFileSystemTest.class.getName()); private ClassLoader getClassLoader(Class clazz) { // Power Mock makes this hard, so try to hack it From 0eb6ed7f0d4ea297a23d1fbf551de6fafa30eff3 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 5 Feb 2016 16:58:42 -0800 Subject: [PATCH 02/11] Improve test style --- .../hadoop/AbstractFileSystemTest.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java index 64fcddcde567..e62efb1e7155 100644 --- a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java +++ b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java @@ -58,7 +58,26 @@ * Tests for {@link AbstractFileSystem}. */ public class AbstractFileSystemTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractFileSystemTest.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE); + + /** + * Sets up the configuration before a test runs. + * + * @throws Exception when creating the mock fails + */ + @Before + public void setup() throws Exception { + mockUserGroupInformation(); + mockMasterClient(); + + if (isHadoop1x()) { + LOG.debug("Running TFS tests against hadoop 1x"); + } else if (isHadoop2x()) { + LOG.debug("Running TFS tests against hadoop 2x"); + } else { + LOG.warn("Running TFS tests against untargeted Hadoop version: " + getHadoopVersion()); + } + } private ClassLoader getClassLoader(Class clazz) { // Power Mock makes this hard, so try to hack it @@ -91,7 +110,7 @@ private URL getSourcePath(Class clazz) { } /** - * Ensures that Hadoop loads TFSFT when configured. + * Ensures that Hadoop loads {@link FaultTolerantFileSystem} when configured. * * @throws IOException when the file system cannot be retrieved */ @@ -108,7 +127,6 @@ public void hadoopShouldLoadTfsFtWhenConfigured() throws IOException { ClientContext.getConf().set(Constants.MASTER_HOSTNAME, uri.getHost()); ClientContext.getConf().set(Constants.MASTER_RPC_PORT, Integer.toString(uri.getPort())); ClientContext.getConf().set(Constants.ZOOKEEPER_ENABLED, "true"); - mockMasterClient(); final org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(uri, conf); @@ -125,7 +143,7 @@ public void hadoopShouldLoadTfsFtWhenConfigured() throws IOException { * @throws IOException when the file system cannot be retrieved */ @Test - public void hadoopShouldLoadTfsWhenConfigured() throws IOException { + public void hadoopShouldLoadFileSystemWhenConfigured() throws IOException { final Configuration conf = new Configuration(); if (isHadoop1x()) { conf.set("fs." + Constants.SCHEME + ".impl", FileSystem.class.getName()); @@ -137,7 +155,6 @@ public void hadoopShouldLoadTfsWhenConfigured() throws IOException { ClientContext.getConf().set(Constants.MASTER_HOSTNAME, uri.getHost()); ClientContext.getConf().set(Constants.MASTER_RPC_PORT, Integer.toString(uri.getPort())); ClientContext.getConf().set(Constants.ZOOKEEPER_ENABLED, "false"); - mockMasterClient(); final org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(uri, conf); @@ -171,22 +188,4 @@ private void mockUserGroupInformation() throws IOException { final UserGroupInformation ugi = Mockito.mock(UserGroupInformation.class); Mockito.when(UserGroupInformation.getCurrentUser()).thenReturn(ugi); } - - /** - * Sets up the configuration before a test runs. - * - * @throws Exception when creating the mock fails - */ - @Before - public void setup() throws Exception { - mockUserGroupInformation(); - - if (isHadoop1x()) { - LOG.debug("Running TFS tests against hadoop 1x"); - } else if (isHadoop2x()) { - LOG.debug("Running TFS tests against hadoop 2x"); - } else { - LOG.warn("Running TFS tests against untargeted Hadoop version: " + getHadoopVersion()); - } - } } From c2b9b285e2ca07ddba232e6feaaa41819132c59f Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 5 Feb 2016 16:59:21 -0800 Subject: [PATCH 03/11] Update test names --- .../src/test/java/alluxio/hadoop/AbstractFileSystemTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java index e62efb1e7155..241309a8b3b6 100644 --- a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java +++ b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java @@ -115,7 +115,7 @@ private URL getSourcePath(Class clazz) { * @throws IOException when the file system cannot be retrieved */ @Test - public void hadoopShouldLoadTfsFtWhenConfigured() throws IOException { + public void hadoopShouldLoadFaultTolerantFileSystemWhenConfiguredTest() throws IOException { final Configuration conf = new Configuration(); if (isHadoop1x()) { conf.set("fs." + Constants.SCHEME_FT + ".impl", FaultTolerantFileSystem.class.getName()); @@ -143,7 +143,7 @@ public void hadoopShouldLoadTfsFtWhenConfigured() throws IOException { * @throws IOException when the file system cannot be retrieved */ @Test - public void hadoopShouldLoadFileSystemWhenConfigured() throws IOException { + public void hadoopShouldLoadFileSystemWhenConfiguredTest() throws IOException { final Configuration conf = new Configuration(); if (isHadoop1x()) { conf.set("fs." + Constants.SCHEME + ".impl", FileSystem.class.getName()); From 4d9a01af48950a5f32b9812eed743e745c50f1dc Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 5 Feb 2016 17:05:18 -0800 Subject: [PATCH 04/11] Add failing unit test to demonstrate bug --- .../alluxio/hadoop/AbstractFileSystemTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java index 241309a8b3b6..f22725b4afc4 100644 --- a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java +++ b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; +import java.net.InetSocketAddress; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -165,6 +166,22 @@ public void hadoopShouldLoadFileSystemWhenConfiguredTest() throws IOException { ClientTestUtils.resetClientContext(); } + /** + * Tests that initializing the {@link AbstractFileSystem} will reinitialize contexts so to pick + * up changes to the master address. + */ + @Test + public void resetContextTest() throws Exception { + URI uri = URI.create(Constants.HEADER + "localhost:19998/"); + + Configuration conf = new Configuration(); + org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(uri, conf); + + URI newUri = URI.create(Constants.HEADER + "otherhost:410/"); + fs.initialize(newUri, conf); + Assert.assertEquals(new InetSocketAddress("otherhost", 410), ClientContext.getMasterAddress()); + } + private boolean isHadoop1x() { return getHadoopVersion().startsWith("1"); } From ce775f3a56510afdb0e3324e76fe45e421dc09d6 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 5 Feb 2016 17:06:35 -0800 Subject: [PATCH 05/11] Reset static contexts when hadoop updates the master address --- .../main/java/alluxio/client/ClientContext.java | 4 ++-- .../java/alluxio/hadoop/AbstractFileSystem.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/client-internal/src/main/java/alluxio/client/ClientContext.java b/core/client-internal/src/main/java/alluxio/client/ClientContext.java index 66b4e58ba2af..73949bb94690 100644 --- a/core/client-internal/src/main/java/alluxio/client/ClientContext.java +++ b/core/client-internal/src/main/java/alluxio/client/ClientContext.java @@ -23,8 +23,8 @@ import com.google.common.base.Preconditions; -import alluxio.Constants; import alluxio.Configuration; +import alluxio.Constants; import alluxio.util.ThreadFactoryUtils; import alluxio.worker.ClientMetrics; @@ -61,7 +61,7 @@ private static void reset() { * {@link Configuration} when {@link Configuration} is changed, e.g. the master hostname or port. * This method requires that configuration has been initialized. */ - private static void init() { + public static void init() { String masterHostname = Preconditions.checkNotNull(sConf.get(Constants.MASTER_HOSTNAME)); int masterPort = sConf.getInt(Constants.MASTER_RPC_PORT); sMasterAddress = new InetSocketAddress(masterHostname, masterPort); diff --git a/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java b/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java index 8b9ef60acd3f..be2cf446ed82 100644 --- a/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java +++ b/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java @@ -36,9 +36,11 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import alluxio.Constants; import alluxio.AlluxioURI; +import alluxio.Configuration; +import alluxio.Constants; import alluxio.client.ClientContext; +import alluxio.client.block.BlockStoreContext; import alluxio.client.file.FileOutStream; import alluxio.client.file.FileSystem; import alluxio.client.file.FileSystemContext; @@ -48,13 +50,13 @@ import alluxio.client.file.options.CreateFileOptions; import alluxio.client.file.options.DeleteOptions; import alluxio.client.file.options.SetAttributeOptions; -import alluxio.Configuration; +import alluxio.client.lineage.LineageContext; +import alluxio.exception.AlluxioException; import alluxio.exception.ConnectionFailedException; import alluxio.exception.ExceptionMessage; import alluxio.exception.FileDoesNotExistException; import alluxio.exception.InvalidPathException; import alluxio.exception.PreconditionMessage; -import alluxio.exception.AlluxioException; import alluxio.util.CommonUtils; import alluxio.wire.FileBlockInfo; import alluxio.wire.WorkerNetAddress; @@ -431,6 +433,12 @@ public void initialize(URI uri, org.apache.hadoop.conf.Configuration conf) throw ClientContext.getConf().set(Constants.MASTER_RPC_PORT, Integer.toString(uri.getPort())); ClientContext.getConf().set(Constants.ZOOKEEPER_ENABLED, Boolean.toString(isZookeeperMode())); + // These must be reset to pick up the change to the master address + ClientContext.init(); + FileSystemContext.INSTANCE.reset(); + BlockStoreContext.INSTANCE.reset(); + LineageContext.INSTANCE.reset(); + mFileSystem = FileSystem.Factory.get(); mUri = URI.create(mAlluxioHeader); mUnderFSAddress = getUfsAddress(); From d1f6cb6eebbd0bcc859faf68d30a291535451605 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Fri, 5 Feb 2016 17:16:27 -0800 Subject: [PATCH 06/11] Add jira ticket and TODO --- .../src/main/java/alluxio/hadoop/AbstractFileSystem.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java b/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java index be2cf446ed82..0c8922da5bc6 100644 --- a/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java +++ b/core/client-internal/src/main/java/alluxio/hadoop/AbstractFileSystem.java @@ -433,7 +433,8 @@ public void initialize(URI uri, org.apache.hadoop.conf.Configuration conf) throw ClientContext.getConf().set(Constants.MASTER_RPC_PORT, Integer.toString(uri.getPort())); ClientContext.getConf().set(Constants.ZOOKEEPER_ENABLED, Boolean.toString(isZookeeperMode())); - // These must be reset to pick up the change to the master address + // These must be reset to pick up the change to the master address. + // TODO(andrew): We should reset key value system in this situation - see TACHYON-1706. ClientContext.init(); FileSystemContext.INSTANCE.reset(); BlockStoreContext.INSTANCE.reset(); From 22fe7bca396bf138dd7d024775a4b945cfae19ab Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Sat, 6 Feb 2016 01:34:46 -0800 Subject: [PATCH 07/11] Add common test utils --- .../test/java/alluxio/CommonTestUtils.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 core/common/src/test/java/alluxio/CommonTestUtils.java diff --git a/core/common/src/test/java/alluxio/CommonTestUtils.java b/core/common/src/test/java/alluxio/CommonTestUtils.java new file mode 100644 index 000000000000..9316bc13e6e7 --- /dev/null +++ b/core/common/src/test/java/alluxio/CommonTestUtils.java @@ -0,0 +1,61 @@ +/* + * Licensed to the University of California, Berkeley 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 alluxio; + +import org.powermock.reflect.Whitebox; + +/** + * Common utilities for testing. + */ +public final class CommonTestUtils { + + /** + * Traverses a chain of potentially private fields using {@link Whitebox}. + * + * For example, if you have the classes + * + *
{@code
+   *public class Foo {
+   *  private Bar myBar = new Bar();
+   *}
+   *
+   *public class Bar {
+   *  private String secret = "puppy";
+   *}
+   *}
+ * + * then you can access {@code "puppy"} with + * {@code CommonTestUtils.getInternalState(new Foo(), "myBar", "secret")}. + * + * @param instance the object to start the traversal from + * @param fieldNames the field names to traverse + * @return the final value at the end of the traversal + */ + public static T getInternalState(Object instance, String... fieldNames) { + Object current = instance; + for (String fieldName : fieldNames) { + Object next = Whitebox.getInternalState(current, fieldName); + if (next == null) { + throw new RuntimeException( + "Couldn't find field " + fieldName + " in " + current.getClass()); + } + current = next; + } + @SuppressWarnings("unchecked") + T finalObject = (T) current; + return finalObject; + } +} From 47954a6e74f66f8003665f68aaa65c18ea755937 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Sat, 6 Feb 2016 01:36:02 -0800 Subject: [PATCH 08/11] Add test-only dependency of client on common --- core/client-internal/pom.xml | 8 ++++++++ core/common/pom.xml | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/client-internal/pom.xml b/core/client-internal/pom.xml index 62284c259805..8fedb694a722 100644 --- a/core/client-internal/pom.xml +++ b/core/client-internal/pom.xml @@ -48,6 +48,14 @@ com.google.code.findbugs annotations + + + + org.alluxio.alluxio + alluxio-core-common + ${project.version} + test-jar + diff --git a/core/common/pom.xml b/core/common/pom.xml index 8bd95e869b27..3d29f09054d0 100644 --- a/core/common/pom.xml +++ b/core/common/pom.xml @@ -98,5 +98,20 @@ true + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + test-jar + + + + + From bbd62f9fcf09cc73b22479576730394b25819319 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Sat, 6 Feb 2016 01:36:58 -0800 Subject: [PATCH 09/11] Test that all contexts are reset --- .../hadoop/AbstractFileSystemTest.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java index f22725b4afc4..c6d381f123bb 100644 --- a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java +++ b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java @@ -38,10 +38,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import alluxio.CommonTestUtils; import alluxio.Constants; import alluxio.client.ClientContext; +import alluxio.client.block.BlockStoreContext; import alluxio.client.file.FileSystemContext; import alluxio.client.file.FileSystemMasterClient; +import alluxio.client.lineage.LineageContext; import alluxio.client.util.ClientTestUtils; /** @@ -60,6 +63,7 @@ */ public class AbstractFileSystemTest { private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE); + private FileSystemContext mMockFileSystemContext; /** * Sets up the configuration before a test runs. @@ -179,7 +183,14 @@ public void resetContextTest() throws Exception { URI newUri = URI.create(Constants.HEADER + "otherhost:410/"); fs.initialize(newUri, conf); - Assert.assertEquals(new InetSocketAddress("otherhost", 410), ClientContext.getMasterAddress()); + InetSocketAddress newAddress = new InetSocketAddress("otherhost", 410); + Assert.assertEquals(newAddress, ClientContext.getMasterAddress()); + Assert.assertEquals(newAddress, CommonTestUtils.getInternalState(BlockStoreContext.INSTANCE, + "mBlockMasterClientPool", "mMasterAddress")); + // Once from calling FileSystem.get, once from calling initialize. + Mockito.verify(mMockFileSystemContext, Mockito.times(2)).reset(); + Assert.assertEquals(newAddress, CommonTestUtils.getInternalState(LineageContext.INSTANCE, + "mLineageMasterClientPool", "mMasterAddress")); } private boolean isHadoop1x() { @@ -192,11 +203,11 @@ private boolean isHadoop2x() { private void mockMasterClient() { PowerMockito.mockStatic(FileSystemContext.class); - FileSystemContext mockContext = PowerMockito.mock(FileSystemContext.class); + mMockFileSystemContext = PowerMockito.mock(FileSystemContext.class); FileSystemMasterClient mockMaster = PowerMockito.mock(FileSystemMasterClient.class); - Whitebox.setInternalState(FileSystemContext.class, "INSTANCE", mockContext); - Mockito.when(mockContext.acquireMasterClient()).thenReturn(mockMaster); + Whitebox.setInternalState(FileSystemContext.class, "INSTANCE", mMockFileSystemContext); + Mockito.when(mMockFileSystemContext.acquireMasterClient()).thenReturn(mockMaster); } private void mockUserGroupInformation() throws IOException { From aa210736028b51128803c2dfb157a45f33ccf269 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Sat, 6 Feb 2016 01:45:40 -0800 Subject: [PATCH 10/11] test jars should be in test scope --- core/client-internal/pom.xml | 1 + keyvalue/client-internal/pom.xml | 2 +- minicluster/pom.xml | 4 +++- tests/pom.xml | 16 +++++++++------- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/client-internal/pom.xml b/core/client-internal/pom.xml index 8fedb694a722..16facb9b639f 100644 --- a/core/client-internal/pom.xml +++ b/core/client-internal/pom.xml @@ -55,6 +55,7 @@ alluxio-core-common ${project.version} test-jar + test diff --git a/keyvalue/client-internal/pom.xml b/keyvalue/client-internal/pom.xml index c79870597c6a..269b6cf2e738 100644 --- a/keyvalue/client-internal/pom.xml +++ b/keyvalue/client-internal/pom.xml @@ -34,8 +34,8 @@ org.alluxio.alluxio alluxio-core-client-internal ${project.version} - test test-jar + test diff --git a/minicluster/pom.xml b/minicluster/pom.xml index a05f27860bc8..729d12dbf320 100644 --- a/minicluster/pom.xml +++ b/minicluster/pom.xml @@ -47,12 +47,14 @@ alluxio-core-client-internal ${project.version} test-jar + test org.alluxio.alluxio alluxio-core-server - test-jar ${project.version} + test-jar + test diff --git a/tests/pom.xml b/tests/pom.xml index 12278d6dc341..35a29c3b4a9b 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -53,13 +53,6 @@ alluxio-core-common ${project.version} - - org.alluxio.alluxio - alluxio-core-server - test-jar - ${project.version} - test - org.alluxio.alluxio alluxio-keyvalue-client-internal @@ -90,6 +83,15 @@ ${project.version} test + + + + org.alluxio.alluxio + alluxio-core-server + ${project.version} + test-jar + test + From 9665190937335a60d7be1c96e6a92de4f0929232 Mon Sep 17 00:00:00 2001 From: Andrew Audibert Date: Sat, 6 Feb 2016 01:50:31 -0800 Subject: [PATCH 11/11] test cleanup --- .../test/java/alluxio/hadoop/AbstractFileSystemTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java index c6d381f123bb..ef132e35c6fb 100644 --- a/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java +++ b/core/client-internal/src/test/java/alluxio/hadoop/AbstractFileSystemTest.java @@ -171,18 +171,21 @@ public void hadoopShouldLoadFileSystemWhenConfiguredTest() throws IOException { } /** - * Tests that initializing the {@link AbstractFileSystem} will reinitialize contexts so to pick - * up changes to the master address. + * Tests that initializing the {@link AbstractFileSystem} will reinitialize contexts to pick up + * changes to the master address. */ @Test public void resetContextTest() throws Exception { + // Create system with master at localhost:19998 URI uri = URI.create(Constants.HEADER + "localhost:19998/"); - Configuration conf = new Configuration(); org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(uri, conf); + // Change to otherhost:410 URI newUri = URI.create(Constants.HEADER + "otherhost:410/"); fs.initialize(newUri, conf); + + // Make sure all contexts are using the new address InetSocketAddress newAddress = new InetSocketAddress("otherhost", 410); Assert.assertEquals(newAddress, ClientContext.getMasterAddress()); Assert.assertEquals(newAddress, CommonTestUtils.getInternalState(BlockStoreContext.INSTANCE,