瀏覽代碼

ZOOKEEPER-586. c client does not compile under cygwin

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@924045 13f79535-47bb-0310-9956-ffa450edef68
Benjamin Reed 15 年之前
父節點
當前提交
fa66a48f63
共有 6 個文件被更改,包括 353 次插入229 次删除
  1. 2 0
      CHANGES.txt
  2. 188 123
      src/c/src/zookeeper.c
  3. 4 0
      src/c/tests/LibCSymTable.h
  4. 55 55
      src/c/tests/TestClient.cc
  5. 30 28
      src/c/tests/TestZookeeperInit.cc
  6. 74 23
      src/c/tests/zkServer.sh

+ 2 - 0
CHANGES.txt

@@ -288,6 +288,8 @@ BUGFIXES:
   ZOOKEEPER-121_4. SyncRequestProcessor is not closing log stream during
   ZOOKEEPER-121_4. SyncRequestProcessor is not closing log stream during
   shutdown (mahadev via breed)
   shutdown (mahadev via breed)
 
 
+  ZOOKEEPER-586. c client does not compile under cygwin (phunt, mahadev, breed via breed)
+
 IMPROVEMENTS:
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)
   "socket reuse" and failure to close client (phunt via mahadev)

File diff suppressed because it is too large
+ 188 - 123
src/c/src/zookeeper.c


+ 4 - 0
src/c/tests/LibCSymTable.h

@@ -35,7 +35,11 @@
 
 
 // TODO: move all these macros to config.h (generated by autoconf) 
 // TODO: move all these macros to config.h (generated by autoconf) 
 #ifdef __CYGWIN__
 #ifdef __CYGWIN__
+#if (CYGWIN_VERSION_DLL_MAJOR < 1007)
 #define RANDOM_RET_TYPE int
 #define RANDOM_RET_TYPE int
+#else
+#define RANDOM_RET_TYPE long int
+#endif
 #define GETTIMEOFDAY_ARG2_TYPE void*
 #define GETTIMEOFDAY_ARG2_TYPE void*
 #else
 #else
 #define RANDOM_RET_TYPE long int
 #define RANDOM_RET_TYPE long int

+ 55 - 55
src/c/tests/TestClient.cc

@@ -67,7 +67,7 @@ static int Stat_eq(struct Stat* a, struct Stat* b)
         int events;
         int events;
         struct timeval tv;
         struct timeval tv;
         int rc;
         int rc;
-        time_t expires = time(0) + seconds; 
+        time_t expires = time(0) + seconds;
         time_t timeLeft = seconds;
         time_t timeLeft = seconds;
         fd_set rfds, wfds, efds;
         fd_set rfds, wfds, efds;
         FD_ZERO(&rfds);
         FD_ZERO(&rfds);
@@ -172,7 +172,7 @@ public:
         }
         }
         return !connected;
         return !connected;
     }
     }
