hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r728812 [1/2] - in /hadoop/zookeeper/trunk: ./ src/c/include/ src/c/tests/ src/docs/src/documentation/content/xdocs/ src/java/main/org/apache/zookeeper/ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/au...
Date Mon, 22 Dec 2008 22:23:33 GMT
Author: mahadev
Date: Mon Dec 22 14:23:32 2008
New Revision: 728812

URL: http://svn.apache.org/viewvc?rev=728812&view=rev
Log:
ZOOKEEPER-246. review error code definition in both source and docs. (pat via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/c/include/zookeeper.h
    hadoop/zookeeper/trunk/src/c/tests/TestClient.cc
    hadoop/zookeeper/trunk/src/c/tests/TestOperations.cc
    hadoop/zookeeper/trunk/src/c/tests/TestWatchers.cc
    hadoop/zookeeper/trunk/src/c/tests/TestZookeeperClose.cc
    hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/KeeperException.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/HostAuthenticationProvider.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/DataTreeV1.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncOps.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Mon Dec 22 14:23:32 2008
@@ -84,6 +84,9 @@
 
    ZOOKEEPER-222.  print C client log message timestamp in human readable
 form. (pat via mahadev) 
+  
+   ZOOKEEPER-246. review error code definition in both source and docs. (pat
+via mahadev)
 
 Release 3.0.0 - 2008-10-21
 

Modified: hadoop/zookeeper/trunk/src/c/include/zookeeper.h
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/include/zookeeper.h?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/include/zookeeper.h (original)
+++ hadoop/zookeeper/trunk/src/c/include/zookeeper.h Mon Dec 22 14:23:32 2008
@@ -69,29 +69,43 @@
 
 /** zookeeper return constants **/
 
-#define ZOK                                    0
-#define ZSYSTEMERROR                          -1
-#define ZRUNTIMEINCONSISTENCY (ZSYSTEMERROR - 1)
-#define ZDATAINCONSISTENCY    (ZSYSTEMERROR - 2)
-#define ZCONNECTIONLOSS       (ZSYSTEMERROR - 3)
-#define ZMARSHALLINGERROR     (ZSYSTEMERROR - 4)
-#define ZUNIMPLEMENTED        (ZSYSTEMERROR - 5)
-#define ZOPERATIONTIMEOUT     (ZSYSTEMERROR - 6)
-#define ZBADARGUMENTS         (ZSYSTEMERROR - 7)
-#define ZINVALIDSTATE         (ZSYSTEMERROR - 8)
-#define ZAPIERROR                           -100
-#define ZNONODE                  (ZAPIERROR - 1)
-#define ZNOAUTH                  (ZAPIERROR - 2)
-#define ZBADVERSION              (ZAPIERROR - 3)
-#define ZNOCHILDRENFOREPHEMERALS (ZAPIERROR - 8)
-#define ZNODEEXISTS             (ZAPIERROR - 10)
-#define ZNOTEMPTY               (ZAPIERROR - 11)
-#define ZSESSIONEXPIRED         (ZAPIERROR - 12)
-#define ZINVALIDCALLBACK        (ZAPIERROR - 13)
-#define ZINVALIDACL             (ZAPIERROR - 14)
-#define ZAUTHFAILED             (ZAPIERROR - 15)
-#define ZCLOSING                (ZAPIERROR - 16)
-#define ZNOTHING                (ZAPIERROR - 17)
+enum ZOO_ERRORS {
+  ZOK = 0, /*!< Everything is OK */
+
+  /** System and server-side errors.
+   * This is never thrown by the server, it shouldn't be used other than
+   * to indicate a range. Specifically error codes greater than this
+   * value, but lesser than {@link #ZAPIERROR}, are system errors. */
+  ZSYSTEMERROR = -1,
+  ZRUNTIMEINCONSISTENCY = -2, /*!< A runtime inconsistency was found */
+  ZDATAINCONSISTENCY = -3, /*!< A data inconsistency was found */
+  ZCONNECTIONLOSS = -4, /*!< Connection to the server has been lost */
+  ZMARSHALLINGERROR = -5, /*!< Error while marshalling or unmarshalling data */
+  ZUNIMPLEMENTED = -6, /*!< Operation is unimplemented */
+  ZOPERATIONTIMEOUT = -7, /*!< Operation timeout */
+  ZBADARGUMENTS = -8, /*!< Invalid arguments */
+  ZINVALIDSTATE = -9, /*!< Invliad zhandle state */
+
+  /** API errors.
+   * This is never thrown by the server, it shouldn't be used other than
+   * to indicate a range. Specifically error codes greater than this
+   * value are API errors (while values less than this indicate a 
+   * {@link #ZSYSTEMERROR}).
+   */
+  ZAPIERROR = -100,
+  ZNONODE = -101, /*!< Node does not exist */
+  ZNOAUTH = -102, /*!< Not authenticated */
+  ZBADVERSION = -103, /*!< Version conflict */
+  ZNOCHILDRENFOREPHEMERALS = -108, /*!< Ephemeral nodes may not have children */
+  ZNODEEXISTS = -110, /*!< The node already exists */
+  ZNOTEMPTY = -111, /*!< The node has children */
+  ZSESSIONEXPIRED = -112, /*!< The session has been expired by the server */
+  ZINVALIDCALLBACK = -113, /*!< Invalid callback specified */
+  ZINVALIDACL = -114, /*!< Invalid ACL specified */
+  ZAUTHFAILED = -115, /*!< Client authentication failed */
+  ZCLOSING = -116, /*!< ZooKeeper is closing */
+  ZNOTHING = -117 /*!< (not error) no server responses to process */
+};
 
 #ifdef __cplusplus
 extern "C" {
@@ -101,6 +115,7 @@
 *  @name Debug levels
 */
 typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel;
+
 /**
  * @name ACL Consts
  */

Modified: hadoop/zookeeper/trunk/src/c/tests/TestClient.cc
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/tests/TestClient.cc?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/tests/TestClient.cc (original)
+++ hadoop/zookeeper/trunk/src/c/tests/TestClient.cc Mon Dec 22 14:23:32 2008
@@ -235,24 +235,24 @@
         for(int i = 0; i < 30; i++) {
             sprintf(path, "/%i", i);
             rc = zoo_create(zkWatchCreator, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
 
         for(int i = 0; i < 30; i++) {
             sprintf(path, "/%i", i);
             struct Stat stat;
             rc = zoo_exists(zkIdle, path, 1, &stat);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
 
         for(int i = 0; i < 30; i++) {
             sprintf(path, "/%i", i);
             usleep(500000);
             rc = zoo_delete(zkWatchCreator, path, -1);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
         struct Stat stat;
-        CPPUNIT_ASSERT_EQUAL(ZNONODE, zoo_exists(zkIdle, "/0", 0, &stat));
+        CPPUNIT_ASSERT_EQUAL((int)ZNONODE, zoo_exists(zkIdle, "/0", 0, &stat));
     }
 
     bool waitForEvent(zhandle_t *zh, watchctx_t *ctx, int seconds) {
@@ -299,7 +299,7 @@
         for(i = 0; i < COUNT; i++) {
             sprintf(path, "/%d", i);
             rc = zoo_awexists(zk, path, watcher, &lctx[i], statCompletion, (void*)ZNONODE);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
 
         yield(zk, 0);
@@ -307,7 +307,7 @@
         for(i = 0; i < COUNT/2; i++) {
             sprintf(path, "/%d", i);
             rc = zoo_acreate(zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, strdup(path));
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
 
         yield(zk, 3);
@@ -322,7 +322,7 @@
         for(i = COUNT/2 + 1; i < COUNT*10; i++) {
             sprintf(path, "/%d", i);
             rc = zoo_acreate(zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, strdup(path));
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
 
         yield(zk, 1);
@@ -353,33 +353,33 @@
 
         rc = zoo_create(zk, "/watchtest", "", 0, 
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
-        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_create(zk, "/watchtest/child", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, 0, 0);
-        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         if (isGlobal) {
             testName = "GlobalTest";
             rc = zoo_get_children(zk, "/watchtest", 1, &strings);
             deallocate_String_vector(&strings);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             blen = sizeof(buf);
             rc = zoo_get(zk, "/watchtest/child", 1, buf, &blen, &stat);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             rc = zoo_exists(zk, "/watchtest/child2", 1, &stat);
-            CPPUNIT_ASSERT_EQUAL(ZNONODE, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc);
         } else {
             testName = "LocalTest";
             rc = zoo_wget_children(zk, "/watchtest", watcher, ctxLocal,
                                  &strings);
             deallocate_String_vector(&strings);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             blen = sizeof(buf);
             rc = zoo_wget(zk, "/watchtest/child", watcher, ctxLocal,
                          buf, &blen, &stat);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             rc = zoo_wexists(zk, "/watchtest/child2", watcher, ctxLocal,
                             &stat);
-            CPPUNIT_ASSERT_EQUAL(ZNONODE, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc);
         }
         
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
@@ -392,18 +392,18 @@
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
 
         rc = zoo_set(zk, "/watchtest/child", "1", 1, -1, 0);
-        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         struct Stat stat1, stat2;
         rc = zoo_set(zk, "/watchtest/child", "1", 1, -1, &stat1);
-        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT(stat1.version >= 0);
         rc = zoo_set(zk, "/watchtest/child", "1", 1, stat1.version, &stat2);
-        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_set(zk, "/watchtest/child", "1", 1, stat2.version, 0);
-        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_create(zk, "/watchtest/child2", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
-        CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
 
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
         
@@ -434,25 +434,25 @@
             testName = "GlobalTest";
             rc = zoo_get_children(zk, "/watchtest", 1, &strings);
             deallocate_String_vector(&strings);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             blen = sizeof(buf);
             rc = zoo_get(zk, "/watchtest/child", 1, buf, &blen, &stat);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             rc = zoo_exists(zk, "/watchtest/child2", 1, &stat);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         } else {
             testName = "LocalTest";
             rc = zoo_wget_children(zk, "/watchtest", watcher, ctxLocal,
                                  &strings);
             deallocate_String_vector(&strings);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             blen = sizeof(buf);
             rc = zoo_wget(zk, "/watchtest/child", watcher, ctxLocal,
                          buf, &blen, &stat);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             rc = zoo_wexists(zk, "/watchtest/child2", watcher, ctxLocal,
                             &stat);
-            CPPUNIT_ASSERT_EQUAL(ZOK, rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
 
         zoo_delete(zk, "/watchtest/child2", -1);

Modified: hadoop/zookeeper/trunk/src/c/tests/TestOperations.cc
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/tests/TestOperations.cc?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/tests/TestOperations.cc (original)
+++ hadoop/zookeeper/trunk/src/c/tests/TestOperations.cc Mon Dec 22 14:23:32 2008
@@ -99,22 +99,22 @@
         AsyncGetOperationCompletion res1;
         zkServer.addOperationResponse(new ZooGetResponse("1",1));
         int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // second operation
         AsyncGetOperationCompletion res2;
         zkServer.addOperationResponse(new ZooGetResponse("2",1));
         rc=zoo_aget(zh,"/x/y/2",0,asyncCompletion,&res2);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // process the send queue
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         while((rc=zookeeper_process(zh,interest))==ZOK) printf("%d\n", rc);
 	printf("RC = %d", rc);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
 
-        CPPUNIT_ASSERT_EQUAL(ZOK,res1.rc_);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,res1.rc_);
         CPPUNIT_ASSERT_EQUAL(string("1"),res1.value_);
-        CPPUNIT_ASSERT_EQUAL(ZOK,res2.rc_);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,res2.rc_);
         CPPUNIT_ASSERT_EQUAL(string("2"),res2.value_);
     }
     // send two getData requests and disconnect while the second request is
@@ -139,25 +139,25 @@
         AsyncGetOperationCompletion res1;
         zkServer.addOperationResponse(new ZooGetResponse("1",1));
         int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // second operation
         AsyncGetOperationCompletion res2;
         zkServer.addOperationResponse(new ZooGetResponse("2",1));
         rc=zoo_aget(zh,"/x/y/2",0,asyncCompletion,&res2);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // process the send queue
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // simulate a disconnect
         zkServer.setConnectionLost();
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZCONNECTIONLOSS,rc);
-        CPPUNIT_ASSERT_EQUAL(ZOK,res1.rc_);
+        CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,res1.rc_);
         CPPUNIT_ASSERT_EQUAL(string("1"),res1.value_);
-        CPPUNIT_ASSERT_EQUAL(ZCONNECTIONLOSS,res2.rc_);
+        CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,res2.rc_);
         CPPUNIT_ASSERT_EQUAL(string(""),res2.value_);
     }
     // send two getData requests and simulate timeout while the both request
@@ -182,20 +182,20 @@
         AsyncGetOperationCompletion res1;
         zkServer.addOperationResponse(new ZooGetResponse("1",1));
         int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // second operation
         AsyncGetOperationCompletion res2;
         zkServer.addOperationResponse(new ZooGetResponse("2",1));
         rc=zoo_aget(zh,"/x/y/2",0,asyncCompletion,&res2);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // simulate timeout
         timeMock.tick(+10); // advance system time by 10 secs
         // the next call to zookeeper_interest should return ZOPERATIONTIMEOUT
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOPERATIONTIMEOUT,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOPERATIONTIMEOUT,rc);
         // make sure the completions have been called
-        CPPUNIT_ASSERT_EQUAL(ZOPERATIONTIMEOUT,res1.rc_);
-        CPPUNIT_ASSERT_EQUAL(ZOPERATIONTIMEOUT,res2.rc_);
+        CPPUNIT_ASSERT_EQUAL((int)ZOPERATIONTIMEOUT,res1.rc_);
+        CPPUNIT_ASSERT_EQUAL((int)ZOPERATIONTIMEOUT,res2.rc_);
     }
 
     class PingCountingServer: public ZookeeperServer{
@@ -231,24 +231,24 @@
         timeval tv;
         // Round 1.
         int rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // simulate waiting for the select() call to timeout; 
         // advance the system clock accordingly
         timeMock.tick(tv);  
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
         // verify no ping sent
         CPPUNIT_ASSERT(zkServer.pingCount_==0);
         
         // Round 2.
         // the client should have the idle threshold exceeded, by now
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // assume the socket is writable, so no idling here; move on to 
         // zookeeper_process immediately
         rc=zookeeper_process(zh,interest);
         // ZNOTHING means the client hasn't received a ping response yet
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
         // verify a ping is sent
         CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_);
         
@@ -257,11 +257,11 @@
         // that the client has updated its last_recv timestamp 
         zkServer.addRecvResponse(new PingResponse);
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // pseudo-sleep for a short while (10 ms)
         timeMock.millitick(10);
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // only one ping so far?
         CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_);
         CPPUNIT_ASSERT(timeMock==zh->last_recv);
@@ -288,7 +288,7 @@
         timeval tv;
         // Round 1.
         int rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // simulate waiting for the select() call to timeout; 
         // advance the system clock accordingly
         timeMock.tick(tv);
@@ -296,7 +296,7 @@
         // trigger a watch now
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/x/y/z"));
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // arrival of a watch sets the last_recv to the current time
         CPPUNIT_ASSERT(timeMock==zh->last_recv);
         // spend 1 millisecond by processing the watch
@@ -305,10 +305,10 @@
         // Round 2.
         // a ping is due; zookeeper_interest() must send it now
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // no delay here -- as if the socket is immediately writable
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
         // verify a ping is sent
         CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_);        
     }
