TestClient.cc 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include <cppunit/extensions/HelperMacros.h>
  19. #include "CppAssertHelper.h"
  20. #include <signal.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <sys/select.h>
  24. #include "CollectionUtil.h"
  25. #include "ThreadingUtil.h"
  26. using namespace Util;
  27. #include "Vector.h"
  28. using namespace std;
  29. #include <cstring>
  30. #include <list>
  31. #include <zookeeper.h>
  32. #include <errno.h>
  33. #include <recordio.h>
  34. #include "Util.h"
  35. #include "ZKMocks.h"
  36. struct buff_struct_2 {
  37. int32_t len;
  38. int32_t off;
  39. char *buffer;
  40. };
  41. // TODO(br33d): the vast majority of this test is not usable with single threaded.
  42. // it needs a overhaul to work properly with both threaded and single
  43. // threaded (ZOOKEEPER-2640)
  44. #ifdef THREADED
  45. // For testing LogMessage Callback functionality
  46. list<string> logMessages;
  47. void logMessageHandler(const char* message) {
  48. cout << "Log Message Received: [" << message << "]" << endl;
  49. logMessages.push_back(message);
  50. }
  51. static int Stat_eq(struct Stat* a, struct Stat* b)
  52. {
  53. if (a->czxid != b->czxid) return 0;
  54. if (a->mzxid != b->mzxid) return 0;
  55. if (a->ctime != b->ctime) return 0;
  56. if (a->mtime != b->mtime) return 0;
  57. if (a->version != b->version) return 0;
  58. if (a->cversion != b->cversion) return 0;
  59. if (a->aversion != b->aversion) return 0;
  60. if (a->ephemeralOwner != b->ephemeralOwner) return 0;
  61. if (a->dataLength != b->dataLength) return 0;
  62. if (a->numChildren != b->numChildren) return 0;
  63. if (a->pzxid != b->pzxid) return 0;
  64. return 1;
  65. }
  66. #ifdef THREADED
  67. static void yield(zhandle_t *zh, int i)
  68. {
  69. sleep(i);
  70. }
  71. #else
  72. static void yield(zhandle_t *zh, int seconds)
  73. {
  74. int fd;
  75. int interest;
  76. int events;
  77. struct timeval tv;
  78. int rc;
  79. time_t expires = time(0) + seconds;
  80. time_t timeLeft = seconds;
  81. fd_set rfds, wfds, efds;
  82. FD_ZERO(&rfds);
  83. FD_ZERO(&wfds);
  84. FD_ZERO(&efds);
  85. while(timeLeft >= 0) {
  86. zookeeper_interest(zh, &fd, &interest, &tv);
  87. if (fd != -1) {
  88. if (interest&ZOOKEEPER_READ) {
  89. FD_SET(fd, &rfds);
  90. } else {
  91. FD_CLR(fd, &rfds);
  92. }
  93. if (interest&ZOOKEEPER_WRITE) {
  94. FD_SET(fd, &wfds);
  95. } else {
  96. FD_CLR(fd, &wfds);
  97. }
  98. } else {
  99. fd = 0;
  100. }
  101. FD_SET(0, &rfds);
  102. if (tv.tv_sec > timeLeft) {
  103. tv.tv_sec = timeLeft;
  104. }
  105. rc = select(fd+1, &rfds, &wfds, &efds, &tv);
  106. timeLeft = expires - time(0);
  107. events = 0;
  108. if (FD_ISSET(fd, &rfds)) {
  109. events |= ZOOKEEPER_READ;
  110. }
  111. if (FD_ISSET(fd, &wfds)) {
  112. events |= ZOOKEEPER_WRITE;
  113. }
  114. zookeeper_process(zh, events);
  115. }
  116. }
  117. #endif
  118. typedef struct evt {
  119. string path;
  120. int type;
  121. } evt_t;
  122. typedef struct watchCtx {
  123. private:
  124. list<evt_t> events;
  125. watchCtx(const watchCtx&);
  126. watchCtx& operator=(const watchCtx&);
  127. public:
  128. bool connected;
  129. zhandle_t *zh;
  130. Mutex mutex;
  131. watchCtx() {
  132. connected = false;
  133. zh = 0;
  134. }
  135. ~watchCtx() {
  136. if (zh) {
  137. zookeeper_close(zh);
  138. zh = 0;
  139. }
  140. }
  141. evt_t getEvent() {
  142. evt_t evt;
  143. mutex.acquire();
  144. CPPUNIT_ASSERT( events.size() > 0);
  145. evt = events.front();
  146. events.pop_front();
  147. mutex.release();
  148. return evt;
  149. }
  150. int countEvents() {
  151. int count;
  152. mutex.acquire();
  153. count = events.size();
  154. mutex.release();
  155. return count;
  156. }
  157. void putEvent(evt_t evt) {
  158. mutex.acquire();
  159. events.push_back(evt);
  160. mutex.release();
  161. }
  162. bool waitForConnected(zhandle_t *zh) {
  163. time_t expires = time(0) + 10;
  164. while(!connected && time(0) < expires) {
  165. yield(zh, 1);
  166. }
  167. return connected;
  168. }
  169. bool waitForDisconnected(zhandle_t *zh) {
  170. time_t expires = time(0) + 15;
  171. while(connected && time(0) < expires) {
  172. yield(zh, 1);
  173. }
  174. return !connected;
  175. }
  176. } watchctx_t;
  177. class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture
  178. {
  179. CPPUNIT_TEST_SUITE(Zookeeper_simpleSystem);
  180. CPPUNIT_TEST(testLogCallbackSet);
  181. CPPUNIT_TEST(testLogCallbackInit);
  182. CPPUNIT_TEST(testLogCallbackClear);
  183. CPPUNIT_TEST(testAsyncWatcherAutoReset);
  184. CPPUNIT_TEST(testDeserializeString);
  185. CPPUNIT_TEST(testFirstServerDown);
  186. CPPUNIT_TEST(testNonexistentHost);
  187. #ifdef THREADED
  188. CPPUNIT_TEST(testNullData);
  189. #ifdef ZOO_IPV6_ENABLED
  190. CPPUNIT_TEST(testIPV6);
  191. #endif
  192. CPPUNIT_TEST(testCreate);
  193. CPPUNIT_TEST(testCreateContainer);
  194. CPPUNIT_TEST(testCreateTtl);
  195. CPPUNIT_TEST(testPath);
  196. CPPUNIT_TEST(testPathValidation);
  197. CPPUNIT_TEST(testPing);
  198. CPPUNIT_TEST(testAcl);
  199. CPPUNIT_TEST(testChroot);
  200. CPPUNIT_TEST(testAuth);
  201. CPPUNIT_TEST(testHangingClient);
  202. CPPUNIT_TEST(testWatcherAutoResetWithGlobal);
  203. CPPUNIT_TEST(testWatcherAutoResetWithLocal);
  204. CPPUNIT_TEST(testGetChildren2);
  205. CPPUNIT_TEST(testLastZxid);
  206. CPPUNIT_TEST(testRemoveWatchers);
  207. #endif
  208. CPPUNIT_TEST_SUITE_END();
  209. static void watcher(zhandle_t *, int type, int state, const char *path,void*v){
  210. watchctx_t *ctx = (watchctx_t*)v;
  211. if (state == ZOO_CONNECTED_STATE) {
  212. ctx->connected = true;
  213. } else {
  214. ctx->connected = false;
  215. }
  216. if (type != ZOO_SESSION_EVENT) {
  217. evt_t evt;
  218. evt.path = path;
  219. evt.type = type;
  220. ctx->putEvent(evt);
  221. }
  222. }
  223. static const char hostPorts[];
  224. const char *getHostPorts() {
  225. return hostPorts;
  226. }
  227. zhandle_t *createClient(watchctx_t *ctx) {
  228. return createClient(hostPorts, ctx);
  229. }
  230. zhandle_t *createClient(watchctx_t *ctx, log_callback_fn logCallback) {
  231. zhandle_t *zk = zookeeper_init2(hostPorts, watcher, 10000, 0, ctx, 0, logCallback);
  232. ctx->zh = zk;
  233. sleep(1);
  234. return zk;
  235. }
  236. zhandle_t *createClient(const char *hp, watchctx_t *ctx) {
  237. zhandle_t *zk = zookeeper_init(hp, watcher, 10000, 0, ctx, 0);
  238. ctx->zh = zk;
  239. sleep(1);
  240. return zk;
  241. }
  242. zhandle_t *createchClient(watchctx_t *ctx, const char* chroot) {
  243. zhandle_t *zk = zookeeper_init(chroot, watcher, 10000, 0, ctx, 0);
  244. ctx->zh = zk;
  245. sleep(1);
  246. return zk;
  247. }
  248. FILE *logfile;
  249. public:
  250. Zookeeper_simpleSystem() {
  251. logfile = openlogfile("Zookeeper_simpleSystem");
  252. }
  253. ~Zookeeper_simpleSystem() {
  254. if (logfile) {
  255. fflush(logfile);
  256. fclose(logfile);
  257. logfile = 0;
  258. }
  259. }
  260. void setUp()
  261. {
  262. zoo_set_log_stream(logfile);
  263. }
  264. void startServer() {
  265. char cmd[1024];
  266. sprintf(cmd, "%s start %s", ZKSERVER_CMD, getHostPorts());
  267. CPPUNIT_ASSERT(system(cmd) == 0);
  268. }
  269. void stopServer() {
  270. char cmd[1024];
  271. sprintf(cmd, "%s stop %s", ZKSERVER_CMD, getHostPorts());
  272. CPPUNIT_ASSERT(system(cmd) == 0);
  273. }
  274. void tearDown()
  275. {
  276. }
  277. /** have a callback in the default watcher **/
  278. static void default_zoo_watcher(zhandle_t *zzh, int type, int state, const char *path, void *context){
  279. int zrc = 0;
  280. struct String_vector str_vec = {0, NULL};
  281. zrc = zoo_wget_children(zzh, "/mytest", default_zoo_watcher, NULL, &str_vec);
  282. }
  283. /** ZOOKEEPER-1057 This checks that the client connects to the second server when the first is not reachable **/
  284. void testFirstServerDown() {
  285. watchctx_t ctx;
  286. zoo_deterministic_conn_order(true);
  287. zhandle_t* zk = createClient("127.0.0.1:22182,127.0.0.1:22181", &ctx);
  288. CPPUNIT_ASSERT(zk != 0);
  289. CPPUNIT_ASSERT(ctx.waitForConnected(zk));
  290. }
  291. /* Checks that a non-existent host will not block the connection*/
  292. void testNonexistentHost() {
  293. char hosts[] = "jimmy:5555,127.0.0.1:22181";
  294. watchctx_t ctx;
  295. zoo_deterministic_conn_order(true /* disable permute */);
  296. zhandle_t *zh = createClient(hosts, &ctx);
  297. CPPUNIT_ASSERT(ctx.waitForConnected(zh));
  298. zoo_deterministic_conn_order(false /* enable permute */);
  299. }
  300. /** this checks for a deadlock in calling zookeeper_close and calls from a default watcher that might get triggered just when zookeeper_close() is in progress **/
  301. void testHangingClient() {
  302. int zrc = 0;
  303. char buff[10] = "testall";
  304. char path[512];
  305. watchctx_t *ctx;
  306. struct String_vector str_vec = {0, NULL};
  307. zhandle_t *zh = zookeeper_init(hostPorts, NULL, 10000, 0, ctx, 0);
  308. sleep(1);
  309. zrc = zoo_create(zh, "/mytest", buff, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, 512);
  310. zrc = zoo_wget_children(zh, "/mytest", default_zoo_watcher, NULL, &str_vec);
  311. zrc = zoo_create(zh, "/mytest/test1", buff, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, 512);
  312. zrc = zoo_wget_children(zh, "/mytest", default_zoo_watcher, NULL, &str_vec);
  313. zrc = zoo_delete(zh, "/mytest/test1", -1);
  314. zookeeper_close(zh);
  315. }
  316. void testBadDescriptor() {
  317. int zrc = 0;
  318. watchctx_t *ctx;
  319. zhandle_t *zh = zookeeper_init(hostPorts, NULL, 10000, 0, ctx, 0);
  320. sleep(1);
  321. zh->io_count = 0;
  322. //close socket
  323. close(zh->fd);
  324. sleep(1);
  325. //Check that doIo isn't spinning
  326. CPPUNIT_ASSERT(zh->io_count < 2);
  327. zookeeper_close(zh);
  328. }
  329. void testPing()
  330. {
  331. watchctx_t ctxIdle;
  332. watchctx_t ctxWC;
  333. zhandle_t *zkIdle = createClient(&ctxIdle);
  334. zhandle_t *zkWatchCreator = createClient(&ctxWC);
  335. CPPUNIT_ASSERT(zkIdle);
  336. CPPUNIT_ASSERT(zkWatchCreator);
  337. char path[80];
  338. sprintf(path, "/testping");
  339. int rc = zoo_create(zkWatchCreator, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  340. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  341. for(int i = 0; i < 30; i++) {
  342. sprintf(path, "/testping/%i", i);
  343. rc = zoo_create(zkWatchCreator, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  344. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  345. }
  346. for(int i = 0; i < 30; i++) {
  347. sprintf(path, "/testping/%i", i);
  348. struct Stat stat;
  349. rc = zoo_exists(zkIdle, path, 1, &stat);
  350. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  351. }
  352. for(int i = 0; i < 30; i++) {
  353. sprintf(path, "/testping/%i", i);
  354. usleep(500000);
  355. rc = zoo_delete(zkWatchCreator, path, -1);
  356. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  357. }
  358. struct Stat stat;
  359. CPPUNIT_ASSERT_EQUAL((int)ZNONODE, zoo_exists(zkIdle, "/testping/0", 0, &stat));
  360. }
  361. bool waitForEvent(zhandle_t *zh, watchctx_t *ctx, int seconds) {
  362. time_t expires = time(0) + seconds;
  363. while(ctx->countEvents() == 0 && time(0) < expires) {
  364. yield(zh, 1);
  365. }
  366. return ctx->countEvents() > 0;
  367. }
  368. #define COUNT 100
  369. static zhandle_t *async_zk;
  370. static volatile int count;
  371. static const char* hp_chroot;
  372. static void statCompletion(int rc, const struct Stat *stat, const void *data) {
  373. int tmp = (int) (long) data;
  374. CPPUNIT_ASSERT_EQUAL(tmp, rc);
  375. }
  376. static void stringCompletion(int rc, const char *value, const void *data) {
  377. char *path = (char*)data;
  378. if (rc == ZCONNECTIONLOSS && path) {
  379. // Try again
  380. rc = zoo_acreate(async_zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, 0);
  381. } else if (rc != ZOK) {
  382. // fprintf(stderr, "rc = %d with path = %s\n", rc, (path ? path : "null"));
  383. }
  384. if (path) {
  385. free(path);
  386. }
  387. }
  388. static void stringStatCompletion(int rc, const char *value, const struct Stat *stat,
  389. const void *data) {
  390. stringCompletion(rc, value, data);
  391. CPPUNIT_ASSERT(stat != 0);
  392. }
  393. static void create_completion_fn(int rc, const char* value, const void *data) {
  394. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  395. if (data) {
  396. const char *expected_value = (const char *)data;
  397. CPPUNIT_ASSERT_EQUAL(string(expected_value), string(value));
  398. }
  399. count++;
  400. }
  401. static void waitForCreateCompletion(int seconds) {
  402. time_t expires = time(0) + seconds;
  403. while(count == 0 && time(0) < expires) {
  404. sleep(1);
  405. }
  406. count--;
  407. }
  408. static void watcher_chroot_fn(zhandle_t *zh, int type,
  409. int state, const char *path,void *watcherCtx) {
  410. // check for path
  411. char *client_path = (char *) watcherCtx;
  412. CPPUNIT_ASSERT(strcmp(client_path, path) == 0);
  413. count ++;
  414. }
  415. static void waitForChrootWatch(int seconds) {
  416. time_t expires = time(0) + seconds;
  417. while (count == 0 && time(0) < expires) {
  418. sleep(1);
  419. }
  420. count--;
  421. }
  422. static void waitForVoidCompletion(int seconds) {
  423. time_t expires = time(0) + seconds;
  424. while(count == 0 && time(0) < expires) {
  425. sleep(1);
  426. }
  427. count--;
  428. }
  429. static void voidCompletion(int rc, const void *data) {
  430. int tmp = (int) (long) data;
  431. CPPUNIT_ASSERT_EQUAL(tmp, rc);
  432. count++;
  433. }
  434. static void verifyCreateFails(const char *path, zhandle_t *zk) {
  435. CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
  436. path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
  437. }
  438. static void verifyCreateOk(const char *path, zhandle_t *zk) {
  439. CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
  440. path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0));
  441. }
  442. static void verifyCreateFailsSeq(const char *path, zhandle_t *zk) {
  443. CPPUNIT_ASSERT_EQUAL((int)ZBADARGUMENTS, zoo_create(zk,
  444. path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
  445. }
  446. static void verifyCreateOkSeq(const char *path, zhandle_t *zk) {
  447. CPPUNIT_ASSERT_EQUAL((int)ZOK, zoo_create(zk,
  448. path, "", 0, &ZOO_OPEN_ACL_UNSAFE, ZOO_SEQUENCE, 0, 0));
  449. }
  450. /**
  451. returns false if the vectors dont match
  452. **/
  453. bool compareAcl(struct ACL_vector acl1, struct ACL_vector acl2) {
  454. if (acl1.count != acl2.count) {
  455. return false;
  456. }
  457. struct ACL *aclval1 = acl1.data;
  458. struct ACL *aclval2 = acl2.data;
  459. if (aclval1->perms != aclval2->perms) {
  460. return false;
  461. }
  462. struct Id id1 = aclval1->id;
  463. struct Id id2 = aclval2->id;
  464. if (strcmp(id1.scheme, id2.scheme) != 0) {
  465. return false;
  466. }
  467. if (strcmp(id1.id, id2.id) != 0) {
  468. return false;
  469. }
  470. return true;
  471. }
  472. void testDeserializeString() {
  473. char *val_str;
  474. int rc = 0;
  475. int val = -1;
  476. struct iarchive *ia;
  477. struct buff_struct_2 *b;
  478. struct oarchive *oa = create_buffer_oarchive();
  479. oa->serialize_Int(oa, "int", &val);
  480. b = (struct buff_struct_2 *) oa->priv;
  481. ia = create_buffer_iarchive(b->buffer, b->len);
  482. rc = ia->deserialize_String(ia, "string", &val_str);
  483. CPPUNIT_ASSERT_EQUAL(-EINVAL, rc);
  484. }
  485. void testAcl() {
  486. int rc;
  487. struct ACL_vector aclvec;
  488. struct Stat stat;
  489. watchctx_t ctx;
  490. zhandle_t *zk = createClient(&ctx);
  491. rc = zoo_create(zk, "/acl", "", 0,
  492. &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  493. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  494. rc = zoo_get_acl(zk, "/acl", &aclvec, &stat );
  495. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  496. bool cmp = compareAcl(ZOO_OPEN_ACL_UNSAFE, aclvec);
  497. CPPUNIT_ASSERT_EQUAL(true, cmp);
  498. rc = zoo_set_acl(zk, "/acl", -1, &ZOO_READ_ACL_UNSAFE);
  499. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  500. rc = zoo_get_acl(zk, "/acl", &aclvec, &stat);
  501. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  502. cmp = compareAcl(ZOO_READ_ACL_UNSAFE, aclvec);
  503. CPPUNIT_ASSERT_EQUAL(true, cmp);
  504. }
  505. void testAuth() {
  506. int rc;
  507. count = 0;
  508. watchctx_t ctx1, ctx2, ctx3, ctx4, ctx5;
  509. zhandle_t *zk = createClient(&ctx1);
  510. struct ACL_vector nodeAcl;
  511. struct ACL acl_val;
  512. rc = zoo_add_auth(0, "", 0, 0, voidCompletion, (void*)-1);
  513. CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
  514. rc = zoo_add_auth(zk, 0, 0, 0, voidCompletion, (void*)-1);
  515. CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
  516. // auth as pat, create /tauth1, close session
  517. rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
  518. (void*)ZOK);
  519. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  520. waitForVoidCompletion(3);
  521. CPPUNIT_ASSERT(count == 0);
  522. rc = zoo_create(zk, "/tauth1", "", 0, &ZOO_CREATOR_ALL_ACL, 0, 0, 0);
  523. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  524. {
  525. //create a new client
  526. zk = createClient(&ctx4);
  527. rc = zoo_add_auth(zk, "digest", "", 0, voidCompletion, (void*)ZOK);
  528. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  529. waitForVoidCompletion(3);
  530. CPPUNIT_ASSERT(count == 0);
  531. rc = zoo_add_auth(zk, "digest", "", 0, voidCompletion, (void*)ZOK);
  532. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  533. waitForVoidCompletion(3);
  534. CPPUNIT_ASSERT(count == 0);
  535. }
  536. //create a new client
  537. zk = createClient(&ctx2);
  538. rc = zoo_add_auth(zk, "digest", "pat:passwd2", 11, voidCompletion,
  539. (void*)ZOK);
  540. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  541. waitForVoidCompletion(3);
  542. CPPUNIT_ASSERT(count == 0);
  543. char buf[1024];
  544. int blen = sizeof(buf);
  545. struct Stat stat;
  546. rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
  547. CPPUNIT_ASSERT_EQUAL((int)ZNOAUTH, rc);
  548. // add auth pat w/correct pass verify success
  549. rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion,
  550. (void*)ZOK);
  551. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  552. rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
  553. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  554. waitForVoidCompletion(3);
  555. CPPUNIT_ASSERT(count == 0);
  556. //create a new client
  557. zk = createClient(&ctx3);
  558. rc = zoo_add_auth(zk, "digest", "pat:passwd", 10, voidCompletion, (void*) ZOK);
  559. waitForVoidCompletion(3);
  560. CPPUNIT_ASSERT(count == 0);
  561. rc = zoo_add_auth(zk, "ip", "none", 4, voidCompletion, (void*)ZOK);
  562. //make the server forget the auths
  563. waitForVoidCompletion(3);
  564. CPPUNIT_ASSERT(count == 0);
  565. stopServer();
  566. CPPUNIT_ASSERT(ctx3.waitForDisconnected(zk));
  567. startServer();
  568. CPPUNIT_ASSERT(ctx3.waitForConnected(zk));
  569. // now try getting the data
  570. rc = zoo_get(zk, "/tauth1", 0, buf, &blen, &stat);
  571. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  572. // also check for get
  573. rc = zoo_get_acl(zk, "/", &nodeAcl, &stat);
  574. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  575. // check if the acl has all the perms
  576. CPPUNIT_ASSERT_EQUAL((int)1, (int)nodeAcl.count);
  577. acl_val = *(nodeAcl.data);
  578. CPPUNIT_ASSERT_EQUAL((int) acl_val.perms, ZOO_PERM_ALL);
  579. // verify on root node
  580. rc = zoo_set_acl(zk, "/", -1, &ZOO_CREATOR_ALL_ACL);
  581. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  582. rc = zoo_set_acl(zk, "/", -1, &ZOO_OPEN_ACL_UNSAFE);
  583. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  584. //[ZOOKEEPER-1108], test that auth info is sent to server, if client is not
  585. //connected to server when zoo_add_auth was called.
  586. zhandle_t *zk_auth = zookeeper_init(hostPorts, NULL, 10000, 0, NULL, 0);
  587. rc = zoo_add_auth(zk_auth, "digest", "pat:passwd", 10, voidCompletion, (void*)ZOK);
  588. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  589. sleep(2);
  590. CPPUNIT_ASSERT(count == 1);
  591. count = 0;
  592. CPPUNIT_ASSERT_EQUAL((int) ZOK, zookeeper_close(zk_auth));
  593. struct sockaddr addr;
  594. socklen_t addr_len = sizeof(addr);
  595. zk = createClient(&ctx5);
  596. stopServer();
  597. CPPUNIT_ASSERT(ctx5.waitForDisconnected(zk));
  598. CPPUNIT_ASSERT(zookeeper_get_connected_host(zk, &addr, &addr_len) == NULL);
  599. addr_len = sizeof(addr);
  600. startServer();
  601. CPPUNIT_ASSERT(ctx5.waitForConnected(zk));
  602. CPPUNIT_ASSERT(zookeeper_get_connected_host(zk, &addr, &addr_len) != NULL);
  603. }
  604. void testCreate() {
  605. watchctx_t ctx;
  606. int rc = 0;
  607. zhandle_t *zk = createClient(&ctx);
  608. CPPUNIT_ASSERT(zk);
  609. char pathbuf[80];
  610. struct Stat stat_a = {0};
  611. struct Stat stat_b = {0};
  612. rc = zoo_create2(zk, "/testcreateA", "", 0,
  613. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, sizeof(pathbuf), &stat_a);
  614. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  615. CPPUNIT_ASSERT(strcmp(pathbuf, "/testcreateA") == 0);
  616. CPPUNIT_ASSERT(stat_a.czxid > 0);
  617. CPPUNIT_ASSERT(stat_a.mtime > 0);
  618. rc = zoo_create2(zk, "/testcreateB", "", 0,
  619. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, sizeof(pathbuf), &stat_b);
  620. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  621. CPPUNIT_ASSERT(strcmp(pathbuf, "/testcreateB") == 0);
  622. CPPUNIT_ASSERT(stat_b.czxid > 0);
  623. CPPUNIT_ASSERT(stat_b.mtime > 0);
  624. // Should get different Stats back from different creates
  625. CPPUNIT_ASSERT(Stat_eq(&stat_a, &stat_b) != 1);
  626. }
  627. void testCreateContainer() {
  628. watchctx_t ctx;
  629. int rc = 0;
  630. zhandle_t *zk = createClient(&ctx);
  631. CPPUNIT_ASSERT(zk);
  632. char pathbuf[80];
  633. struct Stat stat = {0};
  634. rc = zoo_create2(zk, "/testContainer", "", 0, &ZOO_OPEN_ACL_UNSAFE,
  635. ZOO_CONTAINER, pathbuf, sizeof(pathbuf), &stat);
  636. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  637. }
  638. void testCreateTtl() {
  639. watchctx_t ctx;
  640. int rc = 0;
  641. zhandle_t *zk = createClient(&ctx);
  642. CPPUNIT_ASSERT(zk);
  643. char pathbuf[80];
  644. struct Stat stat = {0};
  645. rc = zoo_create2_ttl(zk, "/testTtl", "", 0, &ZOO_OPEN_ACL_UNSAFE,
  646. ZOO_PERSISTENT_WITH_TTL, 1, pathbuf, sizeof(pathbuf), &stat);
  647. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  648. sleep(1);
  649. rc = zoo_exists(zk, "/testTtl", 1, &stat);
  650. CPPUNIT_ASSERT_EQUAL((int) ZNONODE, rc);
  651. }
  652. void testGetChildren2() {
  653. int rc;
  654. watchctx_t ctx;
  655. zhandle_t *zk = createClient(&ctx);
  656. rc = zoo_create(zk, "/parent", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  657. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  658. rc = zoo_create(zk, "/parent/child_a", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  659. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  660. rc = zoo_create(zk, "/parent/child_b", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  661. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  662. rc = zoo_create(zk, "/parent/child_c", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  663. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  664. rc = zoo_create(zk, "/parent/child_d", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  665. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  666. struct String_vector strings;
  667. struct Stat stat_a, stat_b;
  668. rc = zoo_get_children2(zk, "/parent", 0, &strings, &stat_a);
  669. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  670. rc = zoo_exists(zk, "/parent", 0, &stat_b);
  671. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  672. CPPUNIT_ASSERT(Stat_eq(&stat_a, &stat_b));
  673. CPPUNIT_ASSERT(stat_a.numChildren == 4);
  674. }
  675. void testIPV6() {
  676. watchctx_t ctx;
  677. zhandle_t *zk = createClient("::1:22181", &ctx);
  678. CPPUNIT_ASSERT(zk);
  679. int rc = 0;
  680. rc = zoo_create(zk, "/ipv6", NULL, -1,
  681. &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  682. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  683. }
  684. void testNullData() {
  685. watchctx_t ctx;
  686. zhandle_t *zk = createClient(&ctx);
  687. CPPUNIT_ASSERT(zk);
  688. int rc = 0;
  689. rc = zoo_create(zk, "/mahadev", NULL, -1,
  690. &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  691. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  692. char buffer[512];
  693. struct Stat stat;
  694. int len = 512;
  695. rc = zoo_wget(zk, "/mahadev", NULL, NULL, buffer, &len, &stat);
  696. CPPUNIT_ASSERT_EQUAL( -1, len);
  697. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  698. rc = zoo_set(zk, "/mahadev", NULL, -1, -1);
  699. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  700. rc = zoo_wget(zk, "/mahadev", NULL, NULL, buffer, &len, &stat);
  701. CPPUNIT_ASSERT_EQUAL( -1, len);
  702. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  703. }
  704. void testPath() {
  705. watchctx_t ctx;
  706. char pathbuf[20];
  707. zhandle_t *zk = createClient(&ctx);
  708. CPPUNIT_ASSERT(zk);
  709. int rc = 0;
  710. memset(pathbuf, 'X', 20);
  711. rc = zoo_create(zk, "/testpathpath0", "", 0,
  712. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 0);
  713. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  714. CPPUNIT_ASSERT_EQUAL('X', pathbuf[0]);
  715. rc = zoo_create(zk, "/testpathpath1", "", 0,
  716. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 1);
  717. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  718. CPPUNIT_ASSERT(strlen(pathbuf) == 0);
  719. rc = zoo_create(zk, "/testpathpath2", "", 0,
  720. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 2);
  721. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  722. CPPUNIT_ASSERT(strcmp(pathbuf, "/") == 0);
  723. rc = zoo_create(zk, "/testpathpath3", "", 0,
  724. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 3);
  725. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  726. CPPUNIT_ASSERT(strcmp(pathbuf, "/t") == 0);
  727. rc = zoo_create(zk, "/testpathpath7", "", 0,
  728. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 15);
  729. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  730. CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath7") == 0);
  731. rc = zoo_create(zk, "/testpathpath8", "", 0,
  732. &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, 16);
  733. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  734. CPPUNIT_ASSERT(strcmp(pathbuf, "/testpathpath8") == 0);
  735. }
  736. void testPathValidation() {
  737. watchctx_t ctx;
  738. zhandle_t *zk = createClient(&ctx);
  739. CPPUNIT_ASSERT(zk);
  740. verifyCreateFails(0, zk);
  741. verifyCreateFails("", zk);
  742. verifyCreateFails("//", zk);
  743. verifyCreateFails("///", zk);
  744. verifyCreateFails("////", zk);
  745. verifyCreateFails("/.", zk);
  746. verifyCreateFails("/..", zk);
  747. verifyCreateFails("/./", zk);
  748. verifyCreateFails("/../", zk);
  749. verifyCreateFails("/foo/./", zk);
  750. verifyCreateFails("/foo/../", zk);
  751. verifyCreateFails("/foo/.", zk);
  752. verifyCreateFails("/foo/..", zk);
  753. verifyCreateFails("/./.", zk);
  754. verifyCreateFails("/../..", zk);
  755. verifyCreateFails("/foo/bar/", zk);
  756. verifyCreateFails("/foo//bar", zk);
  757. verifyCreateFails("/foo/bar//", zk);
  758. verifyCreateFails("foo", zk);
  759. verifyCreateFails("a", zk);
  760. // verify that trailing fails, except for seq which adds suffix
  761. verifyCreateOk("/createseq", zk);
  762. verifyCreateFails("/createseq/", zk);
  763. verifyCreateOkSeq("/createseq/", zk);
  764. verifyCreateOkSeq("/createseq/.", zk);
  765. verifyCreateOkSeq("/createseq/..", zk);
  766. verifyCreateFailsSeq("/createseq//", zk);
  767. verifyCreateFailsSeq("/createseq/./", zk);
  768. verifyCreateFailsSeq("/createseq/../", zk);
  769. verifyCreateOk("/.foo", zk);
  770. verifyCreateOk("/.f.", zk);
  771. verifyCreateOk("/..f", zk);
  772. verifyCreateOk("/..f..", zk);
  773. verifyCreateOk("/f.c", zk);
  774. verifyCreateOk("/f", zk);
  775. verifyCreateOk("/f/.f", zk);
  776. verifyCreateOk("/f/f.", zk);
  777. verifyCreateOk("/f/..f", zk);
  778. verifyCreateOk("/f/f..", zk);
  779. verifyCreateOk("/f/.f/f", zk);
  780. verifyCreateOk("/f/f./f", zk);
  781. }
  782. void testChroot() {
  783. // the c client async callbacks do
  784. // not callback with the path, so
  785. // we dont need to test taht for now
  786. // we should fix that though soon!
  787. watchctx_t ctx, ctx_ch;
  788. zhandle_t *zk, *zk_ch;
  789. char buf[60];
  790. int rc, len;
  791. struct Stat stat;
  792. const char* data = "garbage";
  793. const char* retStr = "/chroot";
  794. const char* root= "/";
  795. zk_ch = createchClient(&ctx_ch, "127.0.0.1:22181/testch1/mahadev");
  796. CPPUNIT_ASSERT(zk_ch != NULL);
  797. zk = createClient(&ctx);
  798. // first test with a NULL zk handle, make sure client library does not
  799. // dereference a null pointer, but instead returns ZBADARGUMENTS
  800. rc = zoo_create(NULL, "/testch1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  801. CPPUNIT_ASSERT_EQUAL((int) ZBADARGUMENTS, rc);
  802. rc = zoo_create(zk, "/testch1", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  803. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  804. rc = zoo_create(zk, "/testch1/mahadev", data, 7, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  805. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  806. // try an exists with /
  807. len = 60;
  808. rc = zoo_get(zk_ch, "/", 0, buf, &len, &stat);
  809. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  810. //check if the data is the same
  811. CPPUNIT_ASSERT(strncmp(buf, data, 7) == 0);
  812. //check for watches
  813. rc = zoo_wexists(zk_ch, "/chroot", watcher_chroot_fn, (void *) retStr, &stat);
  814. //now check if we can do create/delete/get/sets/acls/getChildren and others
  815. //check create
  816. rc = zoo_create(zk_ch, "/chroot", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0,0);
  817. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  818. waitForChrootWatch(3);
  819. CPPUNIT_ASSERT(count == 0);
  820. rc = zoo_create(zk_ch, "/chroot/child", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  821. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  822. rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
  823. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  824. rc = zoo_delete(zk_ch, "/chroot/child", -1);
  825. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  826. rc = zoo_exists(zk, "/testch1/mahadev/chroot/child", 0, &stat);
  827. CPPUNIT_ASSERT_EQUAL((int) ZNONODE, rc);
  828. rc = zoo_wget(zk_ch, "/chroot", watcher_chroot_fn, (char*) retStr,
  829. buf, &len, &stat);
  830. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  831. rc = zoo_set(zk_ch, "/chroot",buf, 3, -1);
  832. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  833. waitForChrootWatch(3);
  834. CPPUNIT_ASSERT(count == 0);
  835. // check for getchildren
  836. struct String_vector children;
  837. rc = zoo_get_children(zk_ch, "/", 0, &children);
  838. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  839. CPPUNIT_ASSERT_EQUAL((int)1, (int)children.count);
  840. //check if te child if chroot
  841. CPPUNIT_ASSERT(strcmp((retStr+1), children.data[0]) == 0);
  842. // check for get/set acl
  843. struct ACL_vector acl;
  844. rc = zoo_get_acl(zk_ch, "/", &acl, &stat);
  845. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  846. CPPUNIT_ASSERT_EQUAL((int)1, (int)acl.count);
  847. CPPUNIT_ASSERT_EQUAL((int)ZOO_PERM_ALL, (int)acl.data->perms);
  848. // set acl
  849. rc = zoo_set_acl(zk_ch, "/chroot", -1, &ZOO_READ_ACL_UNSAFE);
  850. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  851. // see if you add children
  852. rc = zoo_create(zk_ch, "/chroot/child1", "",0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  853. CPPUNIT_ASSERT_EQUAL((int)ZNOAUTH, rc);
  854. //add wget children test
  855. rc = zoo_wget_children(zk_ch, "/", watcher_chroot_fn, (char*) root, &children);
  856. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  857. //now create a node
  858. rc = zoo_create(zk_ch, "/child2", "",0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  859. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  860. waitForChrootWatch(3);
  861. CPPUNIT_ASSERT(count == 0);
  862. //check for one async call just to make sure
  863. rc = zoo_acreate(zk_ch, "/child3", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0,
  864. create_completion_fn, 0);
  865. waitForCreateCompletion(3);
  866. CPPUNIT_ASSERT(count == 0);
  867. //ZOOKEEPER-1027 correctly return path_buffer without prefixed chroot
  868. const char* path = "/zookeeper1027";
  869. char path_buffer[1024];
  870. int path_buffer_len=sizeof(path_buffer);
  871. rc = zoo_create(zk_ch, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, path_buffer, path_buffer_len);
  872. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  873. CPPUNIT_ASSERT_EQUAL(string(path), string(path_buffer));
  874. const char* path2282 = "/zookeeper2282";
  875. rc = zoo_acreate(zk_ch, path2282, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0,
  876. create_completion_fn, path2282);
  877. waitForCreateCompletion(3);
  878. CPPUNIT_ASSERT(count == 0);
  879. }
  880. // Test creating normal handle via zookeeper_init then explicitly setting callback
  881. void testLogCallbackSet()
  882. {
  883. watchctx_t ctx;
  884. CPPUNIT_ASSERT(logMessages.empty());
  885. zhandle_t *zk = createClient(&ctx);
  886. zoo_set_log_callback(zk, &logMessageHandler);
  887. CPPUNIT_ASSERT_EQUAL(zoo_get_log_callback(zk), &logMessageHandler);
  888. // Log 10 messages and ensure all go to callback
  889. int expected = 10;
  890. for (int i = 0; i < expected; i++)
  891. {
  892. LOG_INFO(LOGCALLBACK(zk), "%s #%d", __FUNCTION__, i);
  893. }
  894. CPPUNIT_ASSERT(expected == logMessages.size());
  895. }
  896. // Test creating handle via zookeeper_init2 to ensure all connection messages go to callback
  897. void testLogCallbackInit()
  898. {
  899. logMessages.clear();
  900. watchctx_t ctx;
  901. zhandle_t *zk = createClient(&ctx, &logMessageHandler);
  902. CPPUNIT_ASSERT_EQUAL(zoo_get_log_callback(zk), &logMessageHandler);
  903. // All the connection messages should have gone to the callback -- don't
  904. // want this to be a maintenance issue so we're not asserting exact count
  905. int numBefore = logMessages.size();
  906. CPPUNIT_ASSERT(numBefore != 0);
  907. // Log 10 messages and ensure all go to callback
  908. int expected = 10;
  909. for (int i = 0; i < expected; i++)
  910. {
  911. LOG_INFO(LOGCALLBACK(zk), "%s #%d", __FUNCTION__, i);
  912. }
  913. CPPUNIT_ASSERT(logMessages.size() == numBefore + expected);
  914. }
  915. // Test clearing log callback -- logging should resume going to logstream
  916. void testLogCallbackClear()
  917. {
  918. logMessages.clear();
  919. watchctx_t ctx;
  920. zhandle_t *zk = createClient(&ctx, &logMessageHandler);
  921. CPPUNIT_ASSERT_EQUAL(zoo_get_log_callback(zk), &logMessageHandler);
  922. // All the connection messages should have gone to the callback -- again, we don't
  923. // want this to be a maintenance issue so we're not asserting exact count
  924. int numBefore = logMessages.size();
  925. CPPUNIT_ASSERT(numBefore > 0);
  926. // Clear log_callback
  927. zoo_set_log_callback(zk, NULL);
  928. // Future log messages should go to logstream not callback
  929. LOG_INFO(LOGCALLBACK(zk), __FUNCTION__);
  930. int numAfter = logMessages.size();
  931. CPPUNIT_ASSERT_EQUAL(numBefore, numAfter);
  932. }
  933. void testAsyncWatcherAutoReset()
  934. {
  935. watchctx_t ctx;
  936. zhandle_t *zk = createClient(&ctx);
  937. watchctx_t lctx[COUNT];
  938. int i;
  939. char path[80];
  940. int rc;
  941. evt_t evt;
  942. async_zk = zk;
  943. for(i = 0; i < COUNT; i++) {
  944. sprintf(path, "/awar%d", i);
  945. rc = zoo_awexists(zk, path, watcher, &lctx[i], statCompletion, (void*)ZNONODE);
  946. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  947. }
  948. yield(zk, 0);
  949. for(i = 0; i < COUNT/4; i++) {
  950. sprintf(path, "/awar%d", i);
  951. rc = zoo_acreate(zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0,
  952. stringCompletion, strdup(path));
  953. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  954. }
  955. for(i = COUNT/4; i < COUNT/2; i++) {
  956. sprintf(path, "/awar%d", i);
  957. rc = zoo_acreate2(zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0,
  958. stringStatCompletion, strdup(path));
  959. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  960. }
  961. yield(zk, 3);
  962. for(i = 0; i < COUNT/2; i++) {
  963. sprintf(path, "/awar%d", i);
  964. CPPUNIT_ASSERT_MESSAGE(path, waitForEvent(zk, &lctx[i], 5));
  965. evt = lctx[i].getEvent();
  966. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path.c_str(), ZOO_CREATED_EVENT, evt.type);
  967. CPPUNIT_ASSERT_EQUAL(string(path), evt.path);
  968. }
  969. for(i = COUNT/2 + 1; i < COUNT*10; i++) {
  970. sprintf(path, "/awar%d", i);
  971. rc = zoo_acreate(zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, stringCompletion, strdup(path));
  972. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  973. }
  974. yield(zk, 1);
  975. stopServer();
  976. CPPUNIT_ASSERT(ctx.waitForDisconnected(zk));
  977. startServer();
  978. CPPUNIT_ASSERT(ctx.waitForConnected(zk));
  979. yield(zk, 3);
  980. for(i = COUNT/2+1; i < COUNT; i++) {
  981. sprintf(path, "/awar%d", i);
  982. CPPUNIT_ASSERT_MESSAGE(path, waitForEvent(zk, &lctx[i], 5));
  983. evt = lctx[i].getEvent();
  984. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CREATED_EVENT, evt.type);
  985. CPPUNIT_ASSERT_EQUAL(string(path), evt.path);
  986. }
  987. }
  988. void testWatcherAutoReset(zhandle_t *zk, watchctx_t *ctxGlobal,
  989. watchctx_t *ctxLocal)
  990. {
  991. bool isGlobal = (ctxGlobal == ctxLocal);
  992. int rc;
  993. struct Stat stat;
  994. char buf[1024];
  995. int blen;
  996. struct String_vector strings;
  997. const char *testName;
  998. rc = zoo_create(zk, "/watchtest", "", 0,
  999. &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1000. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1001. rc = zoo_create(zk, "/watchtest/child", "", 0,
  1002. &ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, 0, 0);
  1003. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1004. if (isGlobal) {
  1005. testName = "GlobalTest";
  1006. rc = zoo_get_children(zk, "/watchtest", 1, &strings);
  1007. deallocate_String_vector(&strings);
  1008. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1009. blen = sizeof(buf);
  1010. rc = zoo_get(zk, "/watchtest/child", 1, buf, &blen, &stat);
  1011. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1012. rc = zoo_exists(zk, "/watchtest/child2", 1, &stat);
  1013. CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc);
  1014. } else {
  1015. testName = "LocalTest";
  1016. rc = zoo_wget_children(zk, "/watchtest", watcher, ctxLocal,
  1017. &strings);
  1018. deallocate_String_vector(&strings);
  1019. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1020. blen = sizeof(buf);
  1021. rc = zoo_wget(zk, "/watchtest/child", watcher, ctxLocal,
  1022. buf, &blen, &stat);
  1023. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1024. rc = zoo_wexists(zk, "/watchtest/child2", watcher, ctxLocal,
  1025. &stat);
  1026. CPPUNIT_ASSERT_EQUAL((int)ZNONODE, rc);
  1027. }
  1028. CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
  1029. stopServer();
  1030. CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk));
  1031. startServer();
  1032. CPPUNIT_ASSERT_MESSAGE(testName, ctxLocal->waitForConnected(zk));
  1033. CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
  1034. rc = zoo_set(zk, "/watchtest/child", "1", 1, -1);
  1035. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1036. struct Stat stat1, stat2;
  1037. rc = zoo_set2(zk, "/watchtest/child", "1", 1, -1, &stat1);
  1038. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1039. CPPUNIT_ASSERT(stat1.version >= 0);
  1040. rc = zoo_set2(zk, "/watchtest/child", "1", 1, stat1.version, &stat2);
  1041. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1042. rc = zoo_set(zk, "/watchtest/child", "1", 1, stat2.version);
  1043. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1044. rc = zoo_create(zk, "/watchtest/child2", "", 0,
  1045. &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1046. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1047. CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
  1048. evt_t evt = ctxLocal->getEvent();
  1049. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHANGED_EVENT, evt.type);
  1050. CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
  1051. CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
  1052. // The create will trigget the get children and the
  1053. // exists watches
  1054. evt = ctxLocal->getEvent();
  1055. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CREATED_EVENT, evt.type);
  1056. CPPUNIT_ASSERT_EQUAL(string("/watchtest/child2"), evt.path);
  1057. CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
  1058. evt = ctxLocal->getEvent();
  1059. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHILD_EVENT, evt.type);
  1060. CPPUNIT_ASSERT_EQUAL(string("/watchtest"), evt.path);
  1061. // Make sure Pings are giving us problems
  1062. sleep(5);
  1063. CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
  1064. stopServer();
  1065. CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk));
  1066. startServer();
  1067. CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForConnected(zk));
  1068. if (isGlobal) {
  1069. testName = "GlobalTest";
  1070. rc = zoo_get_children(zk, "/watchtest", 1, &strings);
  1071. deallocate_String_vector(&strings);
  1072. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1073. blen = sizeof(buf);
  1074. rc = zoo_get(zk, "/watchtest/child", 1, buf, &blen, &stat);
  1075. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1076. rc = zoo_exists(zk, "/watchtest/child2", 1, &stat);
  1077. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1078. } else {
  1079. testName = "LocalTest";
  1080. rc = zoo_wget_children(zk, "/watchtest", watcher, ctxLocal,
  1081. &strings);
  1082. deallocate_String_vector(&strings);
  1083. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1084. blen = sizeof(buf);
  1085. rc = zoo_wget(zk, "/watchtest/child", watcher, ctxLocal,
  1086. buf, &blen, &stat);
  1087. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1088. rc = zoo_wexists(zk, "/watchtest/child2", watcher, ctxLocal,
  1089. &stat);
  1090. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1091. }
  1092. zoo_delete(zk, "/watchtest/child2", -1);
  1093. CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
  1094. evt = ctxLocal->getEvent();
  1095. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
  1096. CPPUNIT_ASSERT_EQUAL(string("/watchtest/child2"), evt.path);
  1097. CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
  1098. evt = ctxLocal->getEvent();
  1099. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_CHILD_EVENT, evt.type);
  1100. CPPUNIT_ASSERT_EQUAL(string("/watchtest"), evt.path);
  1101. stopServer();
  1102. CPPUNIT_ASSERT_MESSAGE(testName, ctxGlobal->waitForDisconnected(zk));
  1103. startServer();
  1104. CPPUNIT_ASSERT_MESSAGE(testName, ctxLocal->waitForConnected(zk));
  1105. zoo_delete(zk, "/watchtest/child", -1);
  1106. zoo_delete(zk, "/watchtest", -1);
  1107. CPPUNIT_ASSERT_MESSAGE(testName, waitForEvent(zk, ctxLocal, 5));
  1108. evt = ctxLocal->getEvent();
  1109. CPPUNIT_ASSERT_EQUAL_MESSAGE(evt.path, ZOO_DELETED_EVENT, evt.type);
  1110. CPPUNIT_ASSERT_EQUAL(string("/watchtest/child"), evt.path);
  1111. // Make sure nothing is straggling
  1112. sleep(1);
  1113. CPPUNIT_ASSERT(ctxLocal->countEvents() == 0);
  1114. }
  1115. void testWatcherAutoResetWithGlobal()
  1116. {
  1117. {
  1118. watchctx_t ctx;
  1119. zhandle_t *zk = createClient(&ctx);
  1120. int rc = zoo_create(zk, "/testarwg", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1121. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  1122. rc = zoo_create(zk, "/testarwg/arwg", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1123. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  1124. }
  1125. {
  1126. watchctx_t ctx;
  1127. zhandle_t *zk = createchClient(&ctx, "127.0.0.1:22181/testarwg/arwg");
  1128. testWatcherAutoReset(zk, &ctx, &ctx);
  1129. }
  1130. }
  1131. void testWatcherAutoResetWithLocal()
  1132. {
  1133. {
  1134. watchctx_t ctx;
  1135. zhandle_t *zk = createClient(&ctx);
  1136. int rc = zoo_create(zk, "/testarwl", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1137. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  1138. rc = zoo_create(zk, "/testarwl/arwl", "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1139. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  1140. }
  1141. {
  1142. watchctx_t ctx;
  1143. watchctx_t lctx;
  1144. zhandle_t *zk = createchClient(&ctx, "127.0.0.1:22181/testarwl/arwl");
  1145. testWatcherAutoReset(zk, &ctx, &lctx);
  1146. }
  1147. }
  1148. void testLastZxid() {
  1149. // ZOOKEEPER-1417: Test that c-client only update last zxid upon
  1150. // receiving request response only.
  1151. const int timeout = 5000;
  1152. int rc;
  1153. watchctx_t ctx1, ctx2;
  1154. zhandle_t *zk1 = createClient(&ctx1);
  1155. zhandle_t *zk2 = createClient(&ctx2);
  1156. CPPUNIT_ASSERT(zk1);
  1157. CPPUNIT_ASSERT(zk2);
  1158. int64_t original = zk2->last_zxid;
  1159. // Create txn to increase system zxid
  1160. rc = zoo_create(zk1, "/lastzxid", "", 0,
  1161. &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1162. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1163. // This should be enough time for zk2 to receive ping request
  1164. usleep(timeout/2 * 1000);
  1165. // check that zk1's last zxid is updated
  1166. struct Stat stat;
  1167. rc = zoo_exists(zk1, "/lastzxid", 0, &stat);
  1168. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  1169. CPPUNIT_ASSERT_EQUAL((int64_t) zk1->last_zxid, stat.czxid);
  1170. // zk2's last zxid should remain the same
  1171. CPPUNIT_ASSERT_EQUAL(original, (int64_t) zk2->last_zxid);
  1172. // Perform read and also register a watch
  1173. rc = zoo_wexists(zk2, "/lastzxid", watcher, &ctx2, &stat);
  1174. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  1175. int64_t updated = zk2->last_zxid;
  1176. // check that zk2's last zxid is updated
  1177. CPPUNIT_ASSERT_EQUAL(updated, stat.czxid);
  1178. // Increment system zxid again
  1179. rc = zoo_set(zk1, "/lastzxid", NULL, -1, -1);
  1180. CPPUNIT_ASSERT_EQUAL((int) ZOK, rc);
  1181. // Wait for zk2 to get watch event
  1182. CPPUNIT_ASSERT(waitForEvent(zk2, &ctx2, 5));
  1183. // zk2's last zxid should remain the same
  1184. CPPUNIT_ASSERT_EQUAL(updated, (int64_t) zk2->last_zxid);
  1185. }
  1186. static void watcher_rw(zhandle_t *zh,
  1187. int type,
  1188. int state,
  1189. const char *path,
  1190. void *ctx) {
  1191. count++;
  1192. }
  1193. static void watcher_rw2(zhandle_t *zh,
  1194. int type,
  1195. int state,
  1196. const char *path,
  1197. void *ctx) {
  1198. count++;
  1199. }
  1200. void testRemoveWatchers() {
  1201. char *path = "/something";
  1202. char buf[1024];
  1203. int blen = sizeof(buf);
  1204. int rc;
  1205. watchctx_t ctx;
  1206. zhandle_t *zk;
  1207. /* setup path */
  1208. zk = createClient(&ctx);
  1209. CPPUNIT_ASSERT(zk);
  1210. rc = zoo_create(zk, path, "", 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1211. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1212. rc = zoo_create(zk, "/something2", "", 0,
  1213. &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
  1214. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1215. /* remove all watchers */
  1216. count = 0;
  1217. rc = zoo_wget(zk, path, watcher_rw, NULL, buf, &blen, NULL);
  1218. rc = zoo_wget(zk, path, watcher_rw2, NULL, buf, &blen, NULL);
  1219. rc = zoo_remove_all_watches(zk, path, ZWATCHTYPE_ANY, 0);
  1220. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1221. rc = zoo_set(zk, path, "nowatch", 7, -1);
  1222. CPPUNIT_ASSERT(count == 0);
  1223. /* remove a specific watcher before it's added (should fail) */
  1224. rc = zoo_remove_watches(zk, path, ZWATCHTYPE_DATA,
  1225. watcher_rw, NULL, 0);
  1226. CPPUNIT_ASSERT_EQUAL((int)ZNOWATCHER, rc);
  1227. /* now add a specific watcher and then remove it */
  1228. rc = zoo_wget(zk, path, watcher_rw, NULL,
  1229. buf, &blen, NULL);
  1230. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1231. rc = zoo_remove_watches(zk, path, ZWATCHTYPE_DATA,
  1232. watcher_rw, NULL, 0);
  1233. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1234. /* ditto for children watcher */
  1235. rc = zoo_remove_watches(zk, path, ZWATCHTYPE_CHILD,
  1236. watcher_rw, NULL, 0);
  1237. CPPUNIT_ASSERT_EQUAL((int)ZNOWATCHER, rc);
  1238. struct String_vector str_vec = {0, NULL};
  1239. rc = zoo_wget_children(zk, path, watcher_rw, NULL,
  1240. &str_vec);
  1241. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1242. rc = zoo_remove_watches(zk, path, ZWATCHTYPE_CHILD,
  1243. watcher_rw, NULL, 0);
  1244. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1245. /* add a watch, stop the server, and have remove fail */
  1246. rc = zoo_wget(zk, path, watcher_rw, NULL,
  1247. buf, &blen, NULL);
  1248. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1249. stopServer();
  1250. ctx.waitForDisconnected(zk);
  1251. rc = zoo_remove_watches(zk, path, ZWATCHTYPE_DATA,
  1252. watcher_rw, NULL, 0);
  1253. CPPUNIT_ASSERT_EQUAL((int)ZCONNECTIONLOSS, rc);
  1254. zookeeper_close(zk);
  1255. /* bring the server back */
  1256. startServer();
  1257. zk = createClient(&ctx);
  1258. /* add a watch, stop the server, and remove it locally */
  1259. void* ctx1=(void*)0x1;
  1260. void* ctx2=(void*)0x2;
  1261. rc = zoo_wget(zk, path, watcher_rw, ctx1,
  1262. buf, &blen, NULL);
  1263. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1264. rc = zoo_wget(zk, "/something2", watcher_rw, ctx2,
  1265. buf, &blen, NULL);
  1266. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1267. stopServer();
  1268. rc = zoo_remove_watches(zk, path, ZWATCHTYPE_DATA,
  1269. watcher_rw, ctx1, 1);
  1270. CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
  1271. rc = zoo_remove_watches(zk, path, ZWATCHTYPE_DATA,
  1272. watcher_rw, ctx1, 1);
  1273. CPPUNIT_ASSERT_EQUAL((int)ZNOWATCHER, rc);
  1274. rc = zoo_remove_watches(zk, "/something2", ZWATCHTYPE_DATA,
  1275. watcher_rw, ctx2, 1);
  1276. CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
  1277. }
  1278. };
  1279. volatile int Zookeeper_simpleSystem::count;
  1280. zhandle_t *Zookeeper_simpleSystem::async_zk;
  1281. const char Zookeeper_simpleSystem::hostPorts[] = "127.0.0.1:22181";
  1282. CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_simpleSystem);
  1283. #endif