-} watchctx_t; 
+} watchctx_t;
 
 
 class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture
 class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture
 {
 {
@@ -252,7 +252,7 @@ public:
     {
     {
         zoo_set_log_stream(logfile);
         zoo_set_log_stream(logfile);
     }
     }
-    
+
 
 
     void startServer() {
     void startServer() {
         char cmd[1024];
         char cmd[1024];
@@ -269,7 +269,7 @@ public:
     void tearDown()
     void tearDown()
     {
     {
     }
     }
-    
+
     void testPing()
     void testPing()
     {
     {
         watchctx_t ctxIdle;
         watchctx_t ctxIdle;
@@ -317,11 +317,11 @@ public:
     }
     }
 
 
 #define COUNT 100
 #define COUNT 100
-    
+
     static zhandle_t *async_zk;
     static zhandle_t *async_zk;
     static volatile int count;
     static volatile int count;
     static const char* hp_chroot;
     static const char* hp_chroot;
-    
+
     static void statCompletion(int rc, const struct Stat *stat, const void *data) {
     static void statCompletion(int rc, const struct Stat *stat, const void *data) {
         int tmp = (int) (long) data;
         int tmp = (int) (long) data;
         CPPUNIT_ASSERT_EQUAL(tmp, rc);
         CPPUNIT_ASSERT_EQUAL(tmp, rc);
@@ -329,7 +329,7 @@ public:
 
 
     static void stringCompletion(int rc, const char *value, const void *data) {
     static void stringCompletion(int rc, const char *value, const void *data) {
         char *path = (char*)data;
         char *path = (char*)data;
-        
+
         if (rc == ZCONNECTIONLOSS && path) {
         if (rc == ZCONNECTIONLOSS && path) {
             // Try again
             // Try again
             rc = zoo_acreate(async_zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, 0);
             rc = zoo_acreate(async_zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, 0);
@@ -340,12 +340,12 @@ public:
             free(path);
             free(path);
         }
         }
     }
     }
-    
+
     static void create_completion_fn(int rc, const char* value, const void *data) {
     static void create_completion_fn(int rc, const char* value, const void *data) {
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         count++;
         count++;
     }
     }
-    
+
     static void waitForCreateCompletion(int seconds) {
     static void waitForCreateCompletion(int seconds) {
         time_t expires = time(0) + seconds;
         time_t expires = time(0) + seconds;
         while(count == 0 && time(0) < expires) {
         while(count == 0 && time(0) < expires) {
@@ -361,7 +361,7 @@ public:
         CPPUNIT_ASSERT(strcmp(client_path, path) == 0);
         CPPUNIT_ASSERT(strcmp(client_path, path) == 0);
         count ++;
         count ++;
     }
     }
-    
+
     static void waitForChrootWatch(int seconds) {
     static void waitForChrootWatch(int seconds) {
         time_t expires = time(0) + seconds;
         time_t expires = time(0) + seconds;
         while (count == 0 && time(0) < expires) {
         while (count == 0 && time(0) < expires) {
@@ -377,34 +377,34 @@ public:
         }
         }
         count--;
         count--;
     }
     }
-    
+
     static void voidCompletion(int rc, const void *data) {
     static void voidCompletion(int rc, const void *data) {
         int tmp = (int) (long) data;
         int tmp = (int) (long) data;
         CPPUNIT_ASSERT_EQUAL(tmp, rc);
         CPPUNIT_ASSERT_EQUAL(tmp, rc);
         count++;
         count++;
     }
     }
-    
+
     static void verifyCreateFails(const char *path, zhandle_t *zk) {
     static void verifyCreateFails(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
       CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
     }
     }
-    
+
     static void verifyCreateOk(const char *path, zhandle_t *zk) {
     static void verifyCreateOk(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
       CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
     }
     }
-    
+
     static void verifyCreateFailsSeq(const char *path, zhandle_t *zk) {
     static void verifyCreateFailsSeq(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
       CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
     }
     }
-    
+
     static void verifyCreateOkSeq(const char *path, zhandle_t *zk) {
     static void verifyCreateOkSeq(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
       CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
     }
     }
-    
-            
+
+
     /**
     /**
        returns false if the vectors dont match
        returns false if the vectors dont match
     **/
     **/
@@ -434,7 +434,7 @@ public:
         struct Stat stat;
         struct Stat stat;
         watchctx_t ctx;
         watchctx_t ctx;
         zhandle_t *zk = createClient(&ctx);
         zhandle_t *zk = createClient(&ctx);
-        rc = zoo_create(zk, "/acl", "", 0, 
+        rc = zoo_create(zk, "/acl", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_get_acl(zk, "/acl", &aclvec, &stat  );
         rc = zoo_get_acl(zk, "/acl", &aclvec, &stat  );
@@ -459,18 +459,18 @@ public:
         struct ACL acl_val;
         struct ACL acl_val;
         rc = zoo_add_auth(0, "", 0, 0, voidCompletion, (void*)-1);
         rc = zoo_add_auth(0, "", 0, 0, voidCompletion, (void*)-1);
         CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
-        
+
         rc = zoo_add_auth(zk, 0, 0, 0, voidCompletion, (void*)-1);
         rc = zoo_add_auth(zk, 0, 0, 0, voidCompletion, (void*)-1);
         CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
-        
+
         // auth as pat, create /tauth1, close session
         // auth as pat, create /tauth1, close session
         rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
         rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
                           (void*)ZOK);
                           (void*)ZOK);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         waitForVoidCompletion(3);
         waitForVoidCompletion(3);
-                
+
         CPPUNIT_ASSERT(count == 0);
         CPPUNIT_ASSERT(count == 0);
-        
+
         rc = zoo_create(zk, "/tauth1", "", 0, &ZOO_CREATOR_ALL_ACL, 0, 0, 0);
         rc = zoo_create(zk, "/tauth1", "", 0, &ZOO_CREATOR_ALL_ACL, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
 
 
@@ -496,7 +496,7 @@ public:
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         waitForVoidCompletion(3);
         waitForVoidCompletion(3);
         CPPUNIT_ASSERT(count == 0);
         CPPUNIT_ASSERT(count == 0);
-                
+
         char buf[1024];
         char buf[1024];
         int blen = sizeof(buf);
         int blen = sizeof(buf);
         struct Stat stat;
         struct Stat stat;
@@ -505,7 +505,7 @@ public:
         // add auth pat w/correct pass verify success
         // add auth pat w/correct pass verify success
         rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
         rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
                           (void*)ZOK);
                           (void*)ZOK);
-        
+
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
         rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
@@ -520,7 +520,7 @@ public:
         //make the server forget the auths
         //make the server forget the auths
         waitForVoidCompletion(3);
         waitForVoidCompletion(3);
         CPPUNIT_ASSERT(count == 0);
         CPPUNIT_ASSERT(count == 0);
-     
+
         stopServer();
         stopServer();
         CPPUNIT_ASSERT(ctx3.waitForDisconnected(zk));
         CPPUNIT_ASSERT(ctx3.waitForDisconnected(zk));
         startServer();
         startServer();
@@ -532,7 +532,7 @@ public:
         rc = zoo_get_acl(zk, "/", &nodeAcl, &stat);
         rc = zoo_get_acl(zk, "/", &nodeAcl, &stat);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         // check if the acl has all the perms
         // check if the acl has all the perms
-        CPPUNIT_ASSERT_EQUAL((int)1, nodeAcl.count);
+        CPPUNIT_ASSERT_EQUAL((int)1, (int)nodeAcl.count);
         acl_val = *(nodeAcl.data);
         acl_val = *(nodeAcl.data);
         CPPUNIT_ASSERT_EQUAL((int) acl_val.perms, ZOO_PERM_ALL);
         CPPUNIT_ASSERT_EQUAL((int) acl_val.perms, ZOO_PERM_ALL);
         // verify on root node
         // verify on root node
@@ -591,7 +591,7 @@ public:
         zhandle_t *zk = createClient(&ctx);
         zhandle_t *zk = createClient(&ctx);
         CPPUNIT_ASSERT(zk);
         CPPUNIT_ASSERT(zk);
         int rc = 0;
         int rc = 0;
-        rc = zoo_create(zk, "/mahadev", NULL, -1, 
+        rc = zoo_create(zk, "/mahadev", NULL, -1,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         char buffer[512];
         char buffer[512];
@@ -615,32 +615,32 @@ public:
         int rc = 0;
         int rc = 0;
 
 
         memset(pathbuf, 'X', 20);
         memset(pathbuf, 'X', 20);
-        rc = zoo_create(zk, "/testpathpath0", "", 0, 
+        rc = zoo_create(zk, "/testpathpath0", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 0);
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL('X', pathbuf[0]);
         CPPUNIT_ASSERT_EQUAL('X', pathbuf[0]);
 
 
-        rc = zoo_create(zk, "/testpathpath1", "", 0, 
+        rc = zoo_create(zk, "/testpathpath1", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 1);
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 1);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strlen(pathbuf) == 0);
         CPPUNIT_ASSERT(strlen(pathbuf) == 0);
 
 
-        rc = zoo_create(zk, "/testpathpath2", "", 0, 
+        rc = zoo_create(zk, "/testpathpath2", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 2);
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 2);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/") == 0);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/") == 0);
 
 
-        rc = zoo_create(zk, "/testpathpath3", "", 0, 
+        rc = zoo_create(zk, "/testpathpath3", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 3);
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 3);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/t") == 0);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/t") == 0);
 
 
-        rc = zoo_create(zk, "/testpathpath7", "", 0, 
+        rc = zoo_create(zk, "/testpathpath7", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 15);
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 15);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath7") == 0);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath7") == 0);
 
 
-        rc = zoo_create(zk, "/testpathpath8", "", 0, 
+        rc = zoo_create(zk, "/testpathpath8", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 16);
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 16);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath8") == 0);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath8") == 0);
@@ -696,10 +696,10 @@ public:
         verifyCreateOk("/f/.f/f", zk);
         verifyCreateOk("/f/.f/f", zk);
         verifyCreateOk("/f/f./f", zk);
         verifyCreateOk("/f/f./f", zk);
     }
     }