@@ -341,29 +341,29 @@
         // send the queued up zoo_aget() request
         Mock_gettimeofday beginningOfTimes(now); // remember when we started
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // no delay -- the socket is writable
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc); // ZNOTHING -- no response yet
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc); // ZNOTHING -- no response yet
         
         // Round 2.
         // what's next?
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // no response from the server yet -- waiting in the select() call
         now.tick(tv);
         // a watch has arrived, thus preventing the connection from timing out 
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/x/y/z"));        
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc); // read the watch message
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc); // read the watch message
         CPPUNIT_ASSERT_EQUAL(0,zkServer.pingCount_); // not yet!
         
         //Round 3.
         // now is the time to send a ping; make sure it's actually sent
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
         // verify a ping is sent
         CPPUNIT_ASSERT_EQUAL(1,zkServer.pingCount_);
         // make sure only 1/3 of the timeout has passed
@@ -407,7 +407,7 @@
             return new TestConcurrentOpJob(svr_,zh_);
         }
         virtual void validate(const char* file, int line) const{
-            CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC("ZOK != rc",ZOK,rc_,file,line);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC("ZOK != rc",(int)ZOK,rc_,file,line);
         }
     };
     void testConcurrentOperations1()
@@ -454,7 +454,7 @@
             //TEST_TRACE(("Finished %d iterations",i));
         }
         virtual void validate(const char* file, int line) const{
-            CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC("ZOK != rc",ZOK,rc_,file,line);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC("ZOK != rc",(int)ZOK,rc_,file,line);
         }
         zhandle_t* zh_;
         int rc_;
