helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [helix] 03/05: Add unit test.
Date Thu, 21 Nov 2019 00:32:52 GMT
This is an automated email from the ASF dual-hosted git repository.

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

View the commit online:
https://github.com/apache/helix/commit/9935fe51d83ab29e880165c11458f460cbff1d73

commit 9935fe51d83ab29e880165c11458f460cbff1d73
Author: Huizhi Lu <ihuizhi.lu@gmail.com>
AuthorDate: Tue Nov 5 18:35:51 2019 -0800

    Add unit test.
---
 .../helix/common/caches/BasicClusterDataCache.java |  1 +
 .../helix/spectator/TestRoutingDataCache.java      | 43 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/helix-core/src/main/java/org/apache/helix/common/caches/BasicClusterDataCache.java
b/helix-core/src/main/java/org/apache/helix/common/caches/BasicClusterDataCache.java
index 1260a2b..3584b36 100644
--- a/helix-core/src/main/java/org/apache/helix/common/caches/BasicClusterDataCache.java
+++ b/helix-core/src/main/java/org/apache/helix/common/caches/BasicClusterDataCache.java
@@ -113,6 +113,7 @@ public class BasicClusterDataCache implements ControlContextProvider {
 
     if (_propertyDataChangedMap.get(HelixConstants.ChangeType.LIVE_INSTANCE)) {
       long start = System.currentTimeMillis();
+      System.out.println("reloading live instances");
       _propertyDataChangedMap.put(HelixConstants.ChangeType.LIVE_INSTANCE, false);
       _propertyDataChangedMap.put(HelixConstants.ChangeType.CURRENT_STATE, true);
       _liveInstancePropertyCache.refresh(accessor);
diff --git a/helix-core/src/test/java/org/apache/helix/spectator/TestRoutingDataCache.java
b/helix-core/src/test/java/org/apache/helix/spectator/TestRoutingDataCache.java
index 09bcac4..bf10bf4 100644
--- a/helix-core/src/test/java/org/apache/helix/spectator/TestRoutingDataCache.java
+++ b/helix-core/src/test/java/org/apache/helix/spectator/TestRoutingDataCache.java
@@ -19,6 +19,8 @@ package org.apache.helix.spectator;
  * under the License.
  */
 
+import java.util.Map;
+
 import org.apache.helix.HelixConstants;
 import org.apache.helix.PropertyType;
 import org.apache.helix.TestHelper;
@@ -26,6 +28,7 @@ import org.apache.helix.ZNRecord;
 import org.apache.helix.integration.common.ZkStandAloneCMTestBase;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.mock.MockZkHelixDataAccessor;
+import org.apache.helix.model.CurrentState;
 import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier;
 import org.apache.helix.tools.ClusterVerifiers.ZkHelixClusterVerifier;
 import org.testng.Assert;
@@ -122,4 +125,44 @@ public class TestRoutingDataCache extends ZkStandAloneCMTestBase {
     cache.refresh(accessor);
     Assert.assertEquals(accessor.getReadCount(PropertyType.EXTERNALVIEW), 1);
   }
+
+  @Test
+  public void testCurrentStatesSelectiveUpdate() {
+    String clusterName = "CLUSTER_" + TestHelper.getTestClassName();
+    MockZkHelixDataAccessor accessor =
+        new MockZkHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<>(_gZkClient));
+    RoutingDataCache cache = new RoutingDataCache(clusterName, PropertyType.CURRENTSTATES);
+
+    // Empty current states map before refreshing.
+    Assert.assertTrue(cache.getCurrentStatesMap().isEmpty());
+
+    // 1. Initial cache refresh.
+    cache.refresh(accessor);
+    Map<String, Map<String, Map<String, CurrentState>>> currentStatesV1
= cache.getCurrentStatesMap();
+
+    // Current states map is not empty and size equals to number of live instances.
+    Assert.assertFalse(currentStatesV1.isEmpty());
+    Assert.assertEquals(currentStatesV1.size(), _participants.length);
+
+    // 2. Without any change, refresh routing data cache.
+    cache.refresh(accessor);
+    // Because of no current states change, current states cache doesn't refresh.
+    Assert.assertEquals(cache.getCurrentStatesMap(), currentStatesV1);
+
+    // 3. Stop one participant to make live instance change and refresh routing data cache.
+    _participants[0].syncStop();
+    cache.notifyDataChange(HelixConstants.ChangeType.LIVE_INSTANCE);
+    cache.refresh(accessor);
+    Map<String, Map<String, Map<String, CurrentState>>> currentStatesV2
= cache.getCurrentStatesMap();
+
+    // Current states cache should refresh and change.
+    Assert.assertFalse(currentStatesV2.isEmpty());
+    Assert.assertEquals(currentStatesV2.size(), _participants.length - 1);
+    Assert.assertFalse(currentStatesV1.equals(currentStatesV2));
+
+    cache.refresh(accessor);
+
+    // No change.
+    Assert.assertEquals(cache.getCurrentStatesMap(), currentStatesV2);
+  }
 }


Mime
View raw message