-    
+
     void testChroot() {
     void testChroot() {
-        // the c client async callbacks do 
-        // not callback with the path, so 
+        // the c client async callbacks do
+        // not callback with the path, so
         // we dont need to test taht for now
         // we dont need to test taht for now
         // we should fix that though soon!
         // we should fix that though soon!
         watchctx_t ctx, ctx_ch;
         watchctx_t ctx, ctx_ch;
@@ -708,7 +708,7 @@ public:
         int rc, len;
         int rc, len;
         struct Stat stat;
         struct Stat stat;
         const char* data = "garbage";
         const char* data = "garbage";
-        const char* retStr = "/chroot"; 
+        const char* retStr = "/chroot";
         const char* root= "/";
         const char* root= "/";
         zk_ch = createchClient(&ctx_ch, "127.0.0.1:22181/testch1/mahadev");
         zk_ch = createchClient(&ctx_ch, "127.0.0.1:22181/testch1/mahadev");
         CPPUNIT_ASSERT(zk_ch != NULL);
         CPPUNIT_ASSERT(zk_ch != NULL);
@@ -723,9 +723,9 @@ public:
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         //check if the data is the same
         //check if the data is the same
         CPPUNIT_ASSERT(strncmp(buf, data, 7) == 0);
         CPPUNIT_ASSERT(strncmp(buf, data, 7) == 0);
-        //check for watches 
+        //check for watches
         rc = zoo_wexists(zk_ch, "/chroot", watcher_chroot_fn, (void *) retStr, &stat);
         rc = zoo_wexists(zk_ch, "/chroot", watcher_chroot_fn, (void *) retStr, &stat);
-        //now check if we can do create/delete/get/sets/acls/getChildren and others 
+        //now check if we can do create/delete/get/sets/acls/getChildren and others
         //check create
         //check create
         rc = zoo_create(zk_ch, "/chroot", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0,0);
         rc = zoo_create(zk_ch, "/chroot", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0,0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
@@ -735,7 +735,7 @@ public:
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
         rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
-        
+
         rc = zoo_delete(zk_ch, "/chroot/child", -1);
         rc = zoo_delete(zk_ch, "/chroot/child", -1);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
         rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
@@ -751,15 +751,15 @@ public:
         struct String_vector children;
         struct String_vector children;
         rc = zoo_get_children(zk_ch, "/", 0, &children);
         rc = zoo_get_children(zk_ch, "/", 0, &children);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
-        CPPUNIT_ASSERT_EQUAL((int)1, children.count);
+        CPPUNIT_ASSERT_EQUAL((int)1, (int)children.count);
         //check if te child if chroot
         //check if te child if chroot
         CPPUNIT_ASSERT(strcmp((retStr+1), children.data[0]) == 0);
         CPPUNIT_ASSERT(strcmp((retStr+1), children.data[0]) == 0);
         // check for get/set acl
         // check for get/set acl
         struct ACL_vector acl;
         struct ACL_vector acl;
         rc = zoo_get_acl(zk_ch, "/", &acl, &stat);
         rc = zoo_get_acl(zk_ch, "/", &acl, &stat);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
-        CPPUNIT_ASSERT_EQUAL((int)1, acl.count);
-        CPPUNIT_ASSERT_EQUAL(ZOO_PERM_ALL, acl.data->perms);
+        CPPUNIT_ASSERT_EQUAL((int)1, (int)acl.count);
+        CPPUNIT_ASSERT_EQUAL((int)ZOO_PERM_ALL, (int)acl.data->perms);
         // set acl
         // set acl
         rc = zoo_set_acl(zk_ch, "/chroot", -1,  &ZOO_READ_ACL_UNSAFE);
         rc = zoo_set_acl(zk_ch, "/chroot", -1,  &ZOO_READ_ACL_UNSAFE);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
@@ -769,14 +769,14 @@ public:
         //add wget children test
         //add wget children test
         rc = zoo_wget_children(zk_ch, "/", watcher_chroot_fn, (char*) root, &children);
         rc = zoo_wget_children(zk_ch, "/", watcher_chroot_fn, (char*) root, &children);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
-        
+
         //now create a node
         //now create a node
         rc = zoo_create(zk_ch, "/child2", "",0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         rc = zoo_create(zk_ch, "/child2", "",0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         waitForChrootWatch(3);
         waitForChrootWatch(3);
         CPPUNIT_ASSERT(count == 0);
         CPPUNIT_ASSERT(count == 0);
         //check for one async call just to make sure
         //check for one async call just to make sure
-        rc = zoo_acreate(zk_ch, "/child3", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 
+        rc = zoo_acreate(zk_ch, "/child3", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0,
                          create_completion_fn, 0);
                          create_completion_fn, 0);
         waitForCreateCompletion(3);
         waitForCreateCompletion(3);
         CPPUNIT_ASSERT(count == 0);
         CPPUNIT_ASSERT(count == 0);
@@ -821,7 +821,7 @@ public:
             rc = zoo_acreate(zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, strdup(path));
             rc = zoo_acreate(zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, strdup(path));
             CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
             CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
         }
-        
+
         yield(zk, 1);
         yield(zk, 1);
         stopServer();
         stopServer();
         CPPUNIT_ASSERT(ctx.waitForDisconnected(zk));
         CPPUNIT_ASSERT(ctx.waitForDisconnected(zk));
@@ -837,7 +837,7 @@ public:
         }
         }
     }
     }
 
 