@@ -514,7 +514,7 @@
             return new TestConcurrentOpWithDisconnectJob(svr_,zh_);
         }
         virtual void validate(const char* file, int line) const{
-            CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC("ZCONNECTIONLOSS != rc",ZCONNECTIONLOSS,rc_,file,line);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC("ZCONNECTIONLOSS != rc",(int)ZCONNECTIONLOSS,rc_,file,line);
         }
     };
 
@@ -570,10 +570,10 @@
         AsyncGetOperationCompletion res1;
         zkServer.addOperationResponse(new ZooGetResponse("1",1));
         int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&res1);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         CPPUNIT_ASSERT(ensureCondition(res1,1000)<1000);
-        CPPUNIT_ASSERT_EQUAL(ZOK,res1.rc_);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,res1.rc_);
         CPPUNIT_ASSERT_EQUAL(string("1"),res1.value_);        
     }
     class ChangeNodeWatcher: public WatcherAction{
@@ -625,7 +625,7 @@
         // prepare a response for the zoo_aexists() request
         zkServer.addOperationResponse(new ZooStatResponse);
         int rc=zoo_aexists(zh,"/x/y/z",1,asyncCompletion,&completion);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         CPPUNIT_ASSERT(ensureCondition(action.isNodeChangedTriggered(),1000)<1000);
         CPPUNIT_ASSERT_EQUAL(string("/x/y/z"),action.path_);                

Modified: hadoop/zookeeper/trunk/src/c/tests/TestWatchers.cc
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/tests/TestWatchers.cc?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/tests/TestWatchers.cc (original)
+++ hadoop/zookeeper/trunk/src/c/tests/TestWatchers.cc Mon Dec 22 14:23:32 2008
@@ -136,15 +136,15 @@
         timeval tv;
         // open the socket
         int rc=zookeeper_interest(zh,&fd,&interest,&tv);        
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);        
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);        
         CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh));
         // send the handshake packet to the server
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);        
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);        
         CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh));
         // receive the server handshake response
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // verify connected
         CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE,zoo_state(zh));
         CPPUNIT_ASSERT(watcher.connected_);
