zhangmeng916 commented on a change in pull request #912: Add integration test 
to customized view aggregation
URL: https://github.com/apache/helix/pull/912#discussion_r398325974
 
 

 ##########
 File path: 
helix-core/src/test/java/org/apache/helix/integration/TestCustomizedViewAggregation.java
 ##########
 @@ -0,0 +1,404 @@
+package org.apache.helix.integration;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import com.google.common.collect.Maps;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.HelixManagerFactory;
+import org.apache.helix.InstanceType;
+import org.apache.helix.PropertyType;
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.customizedstate.CustomizedStateProvider;
+import org.apache.helix.customizedstate.CustomizedStateProviderFactory;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
+import org.apache.helix.model.CustomizedStateConfig;
+import org.apache.helix.model.CustomizedView;
+import org.apache.helix.spectator.RoutingTableProvider;
+import org.apache.helix.spectator.RoutingTableSnapshot;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+public class TestCustomizedViewAggregation extends ZkUnitTestBase {
+
+  private static CustomizedStateProvider _customizedStateProvider_participant0;
+  private static CustomizedStateProvider _customizedStateProvider_participant1;
+  private static RoutingTableProvider _routingTableProvider;
+  private static HelixManager _spectator;
+  private static HelixManager _manager;
+  // 1st key: customized state type, 2nd key: resource name, 3rd key: 
partition name, 4th key: instance name, value: state value
+  // This map contains all the customized state information that is enabled 
for aggregation in config, including those are not listened by routing table 
provider
+  private static Map<String, Map<String, Map<String, Map<String, String>>>> 
_localCustomizedView;
+  // The set contains customized state types that are listened by routing 
table provider
+  private static Set<String> _localVisibleCustomizedStateType;
+  private String INSTANCE_0;
+  private String INSTANCE_1;
+  private final String RESOURCE_A = "TestDB0";
+  private final String RESOURCE_B = "TestDB1";
+  private final String PARTITION_A1 = "TestDB0_0";
+  private final String PARTITION_A2 = "TestDB0_1";
+  private final String PARTITION_B1 = "TestDB1_0";
+  private final String PARTITION_B2 = "TestDB1_1";
+
+  // Customized state values used for test, StatusA1 - StatusA3 are values for 
Customized state TypeA, etc.
+  private enum CurrentStateValues {
+    StatusA1, StatusA2, StatusA3, StatusB1, StatusB2, StatusB3, StatusC1, 
StatusC2, StatusC3
+  }
+
+  private enum CustomizedStateType {
+    TYPE_A, TYPE_B, TYPE_C
+  }
+
+  @BeforeClass
+  public void beforeClass() throws Exception {
+    super.beforeClass();
+
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String clusterName = className + "_" + methodName;
+    int n = 2;
+
+    System.out.println("START " + clusterName + " at " + new 
Date(System.currentTimeMillis()));
+
+    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+        "localhost", // participant name prefix
+        "TestDB", // resource name prefix
+        2, // resources
+        2, // partitions per resource
+        n, // number of nodes
+        2, // replicas
+        "MasterSlave", true); // do rebalance
+
+    ClusterControllerManager controller =
+        new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+    controller.syncStart();
+
+    // start participants
+    MockParticipantManager[] participants = new MockParticipantManager[n];
+    for (int i = 0; i < n; i++) {
+      String instanceName = "localhost_" + (12918 + i);
+
+      participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, 
instanceName);
+      participants[i].syncStart();
+    }
+
+    INSTANCE_0 = participants[0].getInstanceName();
+    INSTANCE_1 = participants[1].getInstanceName();
+
+    _manager = HelixManagerFactory
+        .getZKHelixManager(clusterName, "admin", InstanceType.ADMINISTRATOR, 
ZK_ADDR);
+    _manager.connect();
+
+    _spectator = HelixManagerFactory
+        .getZKHelixManager(clusterName, "spectator", InstanceType.SPECTATOR, 
ZK_ADDR);
+    _spectator.connect();
+    HelixDataAccessor dataAccessor = _manager.getHelixDataAccessor();
+
+    // Initialize customized state provider
+    _customizedStateProvider_participant0 = 
CustomizedStateProviderFactory.getInstance()
+        .buildCustomizedStateProvider(_manager, 
participants[0].getInstanceName());
+    _customizedStateProvider_participant1 = 
CustomizedStateProviderFactory.getInstance()
+        .buildCustomizedStateProvider(_manager, 
participants[1].getInstanceName());
+
+    // Set up aggregation config
+    List<String> aggregationEnabledTypes = Arrays
+        .asList(CustomizedStateType.TYPE_A.name(), 
CustomizedStateType.TYPE_B.name(),
+            CustomizedStateType.TYPE_C.name());
+    CustomizedStateConfig.Builder customizedStateConfigBuilder =
+        new CustomizedStateConfig.Builder();
+    
customizedStateConfigBuilder.setAggregationEnabledTypes(aggregationEnabledTypes);
+    
dataAccessor.updateProperty(dataAccessor.keyBuilder().customizedStateConfig(),
+        customizedStateConfigBuilder.build());
+
+    _localCustomizedView = new HashMap<>();
+    _localVisibleCustomizedStateType = new HashSet<>();
+  }
+
+  @AfterClass
+  public void afterClass() {
+    _routingTableProvider.shutdown();
+    _manager.disconnect();
+    _spectator.disconnect();
+  }
+
+  /**
+   * Compare the customized state values between ZK and local record
 
 Review comment:
   customized state values -> customized view values. 
   State is the raw data input, and view is the aggregated output.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org

Reply via email to