-    void testWatcherAutoReset(zhandle_t *zk, watchctx_t *ctxGlobal, 
+    void testWatcherAutoReset(zhandle_t *zk, watchctx_t *ctxGlobal,
                               watchctx_t *ctxLocal)
                               watchctx_t *ctxLocal)
     {
     {
         bool isGlobal = (ctxGlobal == ctxLocal);
         bool isGlobal = (ctxGlobal == ctxLocal);
@@ -848,7 +848,7 @@ public:
         struct String_vector strings;
         struct String_vector strings;
         const char *testName;
         const char *testName;
 
 
-        rc = zoo_create(zk, "/watchtest", "", 0, 
+        rc = zoo_create(zk, "/watchtest", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_create(zk, "/watchtest/child", "", 0,
         rc = zoo_create(zk, "/watchtest/child", "", 0,
@@ -879,7 +879,7 @@ public:
                             &stat);
                             &stat);
             CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc);
             CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc);
         }
         }
-        
+
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
 
 
         stopServer();
         stopServer();
@@ -904,7 +904,7 @@ public:
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
 
 
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
-        
+
         evt_t evt = ctxLocal->getEvent();
         evt_t evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHANGED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHANGED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
@@ -924,7 +924,7 @@ public:
         sleep(5);
         sleep(5);
 
 
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
-        
+
         stopServer();
         stopServer();
         CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk));
         CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk));
         startServer();
         startServer();