@@ -170,15 +170,15 @@
         AsyncCompletion ignored;
         zkServer.addOperationResponse(new ZooGetResponse("1",1));
         int rc=zoo_aget(zh,"/x/y/1",0,asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // this will process the response and activate the watcher
         rc=zookeeper_process(zh,ZOOKEEPER_READ);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         // now, disconnect
         zkServer.setConnectionLost();
         rc=zookeeper_process(zh,ZOOKEEPER_READ);
-        CPPUNIT_ASSERT_EQUAL(ZCONNECTIONLOSS,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc);
         // verify disconnected
         CPPUNIT_ASSERT(watcher.disconnected_);
         CPPUNIT_ASSERT_EQUAL(1,watcher.counter_);
@@ -205,15 +205,15 @@
         zkServer.addOperationResponse(new ZooStatResponse);
         int rc=zoo_awexists(zh,"/x/y/1",activeWatcher,&wobject,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // this will process the response and activate the watcher
         rc=zookeeper_process(zh,ZOOKEEPER_READ);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         // now, disconnect
         zkServer.setConnectionLost();
         rc=zookeeper_process(zh,ZOOKEEPER_READ);
-        CPPUNIT_ASSERT_EQUAL(ZCONNECTIONLOSS,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc);
 
         // verify the default watcher has been triggered
         CPPUNIT_ASSERT(defWatcher.disconnected_);
@@ -246,22 +246,22 @@
         AsyncCompletion ignored;
         zkServer.addOperationResponse(new ZooStatResponse);
         int rc=zoo_aexists(zh,"/a/b/c",1,asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         CountingDataWatcher wobject;
         zkServer.addOperationResponse(new ZooStatResponse);
         rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         // this will process the response and activate the watcher
         while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
 
         // disconnect now
         zkServer.setConnectionLost();
         rc=zookeeper_process(zh,ZOOKEEPER_READ);
-        CPPUNIT_ASSERT_EQUAL(ZCONNECTIONLOSS,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS,rc);
 
         // verify the default watcher has been triggered
         CPPUNIT_ASSERT(defWatcher.disconnected_);
@@ -294,24 +294,24 @@
         zkServer.addOperationResponse(new ZooStatResponse);
         int rc=zoo_awexists(zh,"/a/b/c",activeWatcher,&wobject1,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         CountingDataWatcher wobject2;
         zkServer.addOperationResponse(new ZooStatResponse);
         rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject2,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         // this will process the response and activate the watcher
         while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
 
         // we are all set now; let's trigger the watches
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/a/b/c"));
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHANGED_EVENT,"/x/y/z"));
         // make sure all watchers have been processed
         while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
         
         CPPUNIT_ASSERT_EQUAL(1,wobject1.counter_);
         CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_);        
@@ -339,7 +339,7 @@
         zkServer.addOperationResponse(new ZooStatResponse);
         int rc=zoo_awexists(zh,"/a",activeWatcher,&wobject1,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         typedef ZooGetChildrenResponse::StringVector ZooVector;
         zkServer.addOperationResponse(new ZooGetChildrenResponse(
@@ -348,17 +348,17 @@
         DeletionCountingDataWatcher wobject2;
         rc=zoo_awget_children(zh,"/a",activeWatcher,
                 &wobject2,asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         // this will process the response and activate the watcher
         while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
 
         // we are all set now; let's trigger the watches
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_DELETED_EVENT,"/a"));
         // make sure the watchers have been processed
         while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
 
         CPPUNIT_ASSERT_EQUAL(1,wobject1.counter_);
         CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_);        
@@ -385,7 +385,7 @@
         zkServer.addOperationResponse(new ZooStatResponse);
         int rc=zoo_awexists(zh,"/a",activeWatcher,&wobject1,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         typedef ZooGetChildrenResponse::StringVector ZooVector;
         zkServer.addOperationResponse(new ZooGetChildrenResponse(
@@ -394,17 +394,17 @@
         ChildEventCountingWatcher wobject2;
         rc=zoo_awget_children(zh,"/a",activeWatcher,
                 &wobject2,asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         // this will process the response and activate the watcher
         while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
 
         // we are all set now; let's trigger the watches
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHILD_EVENT,"/a"));
         // make sure the watchers have been processed
         while((rc=zookeeper_process(zh,ZOOKEEPER_READ))==ZOK);
-        CPPUNIT_ASSERT_EQUAL(ZNOTHING,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZNOTHING,rc);
 
         CPPUNIT_ASSERT_EQUAL(0,wobject1.counter_);
         CPPUNIT_ASSERT_EQUAL(1,wobject2.counter_);        
@@ -461,7 +461,7 @@
         // a successful server response will activate the watcher 
         zkServer.addOperationResponse(new ZooStatResponse);
         int rc=zoo_aexists(zh,"/x/y/z",1,asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         // now, initiate a disconnect
         zkServer.setConnectionLost();
@@ -504,7 +504,7 @@
         // set a path-specific watcher
         int rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // make sure the watcher gets activated before we continue
         CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000);
         
@@ -553,7 +553,7 @@
         zkServer.addOperationResponse(new ZooStatResponse);
         activationTracker.track(&defWatcher);
         int rc=zoo_aexists(zh,"/a/b/c",1,asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // make sure the watcher gets activated before we continue
         CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000);
 
@@ -564,7 +564,7 @@
         // set a path-specific watcher
         rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // make sure the watcher gets activated before we continue
         CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000);
         
@@ -615,7 +615,7 @@
         activationTracker.track(&wobject1);
         int rc=zoo_awexists(zh,"/a/b/c",activeWatcher,&wobject1,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // make sure the watcher gets activated before we continue
         CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000);
 
@@ -626,7 +626,7 @@
         // set a path-specific watcher
         rc=zoo_awexists(zh,"/x/y/z",activeWatcher,&wobject2,
                 asyncCompletion,&ignored);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // make sure the watcher gets activated before we continue
         CPPUNIT_ASSERT(ensureCondition(activationTracker.isWatcherActivated(),1000)<1000);
 
@@ -668,7 +668,7 @@
         Stat stat;
         // add a node watch
         int rc=zoo_wexists(zh,"/a",activeWatcher,&wobject1,&stat);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         typedef ZooGetChildrenResponse::StringVector ZooVector;
         zkServer.addOperationResponse(new ZooGetChildrenResponse(
@@ -678,7 +678,7 @@
         String_vector children;
         rc=zoo_wget_children(zh,"/a",activeWatcher,&wobject2,&children);
         deallocate_String_vector(&children);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         // we are all set now; let's trigger the watches
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_DELETED_EVENT,"/a"));
@@ -715,7 +715,7 @@
         Stat stat;
         // add a node watch
         int rc=zoo_wexists(zh,"/a",activeWatcher,&wobject1,&stat);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         typedef ZooGetChildrenResponse::StringVector ZooVector;
         zkServer.addOperationResponse(new ZooGetChildrenResponse(
@@ -725,7 +725,7 @@
         String_vector children;
         rc=zoo_wget_children(zh,"/a",activeWatcher,&wobject2,&children);
         deallocate_String_vector(&children);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
 
         // we are all set now; let's trigger the watches
         zkServer.addRecvResponse(new ZNodeEvent(ZOO_CHILD_EVENT,"/a"));

Modified: hadoop/zookeeper/trunk/src/c/tests/TestZookeeperClose.cc
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/tests/TestZookeeperClose.cc?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/tests/TestZookeeperClose.cc (original)
+++ hadoop/zookeeper/trunk/src/c/tests/TestZookeeperClose.cc Mon Dec 22 14:23:32 2008
@@ -83,7 +83,7 @@
         freeMock.disable(); // disable mock's fake free()- use libc's free() instead
         
         // verify that zookeeper_close has done its job
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // memory
         CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
         CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
@@ -109,7 +109,7 @@
         freeMock.disable(); // disable mock's fake free()- use libc's free() instead
 
         // verify that zookeeper_close has done its job
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // memory
         CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
         CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
@@ -133,18 +133,18 @@
         timeval tv;
         int rc=zookeeper_interest(zh,&fd,&interest,&tv);
         
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);        
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);        
         CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh));
         CPPUNIT_ASSERT_EQUAL(ZOOKEEPER_READ|ZOOKEEPER_WRITE,interest);
         
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);        
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);        
         CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh));
         
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         rc=zookeeper_process(zh,interest);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);        
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);        
         CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE,zoo_state(zh));
         // do not actually free the memory while in zookeeper_close()
         Mock_free_noop freeMock;
@@ -182,15 +182,15 @@
         timeval tv;
         // initiate connection
         int rc=zookeeper_interest(zh,&fd,&interest,&tv);        
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);        
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);        
         CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh));
         CPPUNIT_ASSERT_EQUAL(ZOOKEEPER_READ|ZOOKEEPER_WRITE,interest);
         rc=zookeeper_process(zh,interest);
         // make sure the handshake in progress 
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);        
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);        
         CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh));
         rc=zookeeper_interest(zh,&fd,&interest,&tv);
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         
         // do not actually free the memory while in zookeeper_close()
         Mock_free_noop freeMock;
@@ -230,7 +230,7 @@
         freeMock.disable();
         
         // verify that zookeeper_close has done its job
-        CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+        CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         // memory
         CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
         CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
@@ -264,7 +264,7 @@
             CPPUNIT_ASSERT(adaptor!=0);
             int rc=zookeeper_close(zh);
             zh=0;
-            CPPUNIT_ASSERT_EQUAL(ZOK,rc);
+            CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
         }
     }
     void testCloseConnected1()
@@ -293,7 +293,7 @@
             // we're done, disable mock's fake free(), use libc's free() instead
             freeMock.disable();
             
-            CPPUNIT_ASSERT_EQUAL(ZOK,rc);            
+            CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);            
             adaptor_threads* adaptor=(adaptor_threads*)lzh.adaptor_priv;
             // memory
             CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
@@ -358,7 +358,7 @@
             // we're done, disable mock's fake free(), use libc's free() instead
             freeMock.disable();
             
-            CPPUNIT_ASSERT_EQUAL(ZOK,closeAction.rc);          
+            CPPUNIT_ASSERT_EQUAL((int)ZOK,closeAction.rc);          
             adaptor_threads* adaptor=(adaptor_threads*)closeAction.lzh.adaptor_priv;
             // memory
             CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh));

Modified: hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml (original)
+++ hadoop/zookeeper/trunk/src/docs/src/documentation/content/xdocs/zookeeperProgrammers.xml Mon Dec 22 14:23:32 2008
@@ -1181,6 +1181,12 @@
       </listitem>
     </itemizedlist>
 
+    <section id="sc_errorsZk">
+      <title>Handling Errors</title>
+
+      <para>Both the Java and C client bindings may report errors. The Java client binding does so by throwing KeeperException, calling code() on the exception will return the specific error code. The C client binding returns an error code as defined in the enum ZOO_ERRORS. API callbacks indicate result code for both language bindings. See the API documentation (javadoc for Java, doxygen for C) for full details on the possible errors and their meaning.</para>
+    </section>
+    
     <section id="sc_connectingToZk">
       <title>Connecting to ZooKeeper</title>
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ClientCnxn.java Mon Dec 22 14:23:32 2008
@@ -458,13 +458,13 @@
         }
         switch(zooKeeper.state) {
         case AUTH_FAILED:
-            p.replyHeader.setErr(KeeperException.Code.AuthFailed);
+            p.replyHeader.setErr(KeeperException.Code.AUTHFAILED.intValue());
             break;
         case CLOSED:
-            p.replyHeader.setErr(KeeperException.Code.SessionExpired);
+            p.replyHeader.setErr(KeeperException.Code.SESSIONEXPIRED.intValue());
             break;
         default:
-            p.replyHeader.setErr(KeeperException.Code.ConnectionLoss);
+            p.replyHeader.setErr(KeeperException.Code.CONNECTIONLOSS.intValue());
         }
         finishPacket(p);
     }
