pkuwm commented on a change in pull request #924: Fix ZkHelixPropertyStore
loses Zookeeper notification issue
URL: https://github.com/apache/helix/pull/924#discussion_r405969528
##########
File path:
helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheAsyncOpSingleThread.java
##########
@@ -37,6 +38,99 @@
import org.testng.annotations.Test;
public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
+ @Test
+ public void testSessionExpirationWithSharedZkClient() throws Exception {
+ int CURSTATECNT = 10;
+ String className = TestHelper.getTestClassName();
+ String methodName = TestHelper.getTestMethodName();
+ String clusterName = className + "_" + methodName;
+
+ // init external base data accessor
+ HelixZkClient sharedZkclient = SharedZkClientFactory.getInstance()
+ .buildZkClient(new HelixZkClient.ZkConnectionConfig(ZK_ADDR));
+ sharedZkclient.setZkSerializer(new ZNRecordSerializer());
+ ZkBaseDataAccessor<ZNRecord> sharedBaseAccessor = new
ZkBaseDataAccessor<>(sharedZkclient);
+
+ // init zkCacheBaseDataAccessor
+ String curStatePath =
PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901");
+ String extViewPath = PropertyPathBuilder.externalView(clusterName);
+
+ ZkBaseDataAccessor<ZNRecord> extBaseAccessor = new
ZkBaseDataAccessor<>(_gZkClient);
+ extBaseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
+
+ List<String> zkCacheInitPaths = Arrays.asList(curStatePath, extViewPath);
+ ZkCacheBaseDataAccessor<ZNRecord> accessor =
+ new ZkCacheBaseDataAccessor<>(sharedBaseAccessor, null, null,
zkCacheInitPaths);
+
+ boolean ret =
+ TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache,
_gZkClient, true);
+ Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
+
+ // create 10 current states using external base accessor
+ List<String> paths = new ArrayList<>();
+ List<ZNRecord> records = new ArrayList<>();
+ for (int i = 0; i < CURSTATECNT; i++) {
+ String path = PropertyPathBuilder.instanceCurrentState(clusterName,
"localhost_8901",
+ "session_0", "TestDB" + i);
+ ZNRecord record = new ZNRecord("TestDB" + i);
+
+ paths.add(path);
+ records.add(record);
+ }
+
+ boolean[] success = extBaseAccessor.createChildren(paths, records,
AccessOption.PERSISTENT);
+ for (int i = 0; i < CURSTATECNT; i++) {
+ Assert.assertTrue(success[i], "Should succeed in create: " +
paths.get(i));
+ }
+
+ TestHelper.verifyWithTimeout("verifyZkCache", 5000,
+ zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true );
+
+ // dup shared ZkClient
+ HelixZkClient dupZkclient = SharedZkClientFactory.getInstance()
+ .buildZkClient(new HelixZkClient.ZkConnectionConfig(ZK_ADDR));
+
+ // kill the session to make sure shared zkClient re-installs watcher
+ final long sessionId = dupZkclient.getSessionId();
+ ZkTestHelper.asyncExpireSession(dupZkclient);
+ ret = TestHelper.verify(()-> {
+ long curSessionId = dupZkclient.getSessionId();
+ if (curSessionId != sessionId && curSessionId != 0) {
+ return true;
+ }
+ return false;
Review comment:
It could be simplified to `return curSessionId != sessionId && curSessionId
!= 0`?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]