|
@@ -58,6 +58,7 @@ public class MockResolver
|
|
|
private Set<FederationNamespaceInfo> namespaces = new HashSet<>();
|
|
|
private String defaultNamespace = null;
|
|
|
private boolean disableDefaultNamespace = false;
|
|
|
+ private volatile boolean disableRegistration = false;
|
|
|
|
|
|
public MockResolver() {
|
|
|
this.cleanRegistrations();
|
|
@@ -98,6 +99,15 @@ public class MockResolver
|
|
|
this.namespaces = new HashSet<>();
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * Disable NameNode auto registration for test. This method usually used after
|
|
|
+ * {@link MockResolver#cleanRegistrations()}, and before {@link
|
|
|
+ * MockResolver#registerNamenode()}
|
|
|
+ */
|
|
|
+ public void setDisableRegistration(boolean isDisable) {
|
|
|
+ disableRegistration = isDisable;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void updateActiveNamenode(
|
|
|
String nsId, InetSocketAddress successfulAddress) {
|
|
@@ -125,7 +135,7 @@ public class MockResolver
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<? extends FederationNamenodeContext>
|
|
|
+ public synchronized List<? extends FederationNamenodeContext>
|
|
|
getNamenodesForNameserviceId(String nameserviceId) {
|
|
|
// Return a copy of the list because it is updated periodically
|
|
|
List<? extends FederationNamenodeContext> namenodes =
|
|
@@ -137,8 +147,8 @@ public class MockResolver
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<? extends FederationNamenodeContext> getNamenodesForBlockPoolId(
|
|
|
- String blockPoolId) {
|
|
|
+ public synchronized List<? extends FederationNamenodeContext>
|
|
|
+ getNamenodesForBlockPoolId(String blockPoolId) {
|
|
|
// Return a copy of the list because it is updated periodically
|
|
|
List<? extends FederationNamenodeContext> namenodes =
|
|
|
this.resolver.get(blockPoolId);
|
|
@@ -226,6 +236,9 @@ public class MockResolver
|
|
|
@Override
|
|
|
public synchronized boolean registerNamenode(NamenodeStatusReport report)
|
|
|
throws IOException {
|
|
|
+ if (disableRegistration) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
MockNamenodeContext context = new MockNamenodeContext(
|
|
|
report.getRpcAddress(), report.getServiceAddress(),
|
|
@@ -263,8 +276,9 @@ public class MockResolver
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Set<FederationNamespaceInfo> getNamespaces() throws IOException {
|
|
|
- return this.namespaces;
|
|
|
+ public synchronized Set<FederationNamespaceInfo> getNamespaces()
|
|
|
+ throws IOException {
|
|
|
+ return Collections.unmodifiableSet(this.namespaces);
|
|
|
}
|
|
|
|
|
|
@Override
|