@@ -566,7 +566,8 @@
              */
             try {
                 if (packet.header.getXid() != replyHdr.getXid()) {
-                    packet.replyHeader.setErr(KeeperException.Code.ConnectionLoss);
+                    packet.replyHeader.setErr(
+                            KeeperException.Code.CONNECTIONLOSS.intValue());
                     throw new IOException("Xid out of order. Got "
                             + replyHdr.getXid() + " expected "
                             + packet.header.getXid());

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/KeeperException.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/KeeperException.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/KeeperException.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/KeeperException.java Mon Dec 22 14:23:32 2008
@@ -18,196 +18,400 @@
 
 package org.apache.zookeeper;
 
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
 @SuppressWarnings("serial")
 public abstract class KeeperException extends Exception {
 
     /**
-     * All non-specific keeper exceptions should be constructed via this factory method
-     * in order to guarantee consistency in error codes and such.  If you know the error
-     * code, then you should construct the special purpose exception directly.  That will
-     * allow you to have the most specific possible declarations of what exceptions might
-     * actually be thrown.
-     * @param code  The error code.
-     * @param path  The zookeeper path being operated on.
-     * @return  The specialized exception, presumably to be thrown by the caller.
+     * All non-specific keeper exceptions should be constructed via
+     * this factory method in order to guarantee consistency in error
+     * codes and such.  If you know the error code, then you should
+     * construct the special purpose exception directly.  That will
+     * allow you to have the most specific possible declarations of
+     * what exceptions might actually be thrown.
+     *
+     * @param code The error code.
+     * @param path The ZooKeeper path being operated on.
+     * @return The specialized exception, presumably to be thrown by
+     *  the caller.
      */
-    public static KeeperException create(int code, String path) {
+    public static KeeperException create(Code code, String path) {
         KeeperException r = create(code);
         r.path = path;
         return r;
     }
 
     /**
-     * All non-specific keeper exceptions should be constructed via this factory method
-     * in order to guarantee consistency in error codes and such.  If you know the error
-     * code, then you should construct the special purpose exception directly.  That will
-     * allow you to have the most specific possible declarations of what exceptions might
-     * actually be thrown.
-     * @param code The error code of your new exception.  This will also determine the
-     * specific type of the exception that is returned.
-     * @return  The specialized exception, presumably to be thrown by the caller.
+     * @deprecated deprecated in 3.1.0, use {@link #create(Code, String)}
+     * instead
      */
+    @Deprecated
+    public static KeeperException create(int code, String path) {
+        KeeperException r = create(Code.get(code));
+        r.path = path;
+        return r;
+    }
+
+    /**
+     * @deprecated deprecated in 3.1.0, use {@link #create(Code)}
+     * instead
+     */
+    @Deprecated
     public static KeeperException create(int code) {
+        return create(Code.get(code));
+    }
+
+    /**
+     * All non-specific keeper exceptions should be constructed via
+     * this factory method in order to guarantee consistency in error
+     * codes and such.  If you know the error code, then you should
+     * construct the special purpose exception directly.  That will
+     * allow you to have the most specific possible declarations of
+     * what exceptions might actually be thrown.
+     *
+     * @param code The error code of your new exception.  This will
+     * also determine the specific type of the exception that is
+     * returned.
+     * @return The specialized exception, presumably to be thrown by
+     * the caller.
+     */
+    public static KeeperException create(Code code) {
         switch (code) {
-            case Code.SystemError:
+            case SYSTEMERROR:
                 return new SystemErrorException();
-            case Code.RuntimeInconsistency:
+            case RUNTIMEINCONSISTENCY:
                 return new RuntimeInconsistencyException();
-            case Code.DataInconsistency:
+            case DATAINCONSISTENCY:
                 return new DataInconsistencyException();
-            case Code.ConnectionLoss:
+            case CONNECTIONLOSS:
                 return new ConnectionLossException();
-            case Code.MarshallingError:
+            case MARSHALLINGERROR:
                 return new MarshallingErrorException();
-            case Code.Unimplemented:
+            case UNIMPLEMENTED:
                 return new UnimplementedException();
-            case Code.OperationTimeout:
+            case OPERATIONTIMEOUT:
                 return new OperationTimeoutException();
-            case Code.BadArguments:
+            case BADARGUMENTS:
                 return new BadArgumentsException();
-            case Code.APIError:
+            case APIERROR:
                 return new APIErrorException();
-            case Code.NoNode:
+            case NONODE:
                 return new NoNodeException();
-            case Code.NoAuth:
+            case NOAUTH:
                 return new NoAuthException();
-            case Code.BadVersion:
+            case BADVERSION:
                 return new BadVersionException();
-            case Code.NoChildrenForEphemerals:
+            case NOCHILDRENFOREPHEMERALS:
                 return new NoChildrenForEphemeralsException();
-            case Code.NodeExists:
+            case NODEEXISTS:
                 return new NodeExistsException();
-            case Code.InvalidACL:
+            case INVALIDACL:
                 return new InvalidACLException();
-            case Code.AuthFailed:
+            case AUTHFAILED:
                 return new AuthFailedException();
-            case Code.NotEmpty:
+            case NOTEMPTY:
                 return new NotEmptyException();
-            case Code.SessionExpired:
+            case SESSIONEXPIRED:
                 return new SessionExpiredException();
-            case Code.InvalidCallback:
+            case INVALIDCALLBACK:
                 return new InvalidCallbackException();
 
-            case 0:
+            case OK:
             default:
                 throw new IllegalArgumentException("Invalid exception code");
         }
     }
 
+    /**
+     * Set the code for this exception
+     * @param code error code
+     * @deprecated deprecated in 3.1.0, exceptions should be immutable, this
+     * method should not be used
+     */
+    @Deprecated
     public void setCode(int code) {
-        this.code = code;
+        this.code = Code.get(code);
     }
 
-    public interface Code {
-        int Ok = 0;
-
-        // System and server-side errors
-        int SystemError = -1;
-
-        int RuntimeInconsistency = SystemError - 1;
-
-        int DataInconsistency = SystemError - 2;
-
-        int ConnectionLoss = SystemError - 3;
-
-        int MarshallingError = SystemError - 4;
-
-        int Unimplemented = SystemError - 5;
-
-        int OperationTimeout = SystemError - 6;
-
-        int BadArguments = SystemError - 7;
-
-        // API errors
-        int APIError = -100; // Catch all, shouldn't be used other
-        // than range start
-
-        int NoNode = APIError - 1; // Node does not exist
-
-        int NoAuth = APIError - 2; // Current operation not permitted
-
-        int BadVersion = APIError - 3; // Version conflict
-
-        int NoChildrenForEphemerals = APIError - 8;
-
-        int NodeExists = APIError - 10;
-
-        int NotEmpty = APIError - 11;
-
-        int SessionExpired = APIError - 12;
-
-        int InvalidCallback = APIError - 13;
-
-        int InvalidACL = APIError - 14;
-
-        int AuthFailed = APIError - 15; // client authentication failed
-
+    public static enum Code {
+        /** Everything is OK */
+        OK (0),
+
+        /** System and server-side errors.
+         * This is never thrown by the server, it shouldn't be used other than
+         * to indicate a range. Specifically error codes greater than this
+         * value, but lesser than {@link #APIERROR}, are system errors.
+         */
+        SYSTEMERROR (-1),
+
+        /** A runtime inconsistency was found */
+        RUNTIMEINCONSISTENCY (-2),
+        /** A data inconsistency was found */
+        DATAINCONSISTENCY (-3),
+        /** Connection to the server has been lost */
+        CONNECTIONLOSS (-4),
+        /** Error while marshalling or unmarshalling data */
+        MARSHALLINGERROR (-5),
+        /** Operation is unimplemented */
+        UNIMPLEMENTED (-6),
+        /** Operation timeout */
+        OPERATIONTIMEOUT (-7),
+        /** Invalid arguments */
+        BADARGUMENTS (-8),
+
+        /** API errors.
+         * This is never thrown by the server, it shouldn't be used other than
+         * to indicate a range. Specifically error codes greater than this
+         * value are API errors (while values less than this indicate a 
+         * {@link #SYSTEMERROR}).
+         */
+        APIERROR (-100),
+
+        /** Node does not exist */
+        NONODE (-101),
+        /** Not authenticated */
+        NOAUTH (-102),
+        /** Version conflict */
+        BADVERSION (-103),
+        /** Ephemeral nodes may not have children */
+        NOCHILDRENFOREPHEMERALS (-108),
+        /** The node already exists */
+        NODEEXISTS (-110),
+        /** The node has children */
+        NOTEMPTY (-111),
+        /** The session has been expired by the server */
+        SESSIONEXPIRED (-112),
+        /** Invalid callback specified */
+        INVALIDCALLBACK (-113),
+        /** Invalid ACL specified */
+        INVALIDACL (-114),
+        /** Client authentication failed */
+        AUTHFAILED (-115);
+
+        private static final Map<Integer,Code> lookup
+            = new HashMap<Integer,Code>();
+
+        static {
+            for(Code c : EnumSet.allOf(Code.class))
+                lookup.put(c.code, c);
+        }
+
+        private final int code;
+        Code(int code) {
+            this.code = code;
+        }
+
+        /**
+         * Get the int value for a particular Code.
+         * @return error code as integer
+         */
+        public int intValue() { return code; }
+
+        /**
+         * Get the Code value for a particular integer error code
+         * @param code int error code
+         * @return Code value corresponding to specified int code, or null
+         */
+        public static Code get(int code) {
+            return lookup.get(code);
+        }
+
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #OK} instead
+         */
+        @Deprecated
+        public static final int Ok = OK.code;
+
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #SYSTEMERROR} instead
+         */
+        @Deprecated
+        public static final int SystemError = SYSTEMERROR.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #RUNTIMEINCONSISTENCY} instead
+         */
+        @Deprecated
+        public static final int RuntimeInconsistency = RUNTIMEINCONSISTENCY.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #DATAINCONSISTENCY}
+         * instead
+         */
+        @Deprecated
+        public static final int DataInconsistency = DATAINCONSISTENCY.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #CONNECTIONLOSS}
+         * instead
+         */
+        @Deprecated
+        public static final int ConnectionLoss = CONNECTIONLOSS.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #MARSHALLINGERROR}
+         * instead
+         */
+        @Deprecated
+        public static final int MarshallingError = MARSHALLINGERROR.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #UNIMPLEMENTED} instead
+         */
+        @Deprecated
+        public static final int Unimplemented = UNIMPLEMENTED.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #OPERATIONTIMEOUT}
+         * instead
+         */
+        @Deprecated
+        public static final int OperationTimeout = OPERATIONTIMEOUT.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #BADARGUMENTS} instead
+         */
+        @Deprecated
+        public static final int BadArguments = BADARGUMENTS.code;
+
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #APIERROR} instead
+         */
+        @Deprecated
+        public static final int APIError = APIERROR.code;
+
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #NONODE} instead
+         */
+        @Deprecated
+        public static final int NoNode = NONODE.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #NOAUTH} instead
+         */
+        @Deprecated
+        public static final int NoAuth = NOAUTH.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #BADVERSION} instead
+         */
+        @Deprecated
+        public static final int BadVersion = BADVERSION.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #NOCHILDRENFOREPHEMERALS}
+         * instead
+         */
+        @Deprecated
+        public static final int
+            NoChildrenForEphemerals = NOCHILDRENFOREPHEMERALS.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #NODEEXISTS} instead
+         */
+        @Deprecated
+        public static final int NodeExists = NODEEXISTS.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #NOTEMPTY} instead
+         */
+        @Deprecated
+        public static final int NotEmpty = NOTEMPTY.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #SESSIONEXPIRED} instead
+         */
+        @Deprecated
+        public static final int SessionExpired = SESSIONEXPIRED.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #INVALIDCALLBACK} instead
+         */
+        @Deprecated
+        public static final int InvalidCallback = INVALIDCALLBACK.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #INVALIDACL} instead
+         */
+        @Deprecated
+        public static final int InvalidACL = INVALIDACL.code;
+        /**
+         * @deprecated deprecated in 3.1.0, use {@link #AUTHFAILED} instead
+         */
+        @Deprecated
+        public static final int AuthFailed = AUTHFAILED.code;
     }
 
-    static String getCodeMessage(int code) {
+    static String getCodeMessage(Code code) {
         switch (code) {
-            case 0:
+            case OK:
                 return "ok";
-            case Code.SystemError:
+            case SYSTEMERROR:
                 return "SystemError";
-            case Code.RuntimeInconsistency:
+            case RUNTIMEINCONSISTENCY:
                 return "RuntimeInconsistency";
-            case Code.DataInconsistency:
+            case DATAINCONSISTENCY:
                 return "DataInconsistency";
-            case Code.ConnectionLoss:
+            case CONNECTIONLOSS:
                 return "ConnectionLoss";
-            case Code.MarshallingError:
+            case MARSHALLINGERROR:
                 return "MarshallingError";
-            case Code.Unimplemented:
+            case UNIMPLEMENTED:
                 return "Unimplemented";
-            case Code.OperationTimeout:
+            case OPERATIONTIMEOUT:
                 return "OperationTimeout";
-            case Code.BadArguments:
+            case BADARGUMENTS:
                 return "BadArguments";
-            case Code.APIError:
+            case APIERROR:
                 return "APIError";
-            case Code.NoNode:
+            case NONODE:
                 return "NoNode";
-            case Code.NoAuth:
+            case NOAUTH:
                 return "NoAuth";
-            case Code.BadVersion:
+            case BADVERSION:
                 return "BadVersion";
-            case Code.NoChildrenForEphemerals:
+            case NOCHILDRENFOREPHEMERALS:
                 return "NoChildrenForEphemerals";
-            case Code.NodeExists:
+            case NODEEXISTS:
                 return "NodeExists";
-            case Code.InvalidACL:
+            case INVALIDACL:
                 return "InvalidACL";
-            case Code.AuthFailed:
+            case AUTHFAILED:
                 return "AuthFailed";
-            case Code.NotEmpty:
+            case NOTEMPTY:
                 return "Directory not empty";
-            case Code.SessionExpired:
+            case SESSIONEXPIRED:
                 return "Session expired";
-            case Code.InvalidCallback:
+            case INVALIDCALLBACK:
                 return "Invalid callback";
             default:
                 return "Unknown error " + code;
         }
     }
 
-    private int code;
+    private Code code;
 
     private String path;
 
-    public KeeperException(int code) {
+    public KeeperException(Code code) {
         this.code = code;
     }
 
-    KeeperException(int code, String path) {
+    KeeperException(Code code, String path) {
         this.code = code;
         this.path = path;
     }
 
+    /**
+     * Read the error code for this exception
+     * @return the error code for this exception
+     * @deprecated deprecated in 3.1.0, use {@link #code()} instead
+     */
+    @Deprecated
     public int getCode() {
+        return code.code;
+    }
+
+    /**
+     * Read the error Code for this exception
+     * @return the error Code for this exception
+     */
+    public Code code() {
         return code;
     }
 
+    /**
+     * Read the path for this exception
+     * @return the path associated with this error, null if none
+     */
     public String getPath() {
         return path;
     }
@@ -220,117 +424,174 @@
         return "KeeperErrorCode = " + getCodeMessage(code) + " for " + path;
     }
 
+    /**
+     *  @see Code.APIERROR
+     */
     public static class APIErrorException extends KeeperException {
         public APIErrorException() {
-            super(Code.APIError);
+            super(Code.APIERROR);
         }
     }
 
+    /**
+     *  @see Code.AUTHFAILED
+     */
     public static class AuthFailedException extends KeeperException {
         public AuthFailedException() {
-            super(Code.AuthFailed);
+            super(Code.AUTHFAILED);
         }
     }
 
+    /**
+     *  @see Code.BADARGUMENTS
+     */
     public static class BadArgumentsException extends KeeperException {
         public BadArgumentsException() {
-            super(Code.BadArguments);
+            super(Code.BADARGUMENTS);
         }
     }
 
+    /**
+     * @see Code.BADVERSION
+     */
     public static class BadVersionException extends KeeperException {
         public BadVersionException() {
-            super(Code.BadVersion);
+            super(Code.BADVERSION);
         }
     }
 
+    /**
+     * @see Code.CONNECTIONLOSS
+     */
     public static class ConnectionLossException extends KeeperException {
         public ConnectionLossException() {
-            super(Code.ConnectionLoss);
+            super(Code.CONNECTIONLOSS);
         }
     }
 
+    /**
+     * @see Code.DATAINCONSISTENCY
+     */
     public static class DataInconsistencyException extends KeeperException {
         public DataInconsistencyException() {
-            super(Code.DataInconsistency);
+            super(Code.DATAINCONSISTENCY);
         }
     }
 
+    /**
+     * @see Code.INVALIDACL
+     */
     public static class InvalidACLException extends KeeperException {
         public InvalidACLException() {
-            super(Code.InvalidACL);
+            super(Code.INVALIDACL);
         }
     }
 
+    /**
+     * @see Code.INVALIDCALLBACK
+     */
     public static class InvalidCallbackException extends KeeperException {
         public InvalidCallbackException() {
-            super(Code.InvalidCallback);
+            super(Code.INVALIDCALLBACK);
         }
     }
 
+    /**
+     * @see Code.MARSHALLINGERROR
+     */
     public static class MarshallingErrorException extends KeeperException {
         public MarshallingErrorException() {
-            super(Code.MarshallingError);
+            super(Code.MARSHALLINGERROR);
         }
     }
 
+    /**
+     * @see Code.NOAUTH
+     */
     public static class NoAuthException extends KeeperException {
         public NoAuthException() {
-            super(Code.NoAuth);
+            super(Code.NOAUTH);
         }
     }
 
+    /**
+     * @see Code.NOCHILDRENFOREPHEMERALS
+     */
     public static class NoChildrenForEphemeralsException extends KeeperException {
         public NoChildrenForEphemeralsException() {
-            super(Code.NoChildrenForEphemerals);
+            super(Code.NOCHILDRENFOREPHEMERALS);
         }
     }
 
+    /**
+     * @see Code.NODEEXISTS
+     */
     public static class NodeExistsException extends KeeperException {
         public NodeExistsException() {
-            super(Code.NodeExists);
+            super(Code.NODEEXISTS);
         }
     }
 
+    /**
+     * @see Code.NONODE
+     */
     public static class NoNodeException extends KeeperException {
         public NoNodeException() {
-            super(Code.NoNode);
+            super(Code.NONODE);
         }
     }
 
+    /**
+     * @see Code.NOTEMPTY
+     */
     public static class NotEmptyException extends KeeperException {
         public NotEmptyException() {
-            super(Code.NotEmpty);
+            super(Code.NOTEMPTY);
         }
     }
 
+    /**
+     * @see Code.OPERATIONTIMEOUT
+     */
     public static class OperationTimeoutException extends KeeperException {
         public OperationTimeoutException() {
-            super(Code.OperationTimeout);
+            super(Code.OPERATIONTIMEOUT);
         }
     }
 
+    /**
+     * @see Code.RUNTIMEINCONSISTENCY
+     */
     public static class RuntimeInconsistencyException extends KeeperException {
         public RuntimeInconsistencyException() {
-            super(Code.RuntimeInconsistency);
+            super(Code.RUNTIMEINCONSISTENCY);
         }
     }
 
+    /**
+     * @see Code.SESSIONEXPIRED
+     */
     public static class SessionExpiredException extends KeeperException {
         public SessionExpiredException() {
-            super(Code.SessionExpired);
+            super(Code.SESSIONEXPIRED);
         }
     }
 
+    /**
+     * @see Code.SYSTEMERROR
+     */
     public static class SystemErrorException extends KeeperException {
         public SystemErrorException() {
-            super(Code.SystemError);
+            super(Code.SYSTEMERROR);
         }
     }
 
+    /**
+     * @see Code.UNIMPLEMENTED
+     */
     public static class UnimplementedException extends KeeperException {
         public UnimplementedException() {
-            super(Code.Unimplemented);
+            super(Code.UNIMPLEMENTED);
         }
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java Mon Dec 22 14:23:32 2008
@@ -278,7 +278,7 @@
         
         @Override
         protected boolean shouldAddWatch(int rc) {
-            return rc == 0 || rc == KeeperException.Code.NoNode;
+            return rc == 0 || rc == KeeperException.Code.NONODE.intValue();
         }
     }
 
@@ -496,7 +496,8 @@
         request.setAcl(acl);
         ReplyHeader r = cnxn.submitRequest(h, request, response, null);
         if (r.getErr() != 0) {
-            throw KeeperException.create(r.getErr(), path);
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()),
+                    path);
         }
         return response.getPath();
     }
@@ -557,7 +558,7 @@
         request.setVersion(version);
         ReplyHeader r = cnxn.submitRequest(h, request, null, null);
         if (r.getErr() != 0) {
-            throw KeeperException.create(r.getErr());
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()));
         }
     }
 
@@ -607,10 +608,10 @@
         }
         ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
         if (r.getErr() != 0) {
-            if (r.getErr() == KeeperException.Code.NoNode) {
+            if (r.getErr() == KeeperException.Code.NONODE.intValue()) {
                 return null;
             }
-            throw KeeperException.create(r.getErr());
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()));
         }
 
         return response.getStat().getCzxid() == -1 ? null : response.getStat();