@@ -958,11 +958,11 @@ public:
         zoo_delete(zk, "/watchtest/child2", -1);
         zoo_delete(zk, "/watchtest/child2", -1);
 
 
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
-        
+
         evt = ctxLocal->getEvent();
         evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child2"), evt.path);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child2"), evt.path);
-        
+
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
         evt = ctxLocal->getEvent();
         evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHILD_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHILD_EVENT, evt.type);
@@ -977,7 +977,7 @@ public:
         zoo_delete(zk, "/watchtest", -1);
         zoo_delete(zk, "/watchtest", -1);
 
 
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
-        
+
         evt = ctxLocal->getEvent();
         evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
@@ -985,7 +985,7 @@ public:
         // Make sure nothing is straggling
         // Make sure nothing is straggling
         sleep(1);
         sleep(1);
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
-    }        
+    }
 
 
     void testWatcherAutoResetWithGlobal()
     void testWatcherAutoResetWithGlobal()
     {
     {

+ 30 - 28
src/c/tests/TestZookeeperInit.cc

@@ -35,8 +35,8 @@ using namespace std;
 
 
 class Zookeeper_init : public CPPUNIT_NS::TestFixture
 class Zookeeper_init : public CPPUNIT_NS::TestFixture
 {
 {
-	CPPUNIT_TEST_SUITE(Zookeeper_init);
-	CPPUNIT_TEST(testBasic);
+    CPPUNIT_TEST_SUITE(Zookeeper_init);
+    CPPUNIT_TEST(testBasic);
     CPPUNIT_TEST(testAddressResolution);
     CPPUNIT_TEST(testAddressResolution);
     CPPUNIT_TEST(testMultipleAddressResolution);
     CPPUNIT_TEST(testMultipleAddressResolution);
     CPPUNIT_TEST(testNullAddressString);
     CPPUNIT_TEST(testNullAddressString);
@@ -48,14 +48,16 @@ class Zookeeper_init : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST(testNonexistentHost);
     CPPUNIT_TEST(testNonexistentHost);
     CPPUNIT_TEST(testOutOfMemory_init);
     CPPUNIT_TEST(testOutOfMemory_init);
     CPPUNIT_TEST(testOutOfMemory_getaddrs1);
     CPPUNIT_TEST(testOutOfMemory_getaddrs1);
+#if !defined(__CYGWIN__) // not valid for cygwin
     CPPUNIT_TEST(testOutOfMemory_getaddrs2);
     CPPUNIT_TEST(testOutOfMemory_getaddrs2);
+#endif
     CPPUNIT_TEST(testPermuteAddrsList);
     CPPUNIT_TEST(testPermuteAddrsList);
-	CPPUNIT_TEST_SUITE_END();
+    CPPUNIT_TEST_SUITE_END();
     zhandle_t *zh;
     zhandle_t *zh;
-    MockPthreadsNull* pthreadMock;   
+    MockPthreadsNull* pthreadMock;
     static void watcher(zhandle_t *, int , int , const char *,void*){}
     static void watcher(zhandle_t *, int , int , const char *,void*){}
     FILE *logfile;
     FILE *logfile;
-public: 
+public:
     Zookeeper_init():zh(0),pthreadMock(0){
     Zookeeper_init():zh(0),pthreadMock(0){
       logfile = openlogfile("Zookeeper_init");
       logfile = openlogfile("Zookeeper_init");
     }
     }
@@ -76,10 +78,10 @@ public:
 #ifdef THREADED
 #ifdef THREADED
         // disable threading
         // disable threading
         pthreadMock=new MockPthreadZKNull;
         pthreadMock=new MockPthreadZKNull;
-#endif        
+#endif
         zh=0;
         zh=0;
     }
     }
-    
+
     void tearDown()
     void tearDown()
     {
     {
         zookeeper_close(zh);
         zookeeper_close(zh);
@@ -90,20 +92,20 @@ public:
 
 
     void testBasic()
     void testBasic()
     {
     {
-    	const string EXPECTED_HOST("127.0.0.1:2121");
-    	const int EXPECTED_ADDRS_COUNT =1;
-    	const int EXPECTED_RECV_TIMEOUT=10000;
+        const string EXPECTED_HOST("127.0.0.1:2121");
+        const int EXPECTED_ADDRS_COUNT =1;
+        const int EXPECTED_RECV_TIMEOUT=10000;
         clientid_t cid;
         clientid_t cid;
-    	memset(&cid,0xFE,sizeof(cid));
-        
-    	zh=zookeeper_init(EXPECTED_HOST.c_str(),watcher,EXPECTED_RECV_TIMEOUT,
-    	        &cid,(void*)1,0);
-        
+        memset(&cid,0xFE,sizeof(cid));
+
+        zh=zookeeper_init(EXPECTED_HOST.c_str(),watcher,EXPECTED_RECV_TIMEOUT,
+                &cid,(void*)1,0);
+
         CPPUNIT_ASSERT(zh!=0);
         CPPUNIT_ASSERT(zh!=0);
-    	CPPUNIT_ASSERT(zh->fd == -1);
-    	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->fd == -1);
+        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 == 0);
         CPPUNIT_ASSERT(zh->context == (void*)1);
         CPPUNIT_ASSERT(zh->context == (void*)1);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_RECV_TIMEOUT,zh->recv_timeout);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_RECV_TIMEOUT,zh->recv_timeout);
@@ -138,7 +140,7 @@ public:
 
 
         zoo_deterministic_conn_order(1);
         zoo_deterministic_conn_order(1);
         zh=zookeeper_init("127.0.0.1:2121",0,10000,0,0,0);
         zh=zookeeper_init("127.0.0.1:2121",0,10000,0,0,0);
-        
+
         CPPUNIT_ASSERT(zh!=0);
         CPPUNIT_ASSERT(zh!=0);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs_count);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDRS_COUNT,zh->addrs_count);
         for(int i=0;i<zh->addrs_count;i++){
         for(int i=0;i<zh->addrs_count;i++){
@@ -233,9 +235,9 @@ public:
     void testNonexistentHost()
     void testNonexistentHost()
     {
     {
         const string EXPECTED_HOST("host1.blabadibla.bla.:1111");
         const string EXPECTED_HOST("host1.blabadibla.bla.:1111");
-        
+
         zh=zookeeper_init(EXPECTED_HOST.c_str(),0,0,0,0,0);
         zh=zookeeper_init(EXPECTED_HOST.c_str(),0,0,0,0,0);
-        
+
         CPPUNIT_ASSERT(zh==0);
         CPPUNIT_ASSERT(zh==0);
         //With the switch to thread safe getaddrinfo, we don't get
         //With the switch to thread safe getaddrinfo, we don't get
         //these global variables
         //these global variables
@@ -246,9 +248,9 @@ public:
     {
     {
         Mock_calloc mock;
         Mock_calloc mock;
         mock.callsBeforeFailure=0; // fail first calloc in init()
         mock.callsBeforeFailure=0; // fail first calloc in init()
-        
+
         zh=zookeeper_init("ahost:123",watcher,10000,0,0,0);
         zh=zookeeper_init("ahost:123",watcher,10000,0,0,0);
-        
+
         CPPUNIT_ASSERT(zh==0);
         CPPUNIT_ASSERT(zh==0);
         CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
         CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
     }
     }
@@ -258,7 +260,7 @@ public:
         reallocMock.callsBeforeFailure=0; // fail on first call to realloc
         reallocMock.callsBeforeFailure=0; // fail on first call to realloc
 
 
         zh=zookeeper_init("127.0.0.1:123",0,0,0,0,0);
         zh=zookeeper_init("127.0.0.1:123",0,0,0,0,0);
-        
+
         CPPUNIT_ASSERT(zh==0);
         CPPUNIT_ASSERT(zh==0);
         CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
         CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
     }
     }
@@ -268,7 +270,7 @@ public:
         reallocMock.callsBeforeFailure=1; // fail on the second call to realloc
         reallocMock.callsBeforeFailure=1; // fail on the second call to realloc
 
 
         zh=zookeeper_init("127.0.0.1:123,127.0.0.2:123,127.0.0.3:123,127.0.0.4:123,127.0.0.5:123,127.0.0.6:123,127.0.0.7:123,127.0.0.8:123,127.0.0.9:123,127.0.0.10:123,127.0.0.11:123,127.0.0.12:123,127.0.0.13:123,127.0.0.14:123,127.0.0.15:123,127.0.0.16:123,127.0.0.17:123",0,0,0,0,0);
         zh=zookeeper_init("127.0.0.1:123,127.0.0.2:123,127.0.0.3:123,127.0.0.4:123,127.0.0.5:123,127.0.0.6:123,127.0.0.7:123,127.0.0.8:123,127.0.0.9:123,127.0.0.10:123,127.0.0.11:123,127.0.0.12:123,127.0.0.13:123,127.0.0.14:123,127.0.0.15:123,127.0.0.16:123,127.0.0.17:123",0,0,0,0,0);
-        
+
         CPPUNIT_ASSERT(zh==0);
         CPPUNIT_ASSERT(zh==0);
         CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
         CPPUNIT_ASSERT_EQUAL(ENOMEM,errno);
     }
     }
