kaisun2000 commented on a change in pull request #924: WIP: fix
ZkHelixPropertyStore loses Zookeeper notification issue
URL: https://github.com/apache/helix/pull/924#discussion_r401178552
##########
File path:
helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
##########
@@ -88,6 +92,57 @@ public void afterClass() {
deleteCluster(getShortClassName());
}
+ @Test
+ public void testSessionExpirationWithSharedZkClient() throws Exception {
+ /*
+ This test is to make sure SharedZkClient would work with
+ HelixPropertyStore when session expiration happens. More specifically
+ HelixPropertyStore would register all the callbacks after session
+ expiration.
+ */
+ String subRoot = _root + "/" + "localCallback";
+ List<String> subscribedPaths = new ArrayList<>();
+ subscribedPaths.add(subRoot);
+
+ ZkSerializer serializer = new ZNRecordSerializer();
+ ZkHelixPropertyStore<ZNRecord> store =
+ new ZkHelixPropertyStore<>(ZK_ADDR, serializer, subRoot,
subscribedPaths);
+
+ TestListener listener = new TestListener();
+ store.subscribe("/", listener);
+
+ // test dataCreate callbacks
+ listener.reset();
+ setNodes(store, 'a', true);
+
+ // kill the session to make sure shared zkClient re-installs watcher
+ // Note, current shared ZkClient does not issue new session. Thus, we need
+ // kill _zkConnectionManager's session. Otherwise,
ZkTestHelper.expireSesson
+ // would not work.
+ SharedZkClient sharedClient = (SharedZkClient) store.getTestZkClient();
+ HelixZkClient testClient = sharedClient.getConnectionManager();
+ ZkTestHelper.expireSession(testClient);
+
+
+ // kill the session one more time to cover Shared ZkClient resetting flag
+ // indicating first time synconnect happened.
+ ZkTestHelper.expireSession(testClient);
+
+ listener.reset();
+ int expectDeleteNodes = 1 + firstLevelNr + firstLevelNr * secondLevelNr;
+ store.remove("/", 0);
+ // wait until all callbacks have been received
+ for (int i = 0; i < 10; i++) {
+ if (listener._deleteKeys.size() == expectDeleteNodes)
+ break;
+ Thread.sleep(500);
+ }
+
+ System.out.println("createKey#:" + listener._createKeys.size() + ",
changeKey#:"
+ + listener._changeKeys.size() + ", deleteKey#:" +
listener._deleteKeys.size());
Review comment:
Java has not way to access otherwise private members in the class. In this
case, we have to expire the session inside this class. This is a common problem
I did not see addressed in our code base. Unless you guys can identify another
pattern, I guess we have to leave it this way.
----------------------------------------------------------------
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]