@@ -705,7 +706,7 @@
         }
         ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
         if (r.getErr() != 0) {
-            throw KeeperException.create(r.getErr());
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()));
         }
         if (stat != null) {
             DataTree.copyStat(response.getStat(), stat);
@@ -805,7 +806,7 @@
         SetDataResponse response = new SetDataResponse();
         ReplyHeader r = cnxn.submitRequest(h, request, response, null);
         if (r.getErr() != 0) {
-            throw KeeperException.create(r.getErr());
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()));
         }
         return response.getStat();
     }
@@ -853,7 +854,7 @@
         GetACLResponse response = new GetACLResponse();
         ReplyHeader r = cnxn.submitRequest(h, request, response, null);
         if (r.getErr() != 0) {
-            throw KeeperException.create(r.getErr());
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()));
         }
         DataTree.copyStat(response.getStat(), stat);
         return response.getAcl();
@@ -909,7 +910,7 @@
         SetACLResponse response = new SetACLResponse();
         ReplyHeader r = cnxn.submitRequest(h, request, response, null);
         if (r.getErr() != 0) {
-            throw KeeperException.create(r.getErr());
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()));
         }
         return response.getStat();
     }
@@ -968,7 +969,7 @@
         }
         ReplyHeader r = cnxn.submitRequest(h, request, response, wcb);
         if (r.getErr() != 0) {
-            throw KeeperException.create(r.getErr());
+            throw KeeperException.create(KeeperException.Code.get(r.getErr()));
         }
         return response.getChildren();
     }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java Mon Dec 22 14:23:32 2008
