فهرست منبع

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
   shutdown (mahadev via breed)
 
+  ZOOKEEPER-586. c client does not compile under cygwin (phunt, mahadev, breed via breed)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 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) 
 #ifdef __CYGWIN__
+#if (CYGWIN_VERSION_DLL_MAJOR < 1007)
 #define RANDOM_RET_TYPE int
+#else
+#define RANDOM_RET_TYPE long int
+#endif
 #define GETTIMEOFDAY_ARG2_TYPE void*
 #else
 #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;
         struct timeval tv;
         int rc;
-        time_t expires = time(0) + seconds; 
+        time_t expires = time(0) + seconds;
         time_t timeLeft = seconds;
         fd_set rfds, wfds, efds;
         FD_ZERO(&rfds);
@@ -172,7 +172,7 @@ public:
         }
         return !connected;
     }
-} watchctx_t; 
+} watchctx_t;
 
 class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture
 {
@@ -252,7 +252,7 @@ public:
     {
         zoo_set_log_stream(logfile);
     }
-    
+
 
     void startServer() {
         char cmd[1024];
@@ -269,7 +269,7 @@ public:
     void tearDown()
     {
     }
-    
+
     void testPing()
     {
         watchctx_t ctxIdle;
@@ -317,11 +317,11 @@ public:
     }
 
 #define COUNT 100
-    
+
     static zhandle_t *async_zk;
     static volatile int count;
     static const char* hp_chroot;
-    
+
     static void statCompletion(int rc, const struct Stat *stat, const void *data) {
         int tmp = (int) (long) data;
         CPPUNIT_ASSERT_EQUAL(tmp, rc);
@@ -329,7 +329,7 @@ public:
 
     static void stringCompletion(int rc, const char *value, const void *data) {
         char *path = (char*)data;
-        
+
         if (rc == ZCONNECTIONLOSS && path) {
             // Try again
             rc = zoo_acreate(async_zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, 0);
@@ -340,12 +340,12 @@ public:
             free(path);
         }
     }
-    
+
     static void create_completion_fn(int rc, const char* value, const void *data) {
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         count++;
     }
-    
+
     static void waitForCreateCompletion(int seconds) {
         time_t expires = time(0) + seconds;
         while(count == 0 && time(0) < expires) {
@@ -361,7 +361,7 @@ public:
         CPPUNIT_ASSERT(strcmp(client_path, path) == 0);
         count ++;
     }
-    
+
     static void waitForChrootWatch(int seconds) {
         time_t expires = time(0) + seconds;
         while (count == 0 && time(0) < expires) {
@@ -377,34 +377,34 @@ public:
         }
         count--;
     }
-    
+
     static void voidCompletion(int rc, const void *data) {
         int tmp = (int) (long) data;
         CPPUNIT_ASSERT_EQUAL(tmp, rc);
         count++;
     }
-    
+
     static void verifyCreateFails(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
     }
-    
+
     static void verifyCreateOk(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
     }
-    
+
     static void verifyCreateFailsSeq(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
     }
-    
+
     static void verifyCreateOkSeq(const char *path, zhandle_t *zk) {
       CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
           path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
     }
-    
-            
+
+
     /**
        returns false if the vectors dont match
     **/
@@ -434,7 +434,7 @@ public:
         struct Stat stat;
         watchctx_t 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);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_get_acl(zk, "/acl", &aclvec, &stat  );
@@ -459,18 +459,18 @@ public:
         struct ACL acl_val;
         rc = zoo_add_auth(0, "", 0, 0, voidCompletion, (void*)-1);
         CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
-        
+
         rc = zoo_add_auth(zk, 0, 0, 0, voidCompletion, (void*)-1);
         CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
-        
+
         // auth as pat, create /tauth1, close session
         rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
                           (void*)ZOK);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         waitForVoidCompletion(3);
-                
+
         CPPUNIT_ASSERT(count == 0);
-        
+
         rc = zoo_create(zk, "/tauth1", "", 0, &ZOO_CREATOR_ALL_ACL, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
 
@@ -496,7 +496,7 @@ public:
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         waitForVoidCompletion(3);
         CPPUNIT_ASSERT(count == 0);
-                
+
         char buf[1024];
         int blen = sizeof(buf);
         struct Stat stat;
@@ -505,7 +505,7 @@ public:
         // add auth pat w/correct pass verify success
         rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
                           (void*)ZOK);
-        
+
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
@@ -520,7 +520,7 @@ public:
         //make the server forget the auths
         waitForVoidCompletion(3);
         CPPUNIT_ASSERT(count == 0);
-     
+
         stopServer();
         CPPUNIT_ASSERT(ctx3.waitForDisconnected(zk));
         startServer();
@@ -532,7 +532,7 @@ public:
         rc = zoo_get_acl(zk, "/", &nodeAcl, &stat);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         // 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);
         CPPUNIT_ASSERT_EQUAL((int) acl_val.perms, ZOO_PERM_ALL);
         // verify on root node
@@ -591,7 +591,7 @@ public:
         zhandle_t *zk = createClient(&ctx);
         CPPUNIT_ASSERT(zk);
         int rc = 0;
-        rc = zoo_create(zk, "/mahadev", NULL, -1, 
+        rc = zoo_create(zk, "/mahadev", NULL, -1,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         char buffer[512];
@@ -615,32 +615,32 @@ public:
         int rc = 0;
 
         memset(pathbuf, 'X', 20);
-        rc = zoo_create(zk, "/testpathpath0", "", 0, 
+        rc = zoo_create(zk, "/testpathpath0", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         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);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strlen(pathbuf) == 0);
 
-        rc = zoo_create(zk, "/testpathpath2", "", 0, 
+        rc = zoo_create(zk, "/testpathpath2", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 2);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/") == 0);
 
-        rc = zoo_create(zk, "/testpathpath3", "", 0, 
+        rc = zoo_create(zk, "/testpathpath3", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 3);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         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);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         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);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath8") == 0);
@@ -696,10 +696,10 @@ public:
         verifyCreateOk("/f/.f/f", zk);
         verifyCreateOk("/f/f./f", zk);
     }
-    
+
     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 should fix that though soon!
         watchctx_t ctx, ctx_ch;
@@ -708,7 +708,7 @@ public:
         int rc, len;
         struct Stat stat;
         const char* data = "garbage";
-        const char* retStr = "/chroot"; 
+        const char* retStr = "/chroot";
         const char* root= "/";
         zk_ch = createchClient(&ctx_ch, "127.0.0.1:22181/testch1/mahadev");
         CPPUNIT_ASSERT(zk_ch != NULL);
@@ -723,9 +723,9 @@ public:
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         //check if the data is the same
         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);
-        //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
         rc = zoo_create(zk_ch, "/chroot", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0,0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
@@ -735,7 +735,7 @@ public:
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
-        
+
         rc = zoo_delete(zk_ch, "/chroot/child", -1);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
@@ -751,15 +751,15 @@ public:
         struct String_vector children;
         rc = zoo_get_children(zk_ch, "/", 0, &children);
         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
         CPPUNIT_ASSERT(strcmp((retStr+1), children.data[0]) == 0);
         // check for get/set acl
         struct ACL_vector acl;
         rc = zoo_get_acl(zk_ch, "/", &acl, &stat);
         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
         rc = zoo_set_acl(zk_ch, "/chroot", -1,  &ZOO_READ_ACL_UNSAFE);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
@@ -769,14 +769,14 @@ public:
         //add wget children test
         rc = zoo_wget_children(zk_ch, "/", watcher_chroot_fn, (char*) root, &children);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
-        
+
         //now create a node
         rc = zoo_create(zk_ch, "/child2", "",0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
         waitForChrootWatch(3);
         CPPUNIT_ASSERT(count == 0);
         //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);
         waitForCreateCompletion(3);
         CPPUNIT_ASSERT(count == 0);
@@ -821,7 +821,7 @@ public:
             rc = zoo_acreate(zk, path, "", 0,  &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, strdup(path));
             CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         }
-        
+
         yield(zk, 1);
         stopServer();
         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)
     {
         bool isGlobal = (ctxGlobal == ctxLocal);
@@ -848,7 +848,7 @@ public:
         struct String_vector strings;
         const char *testName;
 
-        rc = zoo_create(zk, "/watchtest", "", 0, 
+        rc = zoo_create(zk, "/watchtest", "", 0,
                         &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
         rc = zoo_create(zk, "/watchtest/child", "", 0,
@@ -879,7 +879,7 @@ public:
                             &stat);
             CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc);
         }
-        
+
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
 
         stopServer();
@@ -904,7 +904,7 @@ public:
         CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
 
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
-        
+
         evt_t evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHANGED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
@@ -924,7 +924,7 @@ public:
         sleep(5);
 
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
-        
+
         stopServer();
         CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk));
         startServer();
@@ -958,11 +958,11 @@ public:
         zoo_delete(zk, "/watchtest/child2", -1);
 
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
-        
+
         evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child2"), evt.path);
-        
+
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
         evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHILD_EVENT, evt.type);
