Ver Fonte

ZOOKEEPER-1108. Various bugs in zoo_add_auth in C. (Dheeraj Agrawal via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1166970 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar há 13 anos atrás
pai
commit
a7bcf047f5

+ 2 - 0
CHANGES.txt

@@ -311,6 +311,8 @@ BUGFIXES:
   ZOOKEEPER-1160. test timeouts are too small (breed via phunt)
 
   ZOOKEEPER-731. Zookeeper#delete , #create - async versions miss a verb in the javadoc. (Thomas Koch via camille)
+
+  ZOOKEEPER-1108. Various bugs in zoo_add_auth in C. (Dheeraj Agrawal via mahadev)
   
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 

+ 1 - 0
src/c/src/zk_adaptor.h

@@ -41,6 +41,7 @@
 #define CONNECTING_STATE_DEF 1
 #define ASSOCIATING_STATE_DEF 2
 #define CONNECTED_STATE_DEF 3
+#define NOTCONNECTED_STATE_DEF 999
 
 /* zookeeper event type constants */
 #define CREATED_EVENT_DEF 1

+ 3 - 3
src/c/src/zookeeper.c

@@ -334,7 +334,7 @@ static void mark_active_auth(zhandle_t *zh) {
         return;
     }
     element = auth_h.auth;
-    while (element->next != NULL) {
+    while (element != NULL) {
         element->state = 1;
         element = element->next;
     }
@@ -784,7 +784,7 @@ zhandle_t *zookeeper_init(const char *host, watcher_fn watcher,
         return 0;
     }
     zh->fd = -1;
-    zh->state = 0;
+    zh->state = NOTCONNECTED_STATE_DEF;
     zh->context = context;
     zh->recv_timeout = recv_timeout;
     init_auth_info(&zh->auth_h);
@@ -1318,7 +1318,7 @@ static int send_auth_info(zhandle_t *zh) {
         zoo_unlock_auth(zh);
         return ZOK;
     }
-    while (auth->next != NULL) {
+    while (auth != NULL) {
         rc = send_info_packet(zh, auth);
         auth = auth->next;
     }

+ 10 - 1
src/c/tests/TestClient.cc

@@ -518,7 +518,6 @@ public:
                           (void*)ZOK);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         waitForVoidCompletion(3);
-
         CPPUNIT_ASSERT(count == 0);
 
         rc = zoo_create(zk, "/tauth1", "", 0, &ZOO_CREATOR_ALL_ACL, 0, 0, 0);
@@ -592,6 +591,16 @@ public:
         rc = zoo_set_acl(zk, "/", -1, &ZOO_OPEN_ACL_UNSAFE);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
 
+        //[ZOOKEEPER-1108], test that auth info is sent to server, if client is not
+        //connected to server when zoo_add_auth was called.
+        zhandle_t *zk_auth = zookeeper_init(hostPorts, NULL, 10000, 0, NULL, 0);
+        rc = zoo_add_auth(zk_auth, "digest", "pat:passwd", 10, voidCompletion, (void*)ZOK);
+        CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
+        sleep(2);
+        CPPUNIT_ASSERT(count == 1);
+        count  = 0;
+        CPPUNIT_ASSERT_EQUAL((int) ZOK, zookeeper_close(zk_auth));
+        
         // [ZOOKEEPER-800] zoo_add_auth should return ZINVALIDSTATE if
         // the connection is closed. 
         zhandle_t *zk2 = zookeeper_init(hostPorts, NULL, 10000, 0, NULL, 0);

+ 1 - 1
src/c/tests/TestZookeeperInit.cc

@@ -106,7 +106,7 @@ public:
         CPPUNIT_ASSERT(zh->hostname!=0);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs_count);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_HOST,string(zh->hostname));
-        CPPUNIT_ASSERT(zh->state == 0);
+        CPPUNIT_ASSERT(zh->state == NOTCONNECTED_STATE_DEF);
         CPPUNIT_ASSERT(zh->context == (void*)1);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_RECV_TIMEOUT,zh->recv_timeout);
         CPPUNIT_ASSERT(zh->watcher == watcher);

+ 1 - 1
src/java/main/org/apache/zookeeper/ClientCnxn.java

@@ -1204,7 +1204,7 @@ public class ClientCnxn {
 
     private int xid = 1;
 
-    private volatile States state;
+    private volatile States state = States.NOT_CONNECTED;
 
     synchronized private int getXid() {
         return xid++;

+ 1 - 1
src/java/main/org/apache/zookeeper/ZooKeeper.java

@@ -310,7 +310,7 @@ public class ZooKeeper {
 
     public enum States {
         CONNECTING, ASSOCIATING, CONNECTED, CONNECTEDREADONLY,
-        CLOSED, AUTH_FAILED;
+        CLOSED, AUTH_FAILED, NOT_CONNECTED;
 
         public boolean isAlive() {
             return this != CLOSED && this != AUTH_FAILED;