@@ -558,7 +558,8 @@
         } catch (KeeperException e) {
             // These are expected errors since we take a lazy snapshot
             if (initialized
-                    || (e.getCode() != Code.NoNode && e.getCode() != Code.NodeExists)) {
+                    || (e.code() != Code.NONODE 
+                            && e.code() != Code.NODEEXISTS)) {
                 LOG.warn(debug);
                 LOG.error("FIXMSG",e);
             }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java Mon Dec 22 14:23:32 2008
@@ -125,11 +125,12 @@
             return;
         }
         zks.decInProcess();
-        int err = 0;
+        Code err = Code.OK;
         Record rsp = null;
         try {
             if (request.hdr != null && request.hdr.getType() == OpCode.error) {
-                throw KeeperException.create(((ErrorTxn) request.txn).getErr());
+                throw KeeperException.create(KeeperException.Code.get((
+                        (ErrorTxn) request.txn).getErr()));
             }
 
             if (LOG.isDebugEnabled()) {
@@ -145,21 +146,21 @@
                 return;
             case OpCode.create:
                 rsp = new CreateResponse(rc.path);
-                err = rc.err;
+                err = Code.get(rc.err);
                 break;
             case OpCode.delete:
-                err = rc.err;
+                err = Code.get(rc.err);
                 break;
             case OpCode.setData:
                 rsp = new SetDataResponse(rc.stat);
-                err = rc.err;
+                err = Code.get(rc.err);
                 break;
             case OpCode.setACL:
                 rsp = new SetACLResponse(rc.stat);
-                err = rc.err;
+                err = Code.get(rc.err);
                 break;
             case OpCode.closeSession:
-                err = rc.err;
+                err = Code.get(rc.err);
                 break;
             case OpCode.sync:
                 SyncRequest syncRequest = new SyncRequest();
@@ -235,7 +236,7 @@
                 break;
             }
         } catch (KeeperException e) {
-            err = e.getCode();
+            err = e.code();
         } catch (Exception e) {
             LOG.warn("****************************** " + request);
             StringBuffer sb = new StringBuffer();
@@ -246,9 +247,10 @@
             }
             LOG.warn(sb.toString());
             LOG.error("FIXMSG",e);