@@ -276,13 +278,13 @@ public:
     {
     {
         const char EXPECTED[][5]={"\0\0\0\0","\1\1\1\1","\2\2\2\2","\3\3\3\3"};
         const char EXPECTED[][5]={"\0\0\0\0","\1\1\1\1","\2\2\2\2","\3\3\3\3"};
         const int EXPECTED_ADDR_COUNT=COUNTOF(EXPECTED);
         const int EXPECTED_ADDR_COUNT=COUNTOF(EXPECTED);
-        
+
         const int RAND_SEQ[]={0,1,2,3,1,3,2,0,-1};
         const int RAND_SEQ[]={0,1,2,3,1,3,2,0,-1};
         const int RAND_SIZE=COUNTOF(RAND_SEQ);
         const int RAND_SIZE=COUNTOF(RAND_SEQ);
         Mock_random randomMock;
         Mock_random randomMock;
         randomMock.randomReturns.assign(RAND_SEQ,RAND_SEQ+RAND_SIZE-1);
         randomMock.randomReturns.assign(RAND_SEQ,RAND_SEQ+RAND_SIZE-1);
         zh=zookeeper_init("0.0.0.0:123,1.1.1.1:123,2.2.2.2:123,3.3.3.3:123",0,1000,0,0,0);
         zh=zookeeper_init("0.0.0.0:123,1.1.1.1:123,2.2.2.2:123,3.3.3.3:123",0,1000,0,0,0);
-        
+
         CPPUNIT_ASSERT(zh!=0);
         CPPUNIT_ASSERT(zh!=0);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDR_COUNT,zh->addrs_count);
         CPPUNIT_ASSERT_EQUAL(EXPECTED_ADDR_COUNT,zh->addrs_count);
         const string EXPECTED_SEQ("3210");
         const string EXPECTED_SEQ("3210");

+ 74 - 23
src/c/tests/zkServer.sh

@@ -18,36 +18,49 @@
 
 
 if [ "x$1" == "x" ]
 if [ "x$1" == "x" ]
 then
 then
-	echo "USAGE: $0 startClean|start|stop hostPorts"
-	exit 2
+    echo "USAGE: $0 startClean|start|stop hostPorts"
+    exit 2
 fi
 fi
 
 
+case "`uname`" in
+    CYGWIN*) cygwin=true ;;
+    *) cygwin=false ;;
+esac
+
 if [ "x$1" == "xstartClean" ]
 if [ "x$1" == "xstartClean" ]
 then
 then