@@ -977,7 +977,7 @@ public:
         zoo_delete(zk, "/watchtest", -1);
 
         CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
-        
+
         evt = ctxLocal->getEvent();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
         CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
@@ -985,7 +985,7 @@ public:
         // Make sure nothing is straggling
         sleep(1);
         CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
-    }        
+    }
 
     void testWatcherAutoResetWithGlobal()
     {

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

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

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

@@ -18,36 +18,49 @@
 
 if [ "x$1" == "x" ]
 then
-	echo "USAGE: $0 startClean|start|stop hostPorts"
-	exit 2
+    echo "USAGE: $0 startClean|start|stop hostPorts"
+    exit 2
 fi
 
+case "`uname`" in
+    CYGWIN*) cygwin=true ;;
+    *) cygwin=false ;;
+esac
+
 if [ "x$1" == "xstartClean" ]
 then
-    if [ "x${base_dir}" == "x" ]	
+    if [ "x${base_dir}" == "x" ]
     then
     rm -rf /tmp/zkdata
     else
-    rm -rf ${base_dir}/build/tmp
+    rm -rf "${base_dir}/build/tmp"
     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
 if [ -r "/tmp/zk.pid" ]
 then
 pid=`cat /tmp/zk.pid`
-kill -9 $pid
+$KILL -9 $pid
 rm -f /tmp/zk.pid
 fi
 
 if [ -r "${base_dir}/build/tmp/zk.pid" ]
 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
 
-if [ "x${base_dir}" == "x" ]	
+if [ "x${base_dir}" == "x" ]
 then
 zk_base="../../"
 else
@@ -69,26 +82,64 @@ done
 
 CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover.jar"
 
+if $cygwin
+then
+    CLASSPATH=`cygpath -wp "$CLASSPATH"`
+fi
+
 case $1 in
 start|startClean)
-	if [ "x${base_dir}" == "x" ]
+    if [ "x${base_dir}" == "x" ]
         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=$!
-        echo $! > /tmp/zk.pid        
+        echo -n $! > /tmp/zk.pid
         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)
-	# Already killed above
-	;;
+    # Already killed above
+    ;;
 *)
-	echo "Unknown command " + $1
-	exit 2
+    echo "Unknown command " + $1
+    exit 2
 esac
 

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است