-            err = Code.MarshallingError;
+            err = Code.MARSHALLINGERROR;
         }
-        ReplyHeader hdr = new ReplyHeader(request.cxid, request.zxid, err);
+        ReplyHeader hdr =
+            new ReplyHeader(request.cxid, request.zxid, err.intValue());
         ServerStats.getInstance().updateLatency(request.createTime);
         try {
             request.cnxn.sendResponse(hdr, rsp, "response");

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java Mon Dec 22 14:23:32 2008
@@ -423,7 +423,8 @@
             String scheme = authPacket.getScheme();
             AuthenticationProvider ap = ProviderRegistry.getProvider(scheme);
             if (ap == null
-                    || ap.handleAuthentication(this, authPacket.getAuth()) != KeeperException.Code.Ok) {
+                    || (ap.handleAuthentication(this, authPacket.getAuth()) 
+                            != KeeperException.Code.OK)) {
                 if (ap == null)
                     LOG.error("No authentication provider for scheme: "
                             + scheme + " has " + ProviderRegistry.listProviders());
@@ -432,7 +433,7 @@
                             + scheme);
                 // send a response...
                 ReplyHeader rh = new ReplyHeader(h.getXid(), 0,
-                        KeeperException.Code.AuthFailed);
+                        KeeperException.Code.AUTHFAILED.intValue());
                 sendResponse(rh, null, null);
                 // ... and close connection
                 sendBuffer(NIOServerCnxn.closeConn);
@@ -441,7 +442,7 @@
                 LOG.debug("Authentication succeeded for scheme: "
                         + scheme);
                 ReplyHeader rh = new ReplyHeader(h.getXid(), 0,
-                        KeeperException.Code.Ok);
+                        KeeperException.Code.OK.intValue());
                 sendResponse(rh, null, null);
             }
             return;

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java Mon Dec 22 14:23:32 2008
@@ -358,7 +358,7 @@
         } catch (KeeperException e) {
             if (txnHeader != null) {
                 txnHeader.setType(OpCode.error);
-                txn = new ErrorTxn(e.getCode());
+                txn = new ErrorTxn(e.code().intValue());
             }
         } catch (Exception e) {
             LOG.error("*********************************" + request);
@@ -375,7 +375,7 @@
             LOG.error("Unexpected exception", e);
             if (txnHeader != null) {
                 txnHeader.setType(OpCode.error);
-                txn = new ErrorTxn(Code.MarshallingError);
+                txn = new ErrorTxn(Code.MARSHALLINGERROR.intValue());
             }
         }
         request.hdr = txnHeader;

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java Mon Dec 22 14:23:32 2008
@@ -18,6 +18,7 @@
 
 package org.apache.zookeeper.server.auth;
 
+import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.server.ServerCnxn;
 
 /**
@@ -45,7 +46,7 @@
      *                the authentication data received.
      * @return TODO
      */
-    int handleAuthentication(ServerCnxn cnxn, byte authData[]);
+    KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte authData[]);
 
     /**
      * This method is called to see if the given id matches the given id

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java Mon Dec 22 14:23:32 2008
@@ -23,7 +23,6 @@
 import java.security.NoSuchAlgorithmException;
 
 import org.apache.log4j.Logger;
-
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.server.ServerCnxn;
@@ -90,7 +89,9 @@
         return parts[0] + ":" + base64Encode(digest);
     }
 
-    public int handleAuthentication(ServerCnxn cnxn, byte[] authData) {
+    public KeeperException.Code 
+        handleAuthentication(ServerCnxn cnxn, byte[] authData)
+    {
         String id = new String(authData);
         try {
             String digest = generateDigest(id);
@@ -98,11 +99,11 @@
                 cnxn.getAuthInfo().add(new Id("super", ""));
             }
             cnxn.getAuthInfo().add(new Id(getScheme(), digest));
-            return KeeperException.Code.Ok;
+            return KeeperException.Code.OK;
         } catch (NoSuchAlgorithmException e) {
             LOG.error("Missing algorithm",e);
         }
-        return KeeperException.Code.AuthFailed;
+        return KeeperException.Code.AUTHFAILED;
     }
 
     public boolean isAuthenticated() {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/HostAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/HostAuthenticationProvider.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/HostAuthenticationProvider.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/HostAuthenticationProvider.java Mon Dec 22 14:23:32 2008
@@ -28,10 +28,12 @@
         return "host";
     }
 
-    public int handleAuthentication(ServerCnxn cnxn, byte[] authData) {
+    public KeeperException.Code
+        handleAuthentication(ServerCnxn cnxn, byte[] authData)
+    {
         String id = cnxn.getRemoteAddress().getAddress().getCanonicalHostName();
         cnxn.getAuthInfo().add(new Id(getScheme(), id));
-        return KeeperException.Code.Ok;
+        return KeeperException.Code.OK;
     }
 
     public boolean matches(String id, String aclExpr) {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java Mon Dec 22 14:23:32 2008
@@ -28,10 +28,12 @@
         return "ip";
     }
 
-    public int handleAuthentication(ServerCnxn cnxn, byte[] authData) {
+    public KeeperException.Code
+        handleAuthentication(ServerCnxn cnxn, byte[] authData)
+    {
         String id = cnxn.getRemoteAddress().getAddress().getHostAddress();
         cnxn.getAuthInfo().add(new Id(getScheme(), id));
-        return KeeperException.Code.Ok;
+        return KeeperException.Code.OK;
     }
 
     // This is a bit weird but we need to return the address and the number of

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/DataTreeV1.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/DataTreeV1.java?rev=728812&r1=728811&r2=728812&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/DataTreeV1.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/upgrade/DataTreeV1.java Mon Dec 22 14:23:32 2008
@@ -437,7 +437,8 @@
         } catch (KeeperException e) {
             // These are expected errors since we take a lazy snapshot
             if (initialized
-                    || (e.getCode() != Code.NoNode && e.getCode() != Code.NodeExists)) {
+                    || (e.code() != Code.NONODE 
+                            && e.code() != Code.NODEEXISTS)) {
                 LOG.warn(debug);
                 LOG.error("FIXMSG",e);
             }



Mime
View raw message