-    if [ "x${base_dir}" == "x" ]	
+    if [ "x${base_dir}" == "x" ]
     then
     then
     rm -rf /tmp/zkdata
     rm -rf /tmp/zkdata
     else
     else
-    rm -rf ${base_dir}/build/tmp
+    rm -rf "${base_dir}/build/tmp"
     fi
     fi
 fi
 fi
 
 
+if $cygwin
+then
+    # cygwin has a "kill" in the shell itself, gets confused
+    KILL=/bin/kill
+else
+    KILL=kill
+fi
+
 # Make sure nothing is left over from before
 # Make sure nothing is left over from before
 if [ -r "/tmp/zk.pid" ]
 if [ -r "/tmp/zk.pid" ]
 then
 then
 pid=`cat /tmp/zk.pid`
 pid=`cat /tmp/zk.pid`
-kill -9 $pid
+$KILL -9 $pid
 rm -f /tmp/zk.pid
 rm -f /tmp/zk.pid
 fi
 fi
 
 
 if [ -r "${base_dir}/build/tmp/zk.pid" ]
 if [ -r "${base_dir}/build/tmp/zk.pid" ]
 then
 then
-pid=`cat ${base_dir}/build/tmp/zk.pid`
-kill -9 $pid
-rm -f ${base_dir}/build/tmp/zk.pid
+pid=`cat "${base_dir}/build/tmp/zk.pid"`
+$KILL -9 $pid
+rm -f "${base_dir}/build/tmp/zk.pid"
 fi
 fi
 
 
