Browse Source

ZOOKEEPER-800. zoo_add_auth returns ZOK if zookeeper handle is in ZOO_CLOSED_STATE (michi mutsuzaki via mahadev konar)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@1026159 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 14 năm trước cách đây
mục cha
commit
519a452644
3 tập tin đã thay đổi với 18 bổ sung0 xóa
  1. 3 0
      CHANGES.txt
  2. 6 0
      src/c/src/zookeeper.c
  3. 9 0
      src/c/tests/TestClient.cc

+ 3 - 0
CHANGES.txt

@@ -134,6 +134,9 @@ BUGFIXES:
   ZOOKEEPER-794. Callbacks are not invoked when the client is closed
   (Alexis Midon via phunt)
 
+  ZOOKEEPER-800. zoo_add_auth returns ZOK if zookeeper handle is in
+  ZOO_CLOSED_STATE (michi mutsuzaki via mahadev konar)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

+ 6 - 0
src/c/src/zookeeper.c

@@ -2934,6 +2934,12 @@ int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
     if (is_unrecoverable(zh))
         return ZINVALIDSTATE;
 
+    // [ZOOKEEPER-800] zoo_add_auth should return ZINVALIDSTATE if
+    // the connection is closed. 
+    if (zoo_state(zh) == 0) {
+        return ZINVALIDSTATE;
+    }
+
     if(cert!=NULL && certLen!=0){
         auth.buff=calloc(1,certLen);
         if(auth.buff==0) {

+ 9 - 0
src/c/tests/TestClient.cc

@@ -591,6 +591,15 @@ public:
 
         rc = zoo_set_acl(zk, "/", -1, &ZOO_OPEN_ACL_UNSAFE);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
+
+        // [ZOOKEEPER-800] zoo_add_auth should return ZINVALIDSTATE if
+        // the connection is closed. 
+        zhandle_t *zk2 = zookeeper_init(hostPorts, NULL, 10000, 0, NULL, 0);
+        sleep(1);
+        CPPUNIT_ASSERT_EQUAL((int) ZOK, zookeeper_close(zk2));
+        CPPUNIT_ASSERT_EQUAL(0, zoo_state(zk2)); // 0 ==> ZOO_CLOSED_STATE
+        rc = zoo_add_auth(zk2, "digest", "pat:passwd", 10, voidCompletion, (void*)ZOK);
+        CPPUNIT_ASSERT_EQUAL((int) ZINVALIDSTATE, rc);
     }
 
     void testGetChildren2() {