This is an automated email from the ASF dual-hosted git repository.
hzlu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new 76b30eb Clean up instance validation logic and test (#1342)
76b30eb is described below
commit 76b30eb76e771d74d8f588aeff89e04cf1e57c5e
Author: Meng Zhang <[email protected]>
AuthorDate: Wed Sep 2 21:12:01 2020 -0700
Clean up instance validation logic and test (#1342)
---
.../org/apache/helix/util/InstanceValidationUtil.java | 10 ++++++++--
.../apache/helix/util/TestInstanceValidationUtil.java | 16 ++++++++++++----
...onUtil.java => TestInstanceValidationUtilInRest.java} | 2 +-
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git
a/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
b/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
index bc3b48f..4c8ee0f 100644
--- a/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
+++ b/helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java
@@ -159,12 +159,14 @@ public class InstanceValidationUtil {
PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
ClusterConfig clusterConfig =
dataAccessor.getProperty(keyBuilder.clusterConfig());
if (clusterConfig == null) {
- throw new HelixException("Cluster config is missing in cluster " +
clusterId);
+ _logger.error("Cluster config is missing in cluster " + clusterId);
+ return false;
}
if (!clusterConfig.isPersistIntermediateAssignment()) {
- throw new HelixException(String.format(
+ _logger.error(String.format(
"Cluster config %s is not turned on, which is required for instance
stability check.",
ClusterConfig.ClusterConfigProperty.PERSIST_INTERMEDIATE_ASSIGNMENT.toString()));
+ return false;
}
PropertyKey propertyKey = keyBuilder.instanceConfig(instanceName);
InstanceConfig instanceConfig = dataAccessor.getProperty(propertyKey);
@@ -267,6 +269,10 @@ public class InstanceValidationUtil {
*/
public static boolean isInstanceStable(HelixDataAccessor dataAccessor,
String instanceName) {
PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
+ ClusterConfig clusterConfig =
dataAccessor.getProperty(keyBuilder.clusterConfig());
+ if (clusterConfig == null) {
+ throw new HelixException("Missing cluster config!");
+ }
List<String> idealStateNames =
dataAccessor.getChildNames(keyBuilder.idealStates());
for (String idealStateName : idealStateNames) {
IdealState idealState =
dataAccessor.getProperty(keyBuilder.idealStates(idealStateName));
diff --git
a/helix-core/src/test/java/org/apache/helix/util/TestInstanceValidationUtil.java
b/helix-core/src/test/java/org/apache/helix/util/TestInstanceValidationUtil.java
index f8de6ae..832cedd 100644
---
a/helix-core/src/test/java/org/apache/helix/util/TestInstanceValidationUtil.java
+++
b/helix-core/src/test/java/org/apache/helix/util/TestInstanceValidationUtil.java
@@ -43,6 +43,7 @@ import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.doReturn;
@@ -216,7 +217,14 @@ public class TestInstanceValidationUtil {
@Test
public void TestHasValidConfig_true() {
Mock mock = new Mock();
- when(mock.dataAccessor.getProperty(any(PropertyKey.class)))
+ PropertyKey.Builder keyBuilder = mock.dataAccessor.keyBuilder();
+ PropertyKey clusterProperty = keyBuilder.clusterConfig();
+ ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER);
+ clusterConfig.setPersistIntermediateAssignment(true);
+ when(mock.dataAccessor.getProperty(eq(clusterProperty)))
+ .thenReturn(clusterConfig);
+ PropertyKey instanceProperty = keyBuilder.instanceConfig(TEST_INSTANCE);
+ when(mock.dataAccessor.getProperty(eq(instanceProperty)))
.thenReturn(new InstanceConfig(TEST_INSTANCE));
Assert.assertTrue(
@@ -272,14 +280,14 @@ public class TestInstanceValidationUtil {
InstanceValidationUtil.hasErrorPartitions(mock.dataAccessor,
TEST_CLUSTER, TEST_INSTANCE));
}
- @Test(expectedExceptions = HelixException.class)
- public void TestIsInstanceStable_exception_whenPersistAssignmentOff() {
+ @Test
+ public void TestIsInstanceStable_NoException_whenPersistAssignmentOff() {
Mock mock = new Mock();
ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER);
clusterConfig.setPersistIntermediateAssignment(false);
when(mock.dataAccessor.getProperty(any(PropertyKey.class))).thenReturn(clusterConfig);
- InstanceValidationUtil.hasValidConfig(mock.dataAccessor, TEST_CLUSTER,
TEST_INSTANCE);
+ InstanceValidationUtil.isInstanceStable(mock.dataAccessor, TEST_INSTANCE);
}
@Test(expectedExceptions = HelixException.class)
diff --git
a/helix-rest/src/test/java/org/apache/helix/rest/server/util/TestInstanceValidationUtil.java
b/helix-rest/src/test/java/org/apache/helix/rest/server/util/TestInstanceValidationUtilInRest.java
similarity index 98%
rename from
helix-rest/src/test/java/org/apache/helix/rest/server/util/TestInstanceValidationUtil.java
rename to
helix-rest/src/test/java/org/apache/helix/rest/server/util/TestInstanceValidationUtilInRest.java
index 0483a05..ec8b186 100644
---
a/helix-rest/src/test/java/org/apache/helix/rest/server/util/TestInstanceValidationUtil.java
+++
b/helix-rest/src/test/java/org/apache/helix/rest/server/util/TestInstanceValidationUtilInRest.java
@@ -37,7 +37,7 @@ import org.testng.annotations.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class TestInstanceValidationUtil{
+public class TestInstanceValidationUtilInRest{
private static final String RESOURCE_NAME = "TestResource";
private static final String TEST_CLUSTER = "TestCluster";