-if [ "x${base_dir}" == "x" ]	
+if [ "x${base_dir}" == "x" ]
 then
 then
 zk_base="../../"
 zk_base="../../"
 else
 else
@@ -69,26 +82,64 @@ done
 
 
 CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover.jar"
 CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover.jar"
 
 
+if $cygwin
+then
+    CLASSPATH=`cygpath -wp "$CLASSPATH"`
+fi
+
 case $1 in
 case $1 in
 start|startClean)
 start|startClean)
-	if [ "x${base_dir}" == "x" ]
+    if [ "x${base_dir}" == "x" ]
         then
         then
-      	mkdir -p /tmp/zkdata
-        java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22181 /tmp/zkdata 3000 $ZKMAXCNXNS &> /tmp/zk.log &
+        mkdir -p /tmp/zkdata
+        java -cp "$CLASSPATH" org.apache.zookeeper.server.ZooKeeperServerMain 22181 /tmp/zkdata 3000 $ZKMAXCNXNS &> /tmp/zk.log &
         pid=$!
         pid=$!
-        echo $! > /tmp/zk.pid        
+        echo -n $! > /tmp/zk.pid
         else
         else
-        mkdir -p ${base_dir}/build/tmp/zkdata
-        java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22181 ${base_dir}/build/tmp/zkdata 3000 $ZKMAXCNXNS &> ${base_dir}/build/tmp/zk.log &
-        echo $! > ${base_dir}/build/tmp/zk.pid
-	fi
-        sleep 5
-	;;
+        mkdir -p "${base_dir}/build/tmp/zkdata"
+        java -cp "$CLASSPATH" org.apache.zookeeper.server.ZooKeeperServerMain 22181 "${base_dir}/build/tmp/zkdata" 3000 $ZKMAXCNXNS &> "${base_dir}/build/tmp/zk.log" &
+        pid=$!
+        echo -n $pid > "${base_dir}/build/tmp/zk.pid"
+    fi
+
+    # wait max 120 seconds for server to be ready to server clients
+    # this handles testing on slow hosts
+    success=false
+    for i in {1..40}
+    do
+        if ps -p $pid > /dev/null
+        then
+            if java -cp "$CLASSPATH" org.apache.zookeeper.ZooKeeperMain -server localhost:22181 ls / > /dev/null 2>&1
+            then
+                # server not up yet - wait
+                sleep 5
+            else
+                # server is up and serving client connections
+                success=true
+                break
+            fi
+        else
+            # server died - exit now
+            echo -n " ZooKeeper server process failed"
+            break
+        fi
+    done
+
+    if $success
+    then
+        ## in case for debug, but generally don't use as it messes up the
+        ## console test output
+        echo -n " ZooKeeper server started"
+    else
+        echo -n " ZooKeeper server NOT started"
+    fi
+
+    ;;
 stop)
 stop)
-	# Already killed above
-	;;
+    # Already killed above
+    ;;
 *)
 *)
-	echo "Unknown command " + $1
-	exit 2
+    echo "Unknown command " + $1
+    exit 2
 esac
 esac
 
 

Some files were not shown because too many files changed in this diff