This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch customizeView
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/customizeView by this push:
     new 87d077b  Move routing table provider initialization (#946)
87d077b is described below

commit 87d077b21f252490104b0fe55f9451fc59db7310
Author: Molly Gao <[email protected]>
AuthorDate: Mon Apr 13 10:56:48 2020 -0700

    Move routing table provider initialization (#946)
    
    This PR moves the initialization of routing table provider to before class 
so it is initialized before any updates. Also, added several checks into the 
validation method to cover some edge cases.
---
 .../integration/TestCustomizedViewAggregation.java | 92 +++++++++++-----------
 1 file changed, 48 insertions(+), 44 deletions(-)

diff --git 
a/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedViewAggregation.java
 
b/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedViewAggregation.java
index af24107..e270e9f 100644
--- 
a/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedViewAggregation.java
+++ 
b/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedViewAggregation.java
@@ -71,9 +71,7 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
   public void beforeClass() throws Exception {
     super.beforeClass();
 
-    String className = TestHelper.getTestClassName();
-    String methodName = TestHelper.getTestMethodName();
-    String clusterName = className + "_" + methodName;
+    String clusterName = TestHelper.getTestClassName();
     int n = 2;
 
     System.out.println("START " + clusterName + " at " + new 
Date(System.currentTimeMillis()));
@@ -120,6 +118,23 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
     _localCustomizedView = new HashMap<>();
     _routingTableProviderDataSources = new HashSet<>();
     _aggregationEnabledTypes = new HashSet<>();
+
+    List<String> customizedStateTypes = Arrays
+        .asList(CustomizedStateType.TYPE_A.name(), 
CustomizedStateType.TYPE_B.name(),
+            CustomizedStateType.TYPE_C.name());
+
+    CustomizedStateConfig.Builder customizedStateConfigBuilder =
+        new CustomizedStateConfig.Builder();
+    
customizedStateConfigBuilder.setAggregationEnabledTypes(customizedStateTypes);
+    HelixDataAccessor accessor = _manager.getHelixDataAccessor();
+    accessor.setProperty(accessor.keyBuilder().customizedStateConfig(),
+        customizedStateConfigBuilder.build());
+    _aggregationEnabledTypes.addAll(customizedStateTypes);
+
+    Map<PropertyType, List<String>> dataSource = new HashMap<>();
+    dataSource.put(PropertyType.CUSTOMIZEDVIEW, customizedStateTypes);
+    _routingTableProvider = new RoutingTableProvider(_spectator, dataSource);
+    _routingTableProviderDataSources.addAll(customizedStateTypes);
   }
 
   @AfterClass
@@ -143,7 +158,6 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
         // Get customized view snapshot
         Map<String, RoutingTableSnapshot> fullCustomizedViewSnapshot =
             routingTableSnapshots.get(PropertyType.CUSTOMIZEDVIEW.name());
-        boolean result = false;
 
         if (fullCustomizedViewSnapshot.isEmpty() && 
!_routingTableProviderDataSources.isEmpty()) {
           return false;
@@ -170,6 +184,11 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
             return false;
           }
 
+          if (_aggregationEnabledTypes.contains(customizedStateType)
+              && customizedViews.size() != localSnapshot.size()) {
+            return false;
+          }
+
           // Get per resource snapshot
           for (CustomizedView resourceCustomizedView : customizedViews) {
             ZNRecord record = resourceCustomizedView.getRecord();
@@ -200,10 +219,7 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
                 // Per instance value
                 String stateMapValue = stateMap.get(instanceName);
                 String localStateMapValue = localStateMap.get(instanceName);
-                if (isEmptyValue(stateMapValue) && 
isEmptyValue(localStateMapValue)) {
-                } else if ((!isEmptyValue(stateMapValue) && 
!isEmptyValue(localStateMapValue)
-                    && !stateMapValue.equals(localStateMapValue)) || 
(isEmptyValue(stateMapValue)
-                    || isEmptyValue(localStateMapValue))) {
+                if (!stateMapValue.equals(localStateMapValue)) {
                   return false;
                 }
               }
@@ -217,10 +233,6 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
     Assert.assertTrue(result);
   }
 
-  private boolean isEmptyValue(String value) {
-    return value == null || value.equals("");
-  }
-
   /**
    * Update the local record of customized view
    * @param instanceName the instance to be updated
@@ -243,12 +255,6 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
       localPerPartition.remove(instanceName);
       if (localPerPartition.isEmpty()) {
         localPerResource.remove(partitionName);
-        if (localPerResource.isEmpty()) {
-          localPerStateType.remove(resourceName);
-          if (localPerStateType.isEmpty()) {
-            _localCustomizedView.remove(customizedStateType.name());
-          }
-        }
       }
     } else {
       localPerPartition.put(instanceName, customizedStateValue.name());
@@ -348,9 +354,10 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
   }
 
   @Test
-  public void testCustomizedStateViewAggregation() throws Exception {
-    setAggregationEnabledTypes(
-        Arrays.asList(CustomizedStateType.TYPE_A, CustomizedStateType.TYPE_B));
+  public void testCustomizedViewAggregation() throws Exception {
+
+    // Aggregating: Type A, Type B, Type C
+    // Routing table: Type A, Type B, Type C
 
     update(INSTANCE_0, CustomizedStateType.TYPE_A, RESOURCE_0, PARTITION_00,
         CurrentStateValues.TYPE_A_0);
@@ -370,16 +377,6 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
         CurrentStateValues.TYPE_C_2);
     update(INSTANCE_1, CustomizedStateType.TYPE_A, RESOURCE_1, PARTITION_11,
         CurrentStateValues.TYPE_A_1);
-
-    // Aggregation enabled types: A, B; Routing table provider data sources: 
A, B, C; should show TypeA, TypeB customized views
-    setRoutingTableProviderDataSources(Arrays
-        .asList(CustomizedStateType.TYPE_A, CustomizedStateType.TYPE_B,
-            CustomizedStateType.TYPE_C));
-    validateAggregationSnapshot();
-
-    // Aggregation enabled types: A, B; Routing table provider data sources: 
A, B, C; should show TypeA, TypeB customized views
-    setAggregationEnabledTypes(Arrays.asList(CustomizedStateType.TYPE_A, 
CustomizedStateType.TYPE_B,
-        CustomizedStateType.TYPE_C));
     validateAggregationSnapshot();
 
     Assert.assertNull(_customizedStateProvider_participant0
@@ -395,8 +392,18 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
     updateLocalCustomizedViewMap(INSTANCE_1, CustomizedStateType.TYPE_A, 
RESOURCE_1, PARTITION_10,
         CurrentStateValues.TYPE_A_2);
 
-    // Aggregation enabled types: A, B, C; Routing table provider data 
sources: A; should only show TypeA customized view
-    
setRoutingTableProviderDataSources(Arrays.asList(CustomizedStateType.TYPE_A));
+    validateAggregationSnapshot();
+
+    // Set the routing table provider data sources to only Type A and Type B, 
so users won't see Type C customized view
+    // Aggregating: Type A, Type B, Type C
+    // Routing table: Type A, Type B
+    setRoutingTableProviderDataSources(
+        Arrays.asList(CustomizedStateType.TYPE_A, CustomizedStateType.TYPE_B));
+    validateAggregationSnapshot();
+
+    // Aggregating: Type A
+    // Routing table: Type A, Type B
+    setAggregationEnabledTypes(Arrays.asList(CustomizedStateType.TYPE_A));
     validateAggregationSnapshot();
 
     // Test get customized state and get per partition customized state via 
customized state provider, this part of test doesn't change customized view
@@ -433,17 +440,6 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
         null);
     validateAggregationSnapshot();
 
-    //Aggregation enabled types: B; Routing table provider data sources: A, B, 
C; should show TypeB customized views
-    setAggregationEnabledTypes(Arrays.asList(CustomizedStateType.TYPE_B));
-    setRoutingTableProviderDataSources(Arrays
-        .asList(CustomizedStateType.TYPE_A, CustomizedStateType.TYPE_B,
-            CustomizedStateType.TYPE_C));
-    validateAggregationSnapshot();
-
-    //Aggregation enabled types: B; Routing table provider data sources: A; 
should show empty customized view
-    
setRoutingTableProviderDataSources(Arrays.asList(CustomizedStateType.TYPE_A));
-    validateAggregationSnapshot();
-
     // Update some customized states and verify
     delete(INSTANCE_0, CustomizedStateType.TYPE_A, RESOURCE_0, PARTITION_00);
     delete(INSTANCE_1, CustomizedStateType.TYPE_B, RESOURCE_1, PARTITION_10);
@@ -452,6 +448,14 @@ public class TestCustomizedViewAggregation extends 
ZkUnitTestBase {
     delete(INSTANCE_1, CustomizedStateType.TYPE_A, RESOURCE_1, PARTITION_10);
     validateAggregationSnapshot();
 
+    // Aggregating: Type A, Type B, Type C
+    // Routing table: Type A, Type B, Type C
+    setRoutingTableProviderDataSources(Arrays
+        .asList(CustomizedStateType.TYPE_A, CustomizedStateType.TYPE_B, 
CustomizedStateType.TYPE_C));
+    setAggregationEnabledTypes(Arrays.asList(CustomizedStateType.TYPE_A, 
CustomizedStateType.TYPE_B,
+        CustomizedStateType.TYPE_C));
+    validateAggregationSnapshot();
+
     update(INSTANCE_0, CustomizedStateType.TYPE_B, RESOURCE_0, PARTITION_01,
         CurrentStateValues.TYPE_B_2);
     update(INSTANCE_1, CustomizedStateType.TYPE_B, RESOURCE_1, PARTITION_10,

Reply via email to