pkuwm commented on a change in pull request #644: Add new interface
IZkStateListener to provide session aware handleNewSession for ZkHelixManager
URL: https://github.com/apache/helix/pull/644#discussion_r355298267
##########
File path:
helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
##########
@@ -91,29 +94,137 @@ void testGetStat() {
AssertJUnit.assertNotSame(stat, newStat);
}
- @Test()
- void testSessionExpire() throws Exception {
- IZkStateListener listener = new IZkStateListener() {
+ /*
+ * Tests subscribing state changes for helix's IZkStateListener.
+ */
+ @Test
+ public void testSubscribeStateChanges() {
+ int numListeners = _zkClient.numberOfListeners();
+ List<IZkStateListener> listeners = new ArrayList<>();
+
+ for (int i = 0; i < 3; i++) {
+ IZkStateListener listener = new IZkStateListener() {
+ @Override
+ public void handleStateChanged(KeeperState state) {
+ System.out.println("Handle new state: " + state);
+ }
- @Override
- public void handleStateChanged(KeeperState state) {
- System.out.println("In Old connection New state " + state);
- }
+ @Override
+ public void handleNewSession(final String sessionId) {
+ System.out.println("Handle new session: " + sessionId);
+ }
- @Override
- public void handleNewSession() {
- System.out.println("In Old connection New session");
- }
+ @Override
+ public void handleSessionEstablishmentError(Throwable error) {
+ System.out.println("Handle session establishment error: " + error);
+ }
+ };
- @Override
- public void handleSessionEstablishmentError(Throwable var1) {
- }
- };
+ _zkClient.subscribeStateChanges(listener);
+ Assert.assertEquals(_zkClient.numberOfListeners(), ++numListeners);
+ listeners.add(listener);
+ }
+
+ for (IZkStateListener listener : listeners) {
+ _zkClient.unsubscribeStateChanges(listener);
+ Assert.assertEquals(_zkClient.numberOfListeners(), --numListeners);
+ }
+ }
+
+ /*
+ * Tests session expiry for the helix's IZkStateListener.
+ */
+ @Test
+ void testSessionExpiry() throws Exception {
+ long lastSessionId = _zkClient.getSessionId();
+ for (int i = 0; i < 3; i++) {
Review comment:
I think 3 looks straightforward here as we just want to run the test a few
times to make sure the session ids are increasing. Will add comment to explain
it.
----------------------------------------------------------------
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]