Kitxuuu commited on
Commit
bd94260
·
verified ·
1 Parent(s): 6b535d6

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/INSTALL +234 -0
  2. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/LICENSE +385 -0
  3. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/Makefile.am +160 -0
  4. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/NOTICE.txt +41 -0
  5. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/recordio.h +80 -0
  6. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/win_getopt.h +674 -0
  7. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/zookeeper.h +0 -0
  8. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/zookeeper_version.h +31 -0
  9. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/CppAssertHelper.h +37 -0
  10. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/LibCMocks.h +408 -0
  11. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/LibCSymTable.cc +87 -0
  12. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/MocksBase.h +36 -0
  13. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/PthreadMocks.cc +106 -0
  14. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestLogClientEnv.cc +59 -0
  15. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestReadOnlyClient.cc +171 -0
  16. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestSASLAuth.cc +290 -0
  17. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestZookeeperClose.cc +473 -0
  18. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/ThreadingUtil.cc +87 -0
  19. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/Util.h +137 -0
  20. local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/zoo.cfg +15 -0
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/INSTALL ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Installation Instructions
2
+ *************************
3
+
4
+ Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
5
+ 2006 Free Software Foundation, Inc.
6
+
7
+ This file is free documentation; the Free Software Foundation gives
8
+ unlimited permission to copy, distribute and modify it.
9
+
10
+ Basic Installation
11
+ ==================
12
+
13
+ Briefly, the shell commands `./configure; make; make install' should
14
+ configure, build, and install this package. The following
15
+ more-detailed instructions are generic; see the `README' file for
16
+ instructions specific to this package.
17
+
18
+ The `configure' shell script attempts to guess correct values for
19
+ various system-dependent variables used during compilation. It uses
20
+ those values to create a `Makefile' in each directory of the package.
21
+ It may also create one or more `.h' files containing system-dependent
22
+ definitions. Finally, it creates a shell script `config.status' that
23
+ you can run in the future to recreate the current configuration, and a
24
+ file `config.log' containing compiler output (useful mainly for
25
+ debugging `configure').
26
+
27
+ It can also use an optional file (typically called `config.cache'
28
+ and enabled with `--cache-file=config.cache' or simply `-C') that saves
29
+ the results of its tests to speed up reconfiguring. Caching is
30
+ disabled by default to prevent problems with accidental use of stale
31
+ cache files.
32
+
33
+ If you need to do unusual things to compile the package, please try
34
+ to figure out how `configure' could check whether to do them, and mail
35
+ diffs or instructions to the address given in the `README' so they can
36
+ be considered for the next release. If you are using the cache, and at
37
+ some point `config.cache' contains results you don't want to keep, you
38
+ may remove or edit it.
39
+
40
+ The file `configure.ac' (or `configure.in') is used to create
41
+ `configure' by a program called `autoconf'. You need `configure.ac' if
42
+ you want to change it or regenerate `configure' using a newer version
43
+ of `autoconf'.
44
+
45
+ The simplest way to compile this package is:
46
+
47
+ 1. `cd' to the directory containing the package's source code and type
48
+ `./configure' to configure the package for your system.
49
+
50
+ Running `configure' might take a while. While running, it prints
51
+ some messages telling which features it is checking for.
52
+
53
+ 2. Type `make' to compile the package.
54
+
55
+ 3. Optionally, type `make check' to run any self-tests that come with
56
+ the package.
57
+
58
+ 4. Type `make install' to install the programs and any data files and
59
+ documentation.
60
+
61
+ 5. You can remove the program binaries and object files from the
62
+ source code directory by typing `make clean'. To also remove the
63
+ files that `configure' created (so you can compile the package for
64
+ a different kind of computer), type `make distclean'. There is
65
+ also a `make maintainer-clean' target, but that is intended mainly
66
+ for the package's developers. If you use it, you may have to get
67
+ all sorts of other programs in order to regenerate files that came
68
+ with the distribution.
69
+
70
+ Compilers and Options
71
+ =====================
72
+
73
+ Some systems require unusual options for compilation or linking that the
74
+ `configure' script does not know about. Run `./configure --help' for
75
+ details on some of the pertinent environment variables.
76
+
77
+ You can give `configure' initial values for configuration parameters
78
+ by setting variables in the command line or in the environment. Here
79
+ is an example:
80
+
81
+ ./configure CC=c99 CFLAGS=-g LIBS=-lposix
82
+
83
+ *Note Defining Variables::, for more details.
84
+
85
+ Compiling For Multiple Architectures
86
+ ====================================
87
+
88
+ You can compile the package for more than one kind of computer at the
89
+ same time, by placing the object files for each architecture in their
90
+ own directory. To do this, you can use GNU `make'. `cd' to the
91
+ directory where you want the object files and executables to go and run
92
+ the `configure' script. `configure' automatically checks for the
93
+ source code in the directory that `configure' is in and in `..'.
94
+
95
+ With a non-GNU `make', it is safer to compile the package for one
96
+ architecture at a time in the source code directory. After you have
97
+ installed the package for one architecture, use `make distclean' before
98
+ reconfiguring for another architecture.
99
+
100
+ Installation Names
101
+ ==================
102
+
103
+ By default, `make install' installs the package's commands under
104
+ `/usr/local/bin', include files under `/usr/local/include', etc. You
105
+ can specify an installation prefix other than `/usr/local' by giving
106
+ `configure' the option `--prefix=PREFIX'.
107
+
108
+ You can specify separate installation prefixes for
109
+ architecture-specific files and architecture-independent files. If you
110
+ pass the option `--exec-prefix=PREFIX' to `configure', the package uses
111
+ PREFIX as the prefix for installing programs and libraries.
112
+ Documentation and other data files still use the regular prefix.
113
+
114
+ In addition, if you use an unusual directory layout you can give
115
+ options like `--bindir=DIR' to specify different values for particular
116
+ kinds of files. Run `configure --help' for a list of the directories
117
+ you can set and what kinds of files go in them.
118
+
119
+ If the package supports it, you can cause programs to be installed
120
+ with an extra prefix or suffix on their names by giving `configure' the
121
+ option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
122
+
123
+ Optional Features
124
+ =================
125
+
126
+ Some packages pay attention to `--enable-FEATURE' options to
127
+ `configure', where FEATURE indicates an optional part of the package.
128
+ They may also pay attention to `--with-PACKAGE' options, where PACKAGE
129
+ is something like `gnu-as' or `x' (for the X Window System). The
130
+ `README' should mention any `--enable-' and `--with-' options that the
131
+ package recognizes.
132
+
133
+ For packages that use the X Window System, `configure' can usually
134
+ find the X include and library files automatically, but if it doesn't,
135
+ you can use the `configure' options `--x-includes=DIR' and
136
+ `--x-libraries=DIR' to specify their locations.
137
+
138
+ Specifying the System Type
139
+ ==========================
140
+
141
+ There may be some features `configure' cannot figure out automatically,
142
+ but needs to determine by the type of machine the package will run on.
143
+ Usually, assuming the package is built to be run on the _same_
144
+ architectures, `configure' can figure that out, but if it prints a
145
+ message saying it cannot guess the machine type, give it the
146
+ `--build=TYPE' option. TYPE can either be a short name for the system
147
+ type, such as `sun4', or a canonical name which has the form:
148
+
149
+ CPU-COMPANY-SYSTEM
150
+
151
+ where SYSTEM can have one of these forms:
152
+
153
+ OS KERNEL-OS
154
+
155
+ See the file `config.sub' for the possible values of each field. If
156
+ `config.sub' isn't included in this package, then this package doesn't
157
+ need to know the machine type.
158
+
159
+ If you are _building_ compiler tools for cross-compiling, you should
160
+ use the option `--target=TYPE' to select the type of system they will
161
+ produce code for.
162
+
163
+ If you want to _use_ a cross compiler, that generates code for a
164
+ platform different from the build platform, you should specify the
165
+ "host" platform (i.e., that on which the generated programs will
166
+ eventually be run) with `--host=TYPE'.
167
+
168
+ Sharing Defaults
169
+ ================
170
+
171
+ If you want to set default values for `configure' scripts to share, you
172
+ can create a site shell script called `config.site' that gives default
173
+ values for variables like `CC', `cache_file', and `prefix'.
174
+ `configure' looks for `PREFIX/share/config.site' if it exists, then
175
+ `PREFIX/etc/config.site' if it exists. Or, you can set the
176
+ `CONFIG_SITE' environment variable to the location of the site script.
177
+ A warning: not all `configure' scripts look for a site script.
178
+
179
+ Defining Variables
180
+ ==================
181
+
182
+ Variables not defined in a site shell script can be set in the
183
+ environment passed to `configure'. However, some packages may run
184
+ configure again during the build, and the customized values of these
185
+ variables may be lost. In order to avoid this problem, you should set
186
+ them in the `configure' command line, using `VAR=value'. For example:
187
+
188
+ ./configure CC=/usr/local2/bin/gcc
189
+
190
+ causes the specified `gcc' to be used as the C compiler (unless it is
191
+ overridden in the site shell script).
192
+
193
+ Unfortunately, this technique does not work for `CONFIG_SHELL' due to
194
+ an Autoconf bug. Until the bug is fixed you can use this workaround:
195
+
196
+ CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
197
+
198
+ `configure' Invocation
199
+ ======================
200
+
201
+ `configure' recognizes the following options to control how it operates.
202
+
203
+ `--help'
204
+ `-h'
205
+ Print a summary of the options to `configure', and exit.
206
+
207
+ `--version'
208
+ `-V'
209
+ Print the version of Autoconf used to generate the `configure'
210
+ script, and exit.
211
+
212
+ `--cache-file=FILE'
213
+ Enable the cache: use and save the results of the tests in FILE,
214
+ traditionally `config.cache'. FILE defaults to `/dev/null' to
215
+ disable caching.
216
+
217
+ `--config-cache'
218
+ `-C'
219
+ Alias for `--cache-file=config.cache'.
220
+
221
+ `--quiet'
222
+ `--silent'
223
+ `-q'
224
+ Do not print messages saying which checks are being made. To
225
+ suppress all normal output, redirect it to `/dev/null' (any error
226
+ messages will still be shown).
227
+
228
+ `--srcdir=DIR'
229
+ Look for the package's source code in directory DIR. Usually
230
+ `configure' can determine that directory automatically.
231
+
232
+ `configure' also accepts some other, not widely useful, options. Run
233
+ `configure --help' for more details.
234
+
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/LICENSE ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+
205
+
206
+ ===========================================================================================
207
+ === The following part contains the dual OpenSSL and SSLeay license ===
208
+ === for OpenSSL versions 1.1.1, 1.1.0, 1.0.2 and all prior releases ===
209
+ === (see https://www.openssl.org/source/license.html) ===
210
+ ===========================================================================================
211
+
212
+
213
+ LICENSE ISSUES
214
+ ==============
215
+
216
+ The OpenSSL toolkit stays under a double license, i.e. both the conditions of
217
+ the OpenSSL License and the original SSLeay license apply to the toolkit.
218
+ See below for the actual license texts.
219
+
220
+ OpenSSL License
221
+ ---------------
222
+
223
+ /* ====================================================================
224
+ * Copyright (c) 1998-2019 The OpenSSL Project. All rights reserved.
225
+ *
226
+ * Redistribution and use in source and binary forms, with or without
227
+ * modification, are permitted provided that the following conditions
228
+ * are met:
229
+ *
230
+ * 1. Redistributions of source code must retain the above copyright
231
+ * notice, this list of conditions and the following disclaimer.
232
+ *
233
+ * 2. Redistributions in binary form must reproduce the above copyright
234
+ * notice, this list of conditions and the following disclaimer in
235
+ * the documentation and/or other materials provided with the
236
+ * distribution.
237
+ *
238
+ * 3. All advertising materials mentioning features or use of this
239
+ * software must display the following acknowledgment:
240
+ * "This product includes software developed by the OpenSSL Project
241
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
242
+ *
243
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
244
+ * endorse or promote products derived from this software without
245
+ * prior written permission. For written permission, please contact
246
+ * openssl-core@openssl.org.
247
+ *
248
+ * 5. Products derived from this software may not be called "OpenSSL"
249
+ * nor may "OpenSSL" appear in their names without prior written
250
+ * permission of the OpenSSL Project.
251
+ *
252
+ * 6. Redistributions of any form whatsoever must retain the following
253
+ * acknowledgment:
254
+ * "This product includes software developed by the OpenSSL Project
255
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
256
+ *
257
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
258
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
259
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
260
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
261
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
262
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
263
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
264
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
265
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
266
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
267
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
268
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
269
+ * ====================================================================
270
+ *
271
+ * This product includes cryptographic software written by Eric Young
272
+ * (eay@cryptsoft.com). This product includes software written by Tim
273
+ * Hudson (tjh@cryptsoft.com).
274
+ *
275
+ */
276
+
277
+ Original SSLeay License
278
+ -----------------------
279
+
280
+ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
281
+ * All rights reserved.
282
+ *
283
+ * This package is an SSL implementation written
284
+ * by Eric Young (eay@cryptsoft.com).
285
+ * The implementation was written so as to conform with Netscapes SSL.
286
+ *
287
+ * This library is free for commercial and non-commercial use as long as
288
+ * the following conditions are adhered to. The following conditions
289
+ * apply to all code found in this distribution, be it the RC4, RSA,
290
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
291
+ * included with this distribution is covered by the same copyright terms
292
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
293
+ *
294
+ * Copyright remains Eric Young's, and as such any Copyright notices in
295
+ * the code are not to be removed.
296
+ * If this package is used in a product, Eric Young should be given attribution
297
+ * as the author of the parts of the library used.
298
+ * This can be in the form of a textual message at program startup or
299
+ * in documentation (online or textual) provided with the package.
300
+ *
301
+ * Redistribution and use in source and binary forms, with or without
302
+ * modification, are permitted provided that the following conditions
303
+ * are met:
304
+ * 1. Redistributions of source code must retain the copyright
305
+ * notice, this list of conditions and the following disclaimer.
306
+ * 2. Redistributions in binary form must reproduce the above copyright
307
+ * notice, this list of conditions and the following disclaimer in the
308
+ * documentation and/or other materials provided with the distribution.
309
+ * 3. All advertising materials mentioning features or use of this software
310
+ * must display the following acknowledgement:
311
+ * "This product includes cryptographic software written by
312
+ * Eric Young (eay@cryptsoft.com)"
313
+ * The word 'cryptographic' can be left out if the routines from the library
314
+ * being used are not cryptographic related :-).
315
+ * 4. If you include any Windows specific code (or a derivative thereof) from
316
+ * the apps directory (application code) you must include an acknowledgement:
317
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
318
+ *
319
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
320
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
321
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
322
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
323
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
324
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
325
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
326
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
327
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
328
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
329
+ * SUCH DAMAGE.
330
+ *
331
+ * The licence and distribution terms for any publicly available version or
332
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
333
+ * copied and put under another distribution licence
334
+ * [including the GNU Public Licence.]
335
+ */
336
+
337
+ ===========================================================================================
338
+ === The following part contains the license for the Cyrus SASL 2.x library ===
339
+ === used for optional SASL support ===
340
+ ===========================================================================================
341
+
342
+ /* CMU libsasl
343
+ * Tim Martin
344
+ * Rob Earhart
345
+ * Rob Siemborski
346
+ */
347
+ /*
348
+ * Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved.
349
+ *
350
+ * Redistribution and use in source and binary forms, with or without
351
+ * modification, are permitted provided that the following conditions
352
+ * are met:
353
+ *
354
+ * 1. Redistributions of source code must retain the above copyright
355
+ * notice, this list of conditions and the following disclaimer.
356
+ *
357
+ * 2. Redistributions in binary form must reproduce the above copyright
358
+ * notice, this list of conditions and the following disclaimer in
359
+ * the documentation and/or other materials provided with the
360
+ * distribution.
361
+ *
362
+ * 3. The name "Carnegie Mellon University" must not be used to
363
+ * endorse or promote products derived from this software without
364
+ * prior written permission. For permission or any other legal
365
+ * details, please contact
366
+ * Office of Technology Transfer
367
+ * Carnegie Mellon University
368
+ * 5000 Forbes Avenue
369
+ * Pittsburgh, PA 15213-3890
370
+ * (412) 268-4387, fax: (412) 268-7395
371
+ * tech-transfer@andrew.cmu.edu
372
+ *
373
+ * 4. Redistributions of any form whatsoever must retain the following
374
+ * acknowledgment:
375
+ * "This product includes software developed by Computing Services
376
+ * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
377
+ *
378
+ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
379
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
380
+ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
381
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
382
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
383
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
384
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
385
+ */
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/Makefile.am ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # need this for Doxygen integration
2
+ include $(top_srcdir)/aminclude.am
3
+
4
+ AUTOMAKE_OPTIONS = serial-tests
5
+
6
+ if SOLARIS
7
+ SOLARIS_CPPFLAGS = -D_POSIX_PTHREAD_SEMANTICS
8
+ SOLARIS_LIB_LDFLAGS = -lnsl -lsocket
9
+ endif
10
+
11
+ if WANT_OPENSSL
12
+ OPENSSL_CPPFLAGS = -DHAVE_OPENSSL_H
13
+ OPENSSL_LIB_LDFLAGS = -lssl -lcrypto
14
+ endif
15
+
16
+ if WANT_SASL
17
+ SASL_CPPFLAGS = -DHAVE_CYRUS_SASL_H
18
+ SASL_LIB_LDFLAGS = -lsasl2
19
+ SASL_SRC = src/zk_sasl.c
20
+ endif
21
+
22
+ AM_CPPFLAGS = -I${srcdir}/include -I${srcdir}/tests -I${srcdir}/generated $(SOLARIS_CPPFLAGS) $(OPENSSL_CPPFLAGS) $(SASL_CPPFLAGS)
23
+ AM_CFLAGS = -Wall -Werror -Wdeclaration-after-statement
24
+ AM_CXXFLAGS = -Wall $(USEIPV6)
25
+ LIB_LDFLAGS = -no-undefined -version-info 2 $(SOLARIS_LIB_LDFLAGS) $(OPENSSL_LIB_LDFLAGS) $(SASL_LIB_LDFLAGS)
26
+
27
+ # Additional flags for coverage testing (if enabled)
28
+ if ENABLEGCOV
29
+ AM_CFLAGS += -fprofile-arcs -ftest-coverage
30
+ AM_LDFLAGS = -lgcov
31
+ endif
32
+
33
+ pkginclude_HEADERS = include/zookeeper.h include/zookeeper_version.h include/zookeeper_log.h include/proto.h include/recordio.h generated/zookeeper.jute.h
34
+ EXTRA_DIST=LICENSE
35
+
36
+ HASHTABLE_SRC = src/hashtable/hashtable_itr.h src/hashtable/hashtable_itr.c \
37
+ src/hashtable/hashtable_private.h src/hashtable/hashtable.h src/hashtable/hashtable.c
38
+
39
+ noinst_LTLIBRARIES = libhashtable.la
40
+ libhashtable_la_SOURCES = $(HASHTABLE_SRC)
41
+
42
+ COMMON_SRC = src/zookeeper.c include/zookeeper.h include/zookeeper_version.h include/zookeeper_log.h\
43
+ src/recordio.c include/recordio.h include/proto.h \
44
+ src/zk_adaptor.h generated/zookeeper.jute.c \
45
+ src/zk_log.c src/zk_hashtable.h src/zk_hashtable.c \
46
+ src/addrvec.h src/addrvec.c $(SASL_SRC)
47
+
48
+ # These are the symbols (classes, mostly) we want to export from our library.
49
+ EXPORT_SYMBOLS = '(zoo_|zookeeper_|zhandle|Z|format_log_message|log_message|logLevel|deallocate_|allocate_|zerror|is_unrecoverable)'
50
+ noinst_LTLIBRARIES += libzkst.la
51
+ libzkst_la_SOURCES =$(COMMON_SRC) src/st_adaptor.c
52
+ libzkst_la_LIBADD = -lm $(CLOCK_GETTIME_LIBS)
53
+
54
+ lib_LTLIBRARIES = libzookeeper_st.la
55
+ libzookeeper_st_la_SOURCES =
56
+ libzookeeper_st_la_LIBADD=libzkst.la libhashtable.la
57
+ libzookeeper_st_la_DEPENDENCIES=libzkst.la libhashtable.la
58
+ libzookeeper_st_la_LDFLAGS = $(LIB_LDFLAGS) -export-symbols-regex $(EXPORT_SYMBOLS)
59
+
60
+ if WANT_SYNCAPI
61
+ noinst_LTLIBRARIES += libzkmt.la
62
+ libzkmt_la_SOURCES =$(COMMON_SRC) src/mt_adaptor.c
63
+ libzkmt_la_CFLAGS = $(AM_CFLAGS) -DTHREADED
64
+ libzkmt_la_LIBADD = -lm $(CLOCK_GETTIME_LIBS)
65
+
66
+ lib_LTLIBRARIES += libzookeeper_mt.la
67
+ libzookeeper_mt_la_SOURCES =
68
+ libzookeeper_mt_la_LIBADD=libzkmt.la libhashtable.la -lpthread
69
+ libzookeeper_mt_la_DEPENDENCIES=libzkmt.la libhashtable.la
70
+ libzookeeper_mt_la_LDFLAGS = $(LIB_LDFLAGS) -export-symbols-regex $(EXPORT_SYMBOLS)
71
+ endif
72
+
73
+ bin_PROGRAMS = cli_st
74
+
75
+ cli_st_SOURCES = src/cli.c
76
+ cli_st_LDADD = libzookeeper_st.la $(SASL_LIB_LDFLAGS)
77
+
78
+ if WANT_SYNCAPI
79
+ bin_PROGRAMS += cli_mt load_gen
80
+
81
+ cli_mt_SOURCES = src/cli.c
82
+ cli_mt_LDADD = libzookeeper_mt.la $(SASL_LIB_LDFLAGS)
83
+ cli_mt_CFLAGS = $(AM_CFLAGS) -DTHREADED
84
+
85
+ load_gen_SOURCES = src/load_gen.c
86
+ load_gen_LDADD = libzookeeper_mt.la
87
+ load_gen_CFLAGS = $(AM_CFLAGS) -DTHREADED
88
+
89
+ endif
90
+
91
+ #########################################################################
92
+ # build and run unit tests
93
+
94
+ EXTRA_DIST+=$(wildcard ${srcdir}/tests/*.cc) $(wildcard ${srcdir}/tests/*.h) \
95
+ ${srcdir}/tests/wrappers.opt ${srcdir}/tests/wrappers-mt.opt
96
+
97
+ # These tests are ordered in a logical manner such that each builds upon basic
98
+ # functionality tested in prior tests. e.g. the most basic functionality is
99
+ # tested in TestZookeeperInit and TestZookeeperClose and as such should be tested
100
+ # first as a foundation with more complex test suites to follow.
101
+ TEST_SOURCES = \
102
+ tests/TestDriver.cc \
103
+ tests/LibCMocks.cc \
104
+ tests/LibCSymTable.cc \
105
+ tests/MocksBase.cc \
106
+ tests/ZKMocks.cc \
107
+ tests/Util.cc \
108
+ tests/ThreadingUtil.cc \
109
+ tests/TestZookeeperInit.cc \
110
+ tests/TestZookeeperClose.cc \
111
+ tests/TestReconfig.cc \
112
+ tests/TestReconfigServer.cc \
113
+ tests/TestClientRetry.cc \
114
+ tests/TestOperations.cc \
115
+ tests/TestMulti.cc \
116
+ tests/TestWatchers.cc \
117
+ tests/TestClient.cc \
118
+ tests/ZooKeeperQuorumServer.cc \
119
+ tests/ZooKeeperQuorumServer.h \
120
+ tests/TestReadOnlyClient.cc \
121
+ tests/TestLogClientEnv.cc \
122
+ tests/TestSASLAuth.cc \
123
+ $(NULL)
124
+
125
+ if SOLARIS
126
+ SHELL_SYMBOL_WRAPPERS = cat ${srcdir}/tests/wrappers.opt
127
+ SYMBOL_WRAPPERS=$(SHELL_SYMBOL_WRAPPERS:sh)
128
+ else
129
+ SYMBOL_WRAPPERS=$(shell cat ${srcdir}/tests/wrappers.opt)
130
+ endif
131
+
132
+ check_PROGRAMS = zktest-st
133
+ TESTS_ENVIRONMENT = ZKROOT=${srcdir}/../.. \
134
+ CLASSPATH=$$CLASSPATH:$$CLOVER_HOME/lib/clover*.jar
135
+ nodist_zktest_st_SOURCES = $(TEST_SOURCES)
136
+ zktest_st_LDADD = libzkst.la libhashtable.la $(CPPUNIT_LIBS) $(OPENSSL_LIB_LDFLAGS) $(SASL_LIB_LDFLAGS) -ldl
137
+ zktest_st_CXXFLAGS = $(AM_CXXFLAGS) -DUSE_STATIC_LIB $(CPPUNIT_CFLAGS) $(SOLARIS_CPPFLAGS)
138
+ zktest_st_LDFLAGS = -shared $(SYMBOL_WRAPPERS) $(SOLARIS_LIB_LDFLAGS)
139
+
140
+ if WANT_SYNCAPI
141
+ check_PROGRAMS += zktest-mt
142
+ nodist_zktest_mt_SOURCES = $(TEST_SOURCES) tests/PthreadMocks.cc
143
+ zktest_mt_LDADD = libzkmt.la libhashtable.la -lpthread $(CPPUNIT_LIBS) $(OPENSSL_LIB_LDFLAGS) $(SASL_LIB_LDFLAGS) -ldl
144
+ zktest_mt_CXXFLAGS = $(AM_CXXFLAGS) -DUSE_STATIC_LIB -DTHREADED $(CPPUNIT_CFLAGS) $(USEIPV6)
145
+ if SOLARIS
146
+ SHELL_SYMBOL_WRAPPERS_MT = cat ${srcdir}/tests/wrappers-mt.opt
147
+ SYMBOL_WRAPPERS_MT=$(SYMBOL_WRAPPERS) $(SHELL_SYMBOL_WRAPPERS_MT:sh)
148
+ else
149
+ SYMBOL_WRAPPERS_MT=$(SYMBOL_WRAPPERS) $(shell cat ${srcdir}/tests/wrappers-mt.opt)
150
+ endif
151
+ zktest_mt_LDFLAGS = -shared $(SYMBOL_WRAPPERS_MT) $(SOLARIS_LIB_LDFLAGS)
152
+ endif
153
+
154
+ TESTS = $(check_PROGRAMS)
155
+
156
+ clean-local: clean-check
157
+ $(RM) $(DX_CLEANFILES)
158
+
159
+ clean-check:
160
+ $(RM) $(nodist_zktest_st_OBJECTS) $(nodist_zktest_mt_OBJECTS)
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/NOTICE.txt ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache ZooKeeper
2
+ Copyright 2009-2011 The Apache Software Foundation
3
+
4
+ This product includes software developed at
5
+ The Apache Software Foundation (http://www.apache.org/).
6
+
7
+ ----------
8
+ include/winstdint.h is included only for Windows Client support, as follows:
9
+
10
+ // ISO C9x compliant stdint.h for Microsoft Visual Studio
11
+ // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
12
+ //
13
+ // Copyright (c) 2006-2008 Alexander Chemeris
14
+ //
15
+ // Redistribution and use in source and binary forms, with or without
16
+ // modification, are permitted provided that the following conditions are met:
17
+ //
18
+ // 1. Redistributions of source code must retain the above copyright notice,
19
+ // this list of conditions and the following disclaimer.
20
+ //
21
+ // 2. Redistributions in binary form must reproduce the above copyright
22
+ // notice, this list of conditions and the following disclaimer in the
23
+ // documentation and/or other materials provided with the distribution.
24
+ //
25
+ // 3. The name of the author may be used to endorse or promote products
26
+ // derived from this software without specific prior written permission.
27
+ //
28
+ // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
29
+ // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30
+ // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
31
+ // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34
+ // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35
+ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36
+ // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37
+ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
+ //
39
+ ///////////////////////////////////////////////////////////////////////////////
40
+
41
+ ----------
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/recordio.h ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #ifndef __RECORDIO_H__
19
+ #define __RECORDIO_H__
20
+
21
+ #include <sys/types.h>
22
+ #include <stdint.h> /* for int64_t */
23
+ #ifdef WIN32
24
+ #include "winconfig.h"
25
+ #endif
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ struct buffer {
32
+ int32_t len;
33
+ char *buff;
34
+ };
35
+
36
+ void deallocate_String(char **s);
37
+ void deallocate_Buffer(struct buffer *b);
38
+ void deallocate_vector(void *d);
39
+ struct iarchive {
40
+ int (*start_record)(struct iarchive *ia, const char *tag);
41
+ int (*end_record)(struct iarchive *ia, const char *tag);
42
+ int (*start_vector)(struct iarchive *ia, const char *tag, int32_t *count);
43
+ int (*end_vector)(struct iarchive *ia, const char *tag);
44
+ int (*deserialize_Bool)(struct iarchive *ia, const char *name, int32_t *);
45
+ int (*deserialize_Int)(struct iarchive *ia, const char *name, int32_t *);
46
+ int (*deserialize_Long)(struct iarchive *ia, const char *name, int64_t *);
47
+ int (*deserialize_Buffer)(struct iarchive *ia, const char *name,
48
+ struct buffer *);
49
+ int (*deserialize_String)(struct iarchive *ia, const char *name, char **);
50
+ void *priv;
51
+ };
52
+ struct oarchive {
53
+ int (*start_record)(struct oarchive *oa, const char *tag);
54
+ int (*end_record)(struct oarchive *oa, const char *tag);
55
+ int (*start_vector)(struct oarchive *oa, const char *tag, const int32_t *count);
56
+ int (*end_vector)(struct oarchive *oa, const char *tag);
57
+ int (*serialize_Bool)(struct oarchive *oa, const char *name, const int32_t *);
58
+ int (*serialize_Int)(struct oarchive *oa, const char *name, const int32_t *);
59
+ int (*serialize_Long)(struct oarchive *oa, const char *name,
60
+ const int64_t *);
61
+ int (*serialize_Buffer)(struct oarchive *oa, const char *name,
62
+ const struct buffer *);
63
+ int (*serialize_String)(struct oarchive *oa, const char *name, char **);
64
+ void *priv;
65
+ };
66
+
67
+ struct oarchive *create_buffer_oarchive(void);
68
+ void close_buffer_oarchive(struct oarchive **oa, int free_buffer);
69
+ struct iarchive *create_buffer_iarchive(char *buffer, int len);
70
+ void close_buffer_iarchive(struct iarchive **ia);
71
+ char *get_buffer(struct oarchive *);
72
+ int get_buffer_len(struct oarchive *);
73
+
74
+ int64_t zoo_htonll(int64_t v);
75
+
76
+ #ifdef __cplusplus
77
+ }
78
+ #endif
79
+
80
+ #endif
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/win_getopt.h ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ /**
20
+ * DISCLAIMER
21
+ * This file is part of the mingw-w64 runtime package.
22
+ *
23
+ * The mingw-w64 runtime package and its code is distributed in the hope that it
24
+ * will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
25
+ * IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
26
+ * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27
+ */
28
+
29
+ /*
30
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
31
+ *
32
+ * Permission to use, copy, modify, and distribute this software for any
33
+ * purpose with or without fee is hereby granted, provided that the above
34
+ * copyright notice and this permission notice appear in all copies.
35
+ *
36
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43
+ *
44
+ * Sponsored in part by the Defense Advanced Research Projects
45
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
46
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
47
+ */
48
+
49
+ /*-
50
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
51
+ * All rights reserved.
52
+ *
53
+ * This code is derived from software contributed to The NetBSD Foundation
54
+ * by Dieter Baron and Thomas Klausner.
55
+ *
56
+ * Redistribution and use in source and binary forms, with or without
57
+ * modification, are permitted provided that the following conditions
58
+ * are met:
59
+ * 1. Redistributions of source code must retain the above copyright
60
+ * notice, this list of conditions and the following disclaimer.
61
+ * 2. Redistributions in binary form must reproduce the above copyright
62
+ * notice, this list of conditions and the following disclaimer in the
63
+ * documentation and/or other materials provided with the distribution.
64
+ *
65
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
66
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
67
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
68
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
69
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
70
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
71
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
72
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
73
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
74
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
75
+ * POSSIBILITY OF SUCH DAMAGE.
76
+ */
77
+
78
+ #ifndef __GETOPT_H__
79
+
80
+ #pragma warning(disable:4996);
81
+
82
+ #define __GETOPT_H__
83
+
84
+ /* All the headers include this file. */
85
+ #include <crtdefs.h>
86
+ #include <errno.h>
87
+ #include <stdlib.h>
88
+ #include <string.h>
89
+ #include <stdarg.h>
90
+ #include <stdio.h>
91
+ #include <windows.h>
92
+
93
+ #ifdef __cplusplus
94
+ extern "C" {
95
+ #endif
96
+
97
+ #define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
98
+
99
+ #ifdef REPLACE_GETOPT
100
+ int opterr = 1; /* if error message should be printed */
101
+ int optind = 1; /* index into parent argv vector */
102
+ int optopt = '?'; /* character checked for validity */
103
+ #undef optreset /* see getopt.h */
104
+ #define optreset __mingw_optreset
105
+ int optreset; /* reset getopt */
106
+ char *optarg; /* argument associated with option */
107
+ #endif
108
+
109
+ //extern int optind; /* index of first non-option in argv */
110
+ //extern int optopt; /* single option character, as parsed */
111
+ //extern int opterr; /* flag to enable built-in diagnostics... */
112
+ // /* (user may set to zero, to suppress) */
113
+ //
114
+ //extern char *optarg; /* pointer to argument of current option */
115
+
116
+ #define PRINT_ERROR ((opterr) && (*options != ':'))
117
+
118
+ #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
119
+ #define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
120
+ #define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
121
+
122
+ /* return values */
123
+ #define BADCH (int)'?'
124
+ #define BADARG ((*options == ':') ? (int)':' : (int)'?')
125
+ #define INORDER (int)1
126
+
127
+ #ifndef __CYGWIN__
128
+ #define __progname __argv[0]
129
+ #else
130
+ extern char __declspec(dllimport) *__progname;
131
+ #endif
132
+
133
+ #ifdef __CYGWIN__
134
+ static char EMSG[] = "";
135
+ #else
136
+ #define EMSG ""
137
+ #endif
138
+
139
+ static int getopt_internal(int, char * const *, const char *,
140
+ const struct option *, int *, int);
141
+ static int parse_long_options(char * const *, const char *,
142
+ const struct option *, int *, int);
143
+ static int gcd(int, int);
144
+ static void permute_args(int, int, int, char * const *);
145
+
146
+ static char *place = EMSG; /* option letter processing */
147
+
148
+ /* XXX: set optreset to 1 rather than these two */
149
+ static int nonopt_start = -1; /* first non option argument (for permute) */
150
+ static int nonopt_end = -1; /* first option after non options (for permute) */
151
+
152
+ /* Error messages */
153
+ static const char recargchar[] = "option requires an argument -- %c";
154
+ static const char recargstring[] = "option requires an argument -- %s";
155
+ static const char ambig[] = "ambiguous option -- %.*s";
156
+ static const char noarg[] = "option doesn't take an argument -- %.*s";
157
+ static const char illoptchar[] = "unknown option -- %c";
158
+ static const char illoptstring[] = "unknown option -- %s";
159
+
160
+ static void
161
+ _vwarnx(const char *fmt,va_list ap)
162
+ {
163
+ (void)fprintf(stderr,"%s: ",__progname);
164
+ if (fmt != NULL)
165
+ (void)vfprintf(stderr,fmt,ap);
166
+ (void)fprintf(stderr,"\n");
167
+ }
168
+
169
+ static void
170
+ warnx(const char *fmt,...)
171
+ {
172
+ va_list ap;
173
+ va_start(ap,fmt);
174
+ _vwarnx(fmt,ap);
175
+ va_end(ap);
176
+ }
177
+
178
+ /*
179
+ * Compute the greatest common divisor of a and b.
180
+ */
181
+ static int
182
+ gcd(int a, int b)
183
+ {
184
+ int c;
185
+
186
+ c = a % b;
187
+ while (c != 0) {
188
+ a = b;
189
+ b = c;
190
+ c = a % b;
191
+ }
192
+
193
+ return (b);
194
+ }
195
+
196
+ /*
197
+ * Exchange the block from nonopt_start to nonopt_end with the block
198
+ * from nonopt_end to opt_end (keeping the same order of arguments
199
+ * in each block).
200
+ */
201
+ static void
202
+ permute_args(int panonopt_start, int panonopt_end, int opt_end,
203
+ char * const *nargv)
204
+ {
205
+ int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
206
+ char *swap;
207
+
208
+ /*
209
+ * compute lengths of blocks and number and size of cycles
210
+ */
211
+ nnonopts = panonopt_end - panonopt_start;
212
+ nopts = opt_end - panonopt_end;
213
+ ncycle = gcd(nnonopts, nopts);
214
+ cyclelen = (opt_end - panonopt_start) / ncycle;
215
+
216
+ for (i = 0; i < ncycle; i++) {
217
+ cstart = panonopt_end+i;
218
+ pos = cstart;
219
+ for (j = 0; j < cyclelen; j++) {
220
+ if (pos >= panonopt_end)
221
+ pos -= nnonopts;
222
+ else
223
+ pos += nopts;
224
+ swap = nargv[pos];
225
+ /* LINTED const cast */
226
+ ((char **) nargv)[pos] = nargv[cstart];
227
+ /* LINTED const cast */
228
+ ((char **)nargv)[cstart] = swap;
229
+ }
230
+ }
231
+ }
232
+
233
+ #ifdef REPLACE_GETOPT
234
+ /*
235
+ * getopt --
236
+ * Parse argc/argv argument vector.
237
+ *
238
+ * [eventually this will replace the BSD getopt]
239
+ */
240
+ int
241
+ getopt(int nargc, char * const *nargv, const char *options)
242
+ {
243
+
244
+ /*
245
+ * We don't pass FLAG_PERMUTE to getopt_internal() since
246
+ * the BSD getopt(3) (unlike GNU) has never done this.
247
+ *
248
+ * Furthermore, since many privileged programs call getopt()
249
+ * before dropping privileges it makes sense to keep things
250
+ * as simple (and bug-free) as possible.
251
+ */
252
+ return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
253
+ }
254
+ #endif /* REPLACE_GETOPT */
255
+
256
+ //extern int getopt(int nargc, char * const *nargv, const char *options);
257
+
258
+ #ifdef _BSD_SOURCE
259
+ /*
260
+ * BSD adds the non-standard `optreset' feature, for reinitialisation
261
+ * of `getopt' parsing. We support this feature, for applications which
262
+ * proclaim their BSD heritage, before including this header; however,
263
+ * to maintain portability, developers are advised to avoid it.
264
+ */
265
+ # define optreset __mingw_optreset
266
+ extern int optreset;
267
+ #endif
268
+ #ifdef __cplusplus
269
+ }
270
+ #endif
271
+ /*
272
+ * POSIX requires the `getopt' API to be specified in `unistd.h';
273
+ * thus, `unistd.h' includes this header. However, we do not want
274
+ * to expose the `getopt_long' or `getopt_long_only' APIs, when
275
+ * included in this manner. Thus, close the standard __GETOPT_H__
276
+ * declarations block, and open an additional __GETOPT_LONG_H__
277
+ * specific block, only when *not* __UNISTD_H_SOURCED__, in which
278
+ * to declare the extended API.
279
+ */
280
+ #endif /* !defined(__GETOPT_H__) */
281
+
282
+ #if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
283
+ #define __GETOPT_LONG_H__
284
+
285
+ #ifdef __cplusplus
286
+ extern "C" {
287
+ #endif
288
+
289
+ struct option /* specification for a long form option... */
290
+ {
291
+ const char *name; /* option name, without leading hyphens */
292
+ int has_arg; /* does it take an argument? */
293
+ int *flag; /* where to save its status, or NULL */
294
+ int val; /* its associated status value */
295
+ };
296
+
297
+ enum /* permitted values for its `has_arg' field... */
298
+ {
299
+ no_argument = 0, /* option never takes an argument */
300
+ required_argument, /* option always requires an argument */
301
+ optional_argument /* option may take an argument */
302
+ };
303
+
304
+ /*
305
+ * parse_long_options --
306
+ * Parse long options in argc/argv argument vector.
307
+ * Returns -1 if short_too is set and the option does not match long_options.
308
+ */
309
+ static int
310
+ parse_long_options(char * const *nargv, const char *options,
311
+ const struct option *long_options, int *idx, int short_too)
312
+ {
313
+ char *current_argv, *has_equal;
314
+ size_t current_argv_len;
315
+ int i, ambiguous, match;
316
+
317
+ #define IDENTICAL_INTERPRETATION(_x, _y) \
318
+ (long_options[(_x)].has_arg == long_options[(_y)].has_arg && \
319
+ long_options[(_x)].flag == long_options[(_y)].flag && \
320
+ long_options[(_x)].val == long_options[(_y)].val)
321
+
322
+ current_argv = place;
323
+ match = -1;
324
+ ambiguous = 0;
325
+
326
+ optind++;
327
+
328
+ if ((has_equal = strchr(current_argv, '=')) != NULL) {
329
+ /* argument found (--option=arg) */
330
+ current_argv_len = has_equal - current_argv;
331
+ has_equal++;
332
+ } else
333
+ current_argv_len = strlen(current_argv);
334
+
335
+ for (i = 0; long_options[i].name; i++) {
336
+ /* find matching long option */
337
+ if (strncmp(current_argv, long_options[i].name,
338
+ current_argv_len))
339
+ continue;
340
+
341
+ if (strlen(long_options[i].name) == current_argv_len) {
342
+ /* exact match */
343
+ match = i;
344
+ ambiguous = 0;
345
+ break;
346
+ }
347
+ /*
348
+ * If this is a known short option, don't allow
349
+ * a partial match of a single character.
350
+ */
351
+ if (short_too && current_argv_len == 1)
352
+ continue;
353
+
354
+ if (match == -1) /* partial match */
355
+ match = i;
356
+ else if (!IDENTICAL_INTERPRETATION(i, match))
357
+ ambiguous = 1;
358
+ }
359
+ if (ambiguous) {
360
+ /* ambiguous abbreviation */
361
+ if (PRINT_ERROR)
362
+ warnx(ambig, (int)current_argv_len,
363
+ current_argv);
364
+ optopt = 0;
365
+ return (BADCH);
366
+ }
367
+ if (match != -1) { /* option found */
368
+ if (long_options[match].has_arg == no_argument
369
+ && has_equal) {
370
+ if (PRINT_ERROR)
371
+ warnx(noarg, (int)current_argv_len,
372
+ current_argv);
373
+ /*
374
+ * XXX: GNU sets optopt to val regardless of flag
375
+ */
376
+ if (long_options[match].flag == NULL)
377
+ optopt = long_options[match].val;
378
+ else
379
+ optopt = 0;
380
+ return (BADARG);
381
+ }
382
+ if (long_options[match].has_arg == required_argument ||
383
+ long_options[match].has_arg == optional_argument) {
384
+ if (has_equal)
385
+ optarg = has_equal;
386
+ else if (long_options[match].has_arg ==
387
+ required_argument) {
388
+ /*
389
+ * optional argument doesn't use next nargv
390
+ */
391
+ optarg = nargv[optind++];
392
+ }
393
+ }
394
+ if ((long_options[match].has_arg == required_argument)
395
+ && (optarg == NULL)) {
396
+ /*
397
+ * Missing argument; leading ':' indicates no error
398
+ * should be generated.
399
+ */
400
+ if (PRINT_ERROR)
401
+ warnx(recargstring,
402
+ current_argv);
403
+ /*
404
+ * XXX: GNU sets optopt to val regardless of flag
405
+ */
406
+ if (long_options[match].flag == NULL)
407
+ optopt = long_options[match].val;
408
+ else
409
+ optopt = 0;
410
+ --optind;
411
+ return (BADARG);
412
+ }
413
+ } else { /* unknown option */
414
+ if (short_too) {
415
+ --optind;
416
+ return (-1);
417
+ }
418
+ if (PRINT_ERROR)
419
+ warnx(illoptstring, current_argv);
420
+ optopt = 0;
421
+ return (BADCH);
422
+ }
423
+ if (idx)
424
+ *idx = match;
425
+ if (long_options[match].flag) {
426
+ *long_options[match].flag = long_options[match].val;
427
+ return (0);
428
+ } else
429
+ return (long_options[match].val);
430
+ #undef IDENTICAL_INTERPRETATION
431
+ }
432
+
433
+ /*
434
+ * getopt_internal --
435
+ * Parse argc/argv argument vector. Called by user level routines.
436
+ */
437
+ static int
438
+ getopt_internal(int nargc, char * const *nargv, const char *options,
439
+ const struct option *long_options, int *idx, int flags)
440
+ {
441
+ char *oli; /* option letter list index */
442
+ int optchar, short_too;
443
+ static int posixly_correct = -1;
444
+
445
+ if (options == NULL)
446
+ return (-1);
447
+
448
+ /*
449
+ * XXX Some GNU programs (like cvs) set optind to 0 instead of
450
+ * XXX using optreset. Work around this braindamage.
451
+ */
452
+ if (optind == 0)
453
+ optind = optreset = 1;
454
+
455
+ /*
456
+ * Disable GNU extensions if POSIXLY_CORRECT is set or options
457
+ * string begins with a '+'.
458
+ *
459
+ * CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or
460
+ * optreset != 0 for GNU compatibility.
461
+ */
462
+ if (posixly_correct == -1 || optreset != 0)
463
+ posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
464
+ if (*options == '-')
465
+ flags |= FLAG_ALLARGS;
466
+ else if (posixly_correct || *options == '+')
467
+ flags &= ~FLAG_PERMUTE;
468
+ if (*options == '+' || *options == '-')
469
+ options++;
470
+
471
+ optarg = NULL;
472
+ if (optreset)
473
+ nonopt_start = nonopt_end = -1;
474
+ start:
475
+ if (optreset || !*place) { /* update scanning pointer */
476
+ optreset = 0;
477
+ if (optind >= nargc) { /* end of argument vector */
478
+ place = EMSG;
479
+ if (nonopt_end != -1) {
480
+ /* do permutation, if we have to */
481
+ permute_args(nonopt_start, nonopt_end,
482
+ optind, nargv);
483
+ optind -= nonopt_end - nonopt_start;
484
+ }
485
+ else if (nonopt_start != -1) {
486
+ /*
487
+ * If we skipped non-options, set optind
488
+ * to the first of them.
489
+ */
490
+ optind = nonopt_start;
491
+ }
492
+ nonopt_start = nonopt_end = -1;
493
+ return (-1);
494
+ }
495
+ if (*(place = nargv[optind]) != '-' ||
496
+ (place[1] == '\0' && strchr(options, '-') == NULL)) {
497
+ place = EMSG; /* found non-option */
498
+ if (flags & FLAG_ALLARGS) {
499
+ /*
500
+ * GNU extension:
501
+ * return non-option as argument to option 1
502
+ */
503
+ optarg = nargv[optind++];
504
+ return (INORDER);
505
+ }
506
+ if (!(flags & FLAG_PERMUTE)) {
507
+ /*
508
+ * If no permutation wanted, stop parsing
509
+ * at first non-option.
510
+ */
511
+ return (-1);
512
+ }
513
+ /* do permutation */
514
+ if (nonopt_start == -1)
515
+ nonopt_start = optind;
516
+ else if (nonopt_end != -1) {
517
+ permute_args(nonopt_start, nonopt_end,
518
+ optind, nargv);
519
+ nonopt_start = optind -
520
+ (nonopt_end - nonopt_start);
521
+ nonopt_end = -1;
522
+ }
523
+ optind++;
524
+ /* process next argument */
525
+ goto start;
526
+ }
527
+ if (nonopt_start != -1 && nonopt_end == -1)
528
+ nonopt_end = optind;
529
+
530
+ /*
531
+ * If we have "-" do nothing, if "--" we are done.
532
+ */
533
+ if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
534
+ optind++;
535
+ place = EMSG;
536
+ /*
537
+ * We found an option (--), so if we skipped
538
+ * non-options, we have to permute.
539
+ */
540
+ if (nonopt_end != -1) {
541
+ permute_args(nonopt_start, nonopt_end,
542
+ optind, nargv);
543
+ optind -= nonopt_end - nonopt_start;
544
+ }
545
+ nonopt_start = nonopt_end = -1;
546
+ return (-1);
547
+ }
548
+ }
549
+
550
+ /*
551
+ * Check long options if:
552
+ * 1) we were passed some
553
+ * 2) the arg is not just "-"
554
+ * 3) either the arg starts with -- we are getopt_long_only()
555
+ */
556
+ if (long_options != NULL && place != nargv[optind] &&
557
+ (*place == '-' || (flags & FLAG_LONGONLY))) {
558
+ short_too = 0;
559
+ if (*place == '-')
560
+ place++; /* --foo long option */
561
+ else if (*place != ':' && strchr(options, *place) != NULL)
562
+ short_too = 1; /* could be short option too */
563
+
564
+ optchar = parse_long_options(nargv, options, long_options,
565
+ idx, short_too);
566
+ if (optchar != -1) {
567
+ place = EMSG;
568
+ return (optchar);
569
+ }
570
+ }
571
+
572
+ if ((optchar = (int)*place++) == (int)':' ||
573
+ (optchar == (int)'-' && *place != '\0') ||
574
+ (oli = (char*)strchr(options, optchar)) == NULL) {
575
+ /*
576
+ * If the user specified "-" and '-' isn't listed in
577
+ * options, return -1 (non-option) as per POSIX.
578
+ * Otherwise, it is an unknown option character (or ':').
579
+ */
580
+ if (optchar == (int)'-' && *place == '\0')
581
+ return (-1);
582
+ if (!*place)
583
+ ++optind;
584
+ if (PRINT_ERROR)
585
+ warnx(illoptchar, optchar);
586
+ optopt = optchar;
587
+ return (BADCH);
588
+ }
589
+ if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
590
+ /* -W long-option */
591
+ if (*place) /* no space */
592
+ /* NOTHING */;
593
+ else if (++optind >= nargc) { /* no arg */
594
+ place = EMSG;
595
+ if (PRINT_ERROR)
596
+ warnx(recargchar, optchar);
597
+ optopt = optchar;
598
+ return (BADARG);
599
+ } else /* white space */
600
+ place = nargv[optind];
601
+ optchar = parse_long_options(nargv, options, long_options,
602
+ idx, 0);
603
+ place = EMSG;
604
+ return (optchar);
605
+ }
606
+ if (*++oli != ':') { /* doesn't take argument */
607
+ if (!*place)
608
+ ++optind;
609
+ } else { /* takes (optional) argument */
610
+ optarg = NULL;
611
+ if (*place) /* no white space */
612
+ optarg = place;
613
+ else if (oli[1] != ':') { /* arg not optional */
614
+ if (++optind >= nargc) { /* no arg */
615
+ place = EMSG;
616
+ if (PRINT_ERROR)
617
+ warnx(recargchar, optchar);
618
+ optopt = optchar;
619
+ return (BADARG);
620
+ } else
621
+ optarg = nargv[optind];
622
+ }
623
+ place = EMSG;
624
+ ++optind;
625
+ }
626
+ /* dump back option letter */
627
+ return (optchar);
628
+ }
629
+
630
+ /*
631
+ * getopt_long --
632
+ * Parse argc/argv argument vector.
633
+ */
634
+ int
635
+ getopt_long(int nargc, char * const *nargv, const char *options,
636
+ const struct option *long_options, int *idx)
637
+ {
638
+
639
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
640
+ FLAG_PERMUTE));
641
+ }
642
+
643
+ /*
644
+ * getopt_long_only --
645
+ * Parse argc/argv argument vector.
646
+ */
647
+ int
648
+ getopt_long_only(int nargc, char * const *nargv, const char *options,
649
+ const struct option *long_options, int *idx)
650
+ {
651
+
652
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
653
+ FLAG_PERMUTE|FLAG_LONGONLY));
654
+ }
655
+
656
+ //extern int getopt_long(int nargc, char * const *nargv, const char *options,
657
+ // const struct option *long_options, int *idx);
658
+ //extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
659
+ // const struct option *long_options, int *idx);
660
+ /*
661
+ * Previous MinGW implementation had...
662
+ */
663
+ #ifndef HAVE_DECL_GETOPT
664
+ /*
665
+ * ...for the long form API only; keep this for compatibility.
666
+ */
667
+ # define HAVE_DECL_GETOPT 1
668
+ #endif
669
+
670
+ #ifdef __cplusplus
671
+ }
672
+ #endif
673
+
674
+ #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/zookeeper.h ADDED
The diff for this file is too large to render. See raw diff
 
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/include/zookeeper_version.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ #ifndef ZOOKEEPER_VERSION_H_
19
+ #define ZOOKEEPER_VERSION_H_
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ #define ZOO_VERSION "3.10.0"
26
+
27
+ #ifdef __cplusplus
28
+ }
29
+ #endif
30
+
31
+ #endif /* ZOOKEEPER_VERSION_H_ */
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/CppAssertHelper.h ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #ifndef CPPASSERTHELPER_H_
20
+ #define CPPASSERTHELPER_H_
21
+
22
+ #include <cppunit/TestAssert.h>
23
+
24
+ // make it possible to specify location of the ASSERT call
25
+ #define CPPUNIT_ASSERT_EQUAL_LOC(expected,actual,file,line) \
26
+ ( CPPUNIT_NS::assertEquals( (expected), \
27
+ (actual), \
28
+ CPPUNIT_NS::SourceLine(file,line), \
29
+ "" ) )
30
+
31
+ #define CPPUNIT_ASSERT_EQUAL_MESSAGE_LOC(message,expected,actual,file,line) \
32
+ ( CPPUNIT_NS::assertEquals( (expected), \
33
+ (actual), \
34
+ CPPUNIT_NS::SourceLine(file,line), \
35
+ (message) ) )
36
+
37
+ #endif /*CPPASSERTHELPER_H_*/
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/LibCMocks.h ADDED
@@ -0,0 +1,408 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #ifndef LIBCMOCKS_H_
20
+ #define LIBCMOCKS_H_
21
+
22
+ #include <string>
23
+ #include <vector>
24
+ #include <deque>
25
+
26
+ #include <errno.h>
27
+ #include <string.h>
28
+
29
+ #include "MocksBase.h"
30
+ #include "LibCSymTable.h"
31
+ #include "ThreadingUtil.h"
32
+
33
+ // *****************************************************************************
34
+ // gethostbyname
35
+
36
+ class Mock_gethostbyname: public Mock
37
+ {
38
+ public:
39
+ struct HostEntry: public hostent {
40
+ HostEntry(const char* hostName,short addrtype);
41
+ ~HostEntry();
42
+ HostEntry& addAlias(const char* alias);
43
+ HostEntry& addAddress(const char* addr4);
44
+ };
45
+
46
+ Mock_gethostbyname():current(0){mock_=this;}
47
+ virtual ~Mock_gethostbyname();
48
+ HostEntry& addHostEntry(const char* hostName,short addrtype=AF_INET);
49
+ virtual hostent* call(const char* name);
50
+
51
+ typedef std::vector<HostEntry*> HostEntryCollection;
52
+ HostEntryCollection gethostbynameReturns;
53
+ int current;
54
+ static Mock_gethostbyname* mock_;
55
+ };
56
+
57
+ class MockFailed_gethostbyname: public Mock_gethostbyname
58
+ {
59
+ public:
60
+ MockFailed_gethostbyname():h_errnoReturn(HOST_NOT_FOUND) {}
61
+
62
+ int h_errnoReturn;
63
+ virtual hostent* call(const char* name) {
64
+ h_errno=h_errnoReturn;
65
+ return 0;
66
+ }
67
+ };
68
+
69
+ // *****************************************************************************
70
+ // calloc
71
+
72
+ class Mock_calloc: public Mock
73
+ {
74
+ public:
75
+ Mock_calloc():errnoOnFailure(ENOMEM),callsBeforeFailure(-1),counter(0) {
76
+ mock_=this;
77
+ }
78
+ virtual ~Mock_calloc() {mock_=0;}
79
+
80
+ int errnoOnFailure;
81
+ int callsBeforeFailure;
82
+ int counter;
83
+ virtual void* call(size_t p1, size_t p2);
84
+
85
+ static Mock_calloc* mock_;
86
+ };
87
+
88
+ // *****************************************************************************
89
+ // realloc
90
+
91
+ class Mock_realloc: public Mock
92
+ {
93
+ public:
94
+ Mock_realloc():errnoOnFailure(ENOMEM),callsBeforeFailure(-1),counter(0) {
95
+ mock_=this;
96
+ }
97
+ virtual ~Mock_realloc() {mock_=0;}
98
+
99
+ int errnoOnFailure;
100
+ int callsBeforeFailure;
101
+ int counter;
102
+ virtual void* call(void* p, size_t s);
103
+
104
+ static Mock_realloc* mock_;
105
+ };
106
+
107
+ // *****************************************************************************
108
+ // random
109
+
110
+ class Mock_random: public Mock
111
+ {
112
+ public:
113
+ Mock_random():currentIdx(0) {mock_=this;}
114
+ virtual ~Mock_random() {mock_=0;}
115
+
116
+ int currentIdx;
117
+ std::vector<int> randomReturns;
118
+ virtual int call();
119
+ void setSeed(unsigned long){currentIdx=0;}
120
+
121
+ static Mock_random* mock_;
122
+ };
123
+
124
+ // *****************************************************************************
125
+ // no-op free; keeps track of all deallocation requests
126
+ class Mock_free_noop: public Mock
127
+ {
128
+ Mutex mx;
129
+ std::vector<void*> requested;
130
+ public:
131
+ Mock_free_noop():nested(0),callCounter(0){mock_=this;}
132
+ virtual ~Mock_free_noop(){
133
+ mock_=0;
134
+ freeRequested();
135
+ }
136
+
137
+ int nested;
138
+ int callCounter;
139
+ virtual void call(void* p);
140
+ void freeRequested();
141
+ void disable(){mock_=0;}
142
+ // returns number of times the pointer was freed
143
+ int getFreeCount(void*);
144
+ bool isFreed(void*);
145
+
146
+ static Mock_free_noop* mock_;
147
+ };
148
+
149
+ // *****************************************************************************
150
+ // socket and related system calls
151
+
152
+ class Mock_socket: public Mock
153
+ {
154
+ public:
155
+ static const int FD=63;
156
+ Mock_socket():socketReturns(FD),closeReturns(0),getsocketoptReturns(0),
157
+ optvalSO_ERROR(0),
158
+ setsockoptReturns(0),connectReturns(0),connectErrno(0),
159
+ sendErrno(0),recvErrno(0)
160
+ {
161
+ mock_=this;
162
+ }
163
+ virtual ~Mock_socket(){mock_=0;}
164
+
165
+ int socketReturns;
166
+ virtual int callSocket(int domain, int type, int protocol){
167
+ return socketReturns;
168
+ }
169
+ int closeReturns;
170
+ virtual int callClose(int fd){
171
+ return closeReturns;
172
+ }
173
+ int getsocketoptReturns;
174
+ int optvalSO_ERROR;
175
+ virtual int callGet(int s,int level,int optname,void *optval,socklen_t *len){
176
+ if(level==SOL_SOCKET && optname==SO_ERROR){
177
+ setSO_ERROR(optval,*len);
178
+ }
179
+ return getsocketoptReturns;
180
+ }
181
+ virtual void setSO_ERROR(void *optval,socklen_t len){
182
+ memcpy(optval,&optvalSO_ERROR,len);
183
+ }
184
+
185
+ int setsockoptReturns;
186
+ virtual int callSet(int s,int level,int optname,const void *optval,socklen_t len){
187
+ return setsockoptReturns;
188
+ }
189
+ int connectReturns;
190
+ int connectErrno;
191
+ virtual int callConnect(int s,const struct sockaddr *addr,socklen_t len){
192
+ errno=connectErrno;
193
+ return connectReturns;
194
+ }
195
+
196
+ virtual void notifyBufferSent(const std::string& buffer){}
197
+
198
+ int sendErrno;
199
+ std::string sendBuffer;
200
+ virtual ssize_t callSend(int s,const void *buf,size_t len,int flags){
201
+ if(sendErrno!=0){
202
+ errno=sendErrno;
203
+ return -1;
204
+ }
205
+ // first call to send() is always the length of the buffer to follow
206
+ bool sendingLength=sendBuffer.size()==0;
207
+ // overwrite the length bytes
208
+ sendBuffer.assign((const char*)buf,len);
209
+ if(!sendingLength){
210
+ notifyBufferSent(sendBuffer);
211
+ sendBuffer.erase();
212
+ }
213
+ return len;
214
+ }
215
+
216
+ int recvErrno;
217
+ std::string recvReturnBuffer;
218
+ virtual ssize_t callRecv(int s,void *buf,size_t len,int flags){
219
+ if(recvErrno!=0){
220
+ errno=recvErrno;
221
+ return -1;
222
+ }
223
+ int k=std::min(len,recvReturnBuffer.length());
224
+ if(k==0)
225
+ return 0;
226
+ memcpy(buf,recvReturnBuffer.data(),k);
227
+ recvReturnBuffer.erase(0,k);
228
+ return k;
229
+ }
230
+ virtual bool hasMoreRecv() const{
231
+ return recvReturnBuffer.size()!=0;
232
+ }
233
+ static Mock_socket* mock_;
234
+ };
235
+
236
+ // *****************************************************************************
237
+ // fcntl
238
+ class Mock_fcntl: public Mock
239
+ {
240
+ public:
241
+ Mock_fcntl():callReturns(0),trapFD(-1){mock_=this;}
242
+ ~Mock_fcntl(){mock_=0;}
243
+
244
+ int callReturns;
245
+ int trapFD;
246
+ virtual int call(int fd, int cmd, void* arg){
247
+ if(trapFD==-1)
248
+ return LIBC_SYMBOLS.fcntl(fd,cmd,arg);
249
+ return callReturns;
250
+ }
251
+
252
+ static Mock_fcntl* mock_;
253
+ };
254
+
255
+ // *****************************************************************************
256
+ // select
257
+ class Mock_select: public Mock
258
+ {
259
+ public:
260
+ Mock_select(Mock_socket* s,int fd):sock(s),
261
+ callReturns(0),myFD(fd),timeout(50)
262
+ {
263
+ mock_=this;
264
+ }
265
+ ~Mock_select(){mock_=0;}
266
+
267
+ Mock_socket* sock;
268
+ int callReturns;
269
+ int myFD;
270
+ int timeout; //in millis
271
+ virtual int call(int nfds,fd_set *rfds,fd_set *wfds,fd_set *efds,struct timeval *tv){
272
+ bool isWritableRequested=(wfds && FD_ISSET(myFD,wfds));
273
+ if(rfds) FD_CLR(myFD,rfds);
274
+ if(wfds) FD_CLR(myFD,wfds);
275
+ // this timeout is only to prevent a tight loop
276
+ timeval myTimeout={0,0};
277
+ if(!isWritableRequested && !isFDReadable()){
278
+ myTimeout.tv_sec=timeout/1000;
279
+ myTimeout.tv_usec=(timeout%1000)*1000;
280
+ }
281
+ LIBC_SYMBOLS.select(nfds,rfds,wfds,efds,&myTimeout);
282
+ // myFD is always writable
283
+ if(isWritableRequested) FD_SET(myFD,wfds);
284
+ // myFD is only readable if the socket has anything to read
285
+ if(isFDReadable() && rfds) FD_SET(myFD,rfds);
286
+ return callReturns;
287
+ }
288
+
289
+ virtual bool isFDReadable() const {
290
+ return sock->hasMoreRecv();
291
+ }
292
+
293
+ static Mock_select* mock_;
294
+ };
295
+
296
+ // *****************************************************************************
297
+ // poll
298
+ // the last element of the pollfd array is expected to be test FD
299
+ class Mock_poll: public Mock
300
+ {
301
+ public:
302
+ Mock_poll(Mock_socket* s,int fd):sock(s),
303
+ callReturns(1),myFD(fd),timeout(50)
304
+ {
305
+ mock_=this;
306
+ }
307
+ ~Mock_poll(){mock_=0;}
308
+
309
+ Mock_socket* sock;
310
+ int callReturns;
311
+ int myFD;
312
+ int timeout; //in millis
313
+ virtual int call(struct pollfd *fds, POLL_NFDS_TYPE nfds, int to) {
314
+ pollfd* myPoll=0;
315
+ if(fds[nfds-1].fd==myFD)
316
+ myPoll=&fds[nfds-1];
317
+ bool isWritableRequested=false;
318
+ if(myPoll!=0){
319
+ isWritableRequested=myPoll->events&POLLOUT;
320
+ nfds--;
321
+ }
322
+ LIBC_SYMBOLS.poll(fds,nfds,(!isWritableRequested&&!isFDReadable())?timeout:0);
323
+ if(myPoll!=0){
324
+ // myFD is always writable if requested
325
+ myPoll->revents=isWritableRequested?POLLOUT:0;
326
+ // myFD is only readable if the socket has anything to read
327
+ myPoll->revents|=isFDReadable()?POLLIN:0;
328
+ }
329
+ return callReturns;
330
+ }
331
+
332
+ virtual bool isFDReadable() const {
333
+ return sock->hasMoreRecv();
334
+ }
335
+
336
+ static Mock_poll* mock_;
337
+ };
338
+
339
+ // *****************************************************************************
340
+ // gettimeofday
341
+ class Mock_gettimeofday: public Mock
342
+ {
343
+ public:
344
+ Mock_gettimeofday(){
345
+ LIBC_SYMBOLS.gettimeofday(&tv,0);
346
+ mock_=this;
347
+ }
348
+ Mock_gettimeofday(const Mock_gettimeofday& other):tv(other.tv){}
349
+ Mock_gettimeofday(int32_t sec,int32_t usec){
350
+ tv.tv_sec=sec;
351
+ tv.tv_usec=usec;
352
+ }
353
+ ~Mock_gettimeofday(){mock_=0;}
354
+
355
+ timeval tv;
356
+ virtual int call(struct timeval *tp, GETTIMEOFDAY_ARG2_TYPE tzp){
357
+ *tp=tv;
358
+ return 0;
359
+ }
360
+ operator timeval() const{
361
+ return tv;
362
+ }
363
+ // advance secs
364
+ virtual void tick(int howmuch=1){tv.tv_sec+=howmuch;}
365
+ // advance milliseconds
366
+ // can move the clock forward as well as backward by providing a negative
367
+ // number
368
+ virtual void millitick(int howmuch=1){
369
+ int ms=tv.tv_usec/1000+howmuch;
370
+ tv.tv_sec+=ms/1000;
371
+ // going backward?
372
+ if(ms<0){
373
+ ms=1000-(-ms%1000); //wrap millis around
374
+ }
375
+ tv.tv_usec=(ms%1000)*1000;
376
+ }
377
+ virtual void tick(const timeval& howmuch){
378
+ // add milliseconds (discarding microsecond portion)
379
+ long ms=tv.tv_usec/1000+howmuch.tv_usec/1000;
380
+ tv.tv_sec+=howmuch.tv_sec+ms/1000;
381
+ tv.tv_usec=(ms%1000)*1000;
382
+ }
383
+ static Mock_gettimeofday* mock_;
384
+ };
385
+
386
+ // discard microseconds!
387
+ inline bool operator==(const timeval& lhs, const timeval& rhs){
388
+ return rhs.tv_sec==lhs.tv_sec && rhs.tv_usec/1000==lhs.tv_usec/1000;
389
+ }
390
+
391
+ // simplistic implementation: no normalization, assume lhs >= rhs,
392
+ // discarding microseconds
393
+ inline timeval operator-(const timeval& lhs, const timeval& rhs){
394
+ timeval res;
395
+ res.tv_sec=lhs.tv_sec-rhs.tv_sec;
396
+ res.tv_usec=(lhs.tv_usec/1000-rhs.tv_usec/1000)*1000;
397
+ if(res.tv_usec<0){
398
+ res.tv_sec--;
399
+ res.tv_usec=1000000+res.tv_usec%1000000; // wrap the millis around
400
+ }
401
+ return res;
402
+ }
403
+
404
+ inline int32_t toMilliseconds(const timeval& tv){
405
+ return tv.tv_sec*1000+tv.tv_usec/1000;
406
+ }
407
+
408
+ #endif /*LIBCMOCKS_H_*/
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/LibCSymTable.cc ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #include "LibCSymTable.h"
20
+ #include <unistd.h> // needed for _POSIX_MONOTONIC_CLOCK
21
+
22
+ #define LOAD_SYM(sym) \
23
+ sym=(sym##_sig)dlsym(handle,#sym); \
24
+ assert("Unable to load "#sym" from libc"&&sym)
25
+
26
+
27
+ LibCSymTable& LibCSymTable::instance(){
28
+ static LibCSymTable tbl;
29
+ return tbl;
30
+ }
31
+
32
+ //******************************************************************************
33
+ // preload original libc symbols
34
+ LibCSymTable::LibCSymTable()
35
+ {
36
+ void* handle=getHandle();
37
+ LOAD_SYM(gethostbyname);
38
+ LOAD_SYM(calloc);
39
+ LOAD_SYM(realloc);
40
+ LOAD_SYM(free);
41
+ LOAD_SYM(random);
42
+ LOAD_SYM(srandom);
43
+ LOAD_SYM(printf);
44
+ LOAD_SYM(socket);
45
+ LOAD_SYM(close);
46
+ LOAD_SYM(getsockopt);
47
+ LOAD_SYM(setsockopt);
48
+ LOAD_SYM(fcntl);
49
+ LOAD_SYM(connect);
50
+ LOAD_SYM(send);
51
+ LOAD_SYM(recv);
52
+ LOAD_SYM(select);
53
+ LOAD_SYM(poll);
54
+ LOAD_SYM(gettimeofday);
55
+ #ifdef _POSIX_MONOTONIC_CLOCK
56
+ LOAD_SYM(clock_gettime);
57
+ #endif
58
+ #ifdef THREADED
59
+ LOAD_SYM(pthread_create);
60
+ LOAD_SYM(pthread_detach);
61
+ LOAD_SYM(pthread_cond_broadcast);
62
+ LOAD_SYM(pthread_cond_destroy);
63
+ LOAD_SYM(pthread_cond_init);
64
+ LOAD_SYM(pthread_cond_signal);
65
+ LOAD_SYM(pthread_cond_timedwait);
66
+ LOAD_SYM(pthread_cond_wait);
67
+ LOAD_SYM(pthread_join);
68
+ LOAD_SYM(pthread_mutex_destroy);
69
+ LOAD_SYM(pthread_mutex_init);
70
+ LOAD_SYM(pthread_mutex_lock);
71
+ LOAD_SYM(pthread_mutex_trylock);
72
+ LOAD_SYM(pthread_mutex_unlock);
73
+ #endif
74
+ }
75
+
76
+ void* LibCSymTable::getHandle(){
77
+ static void* handle=0;
78
+ if(!handle){
79
+ #ifdef __CYGWIN__
80
+ handle=dlopen("cygwin1.dll",RTLD_LAZY);
81
+ assert("Unable to dlopen global sym table"&&handle);
82
+ #else
83
+ handle=RTLD_NEXT;
84
+ #endif
85
+ }
86
+ return handle;
87
+ }
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/MocksBase.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #ifndef MOCKSBASE_H_
20
+ #define MOCKSBASE_H_
21
+
22
+ #include <cstddef>
23
+
24
+ // *****************************************************************************
25
+ // Mock base
26
+
27
+ class Mock
28
+ {
29
+ public:
30
+ virtual ~Mock(){}
31
+
32
+ static void* operator new(std::size_t s);
33
+ static void operator delete(void* p);
34
+ };
35
+
36
+ #endif /*MOCKSBASE_H_*/
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/PthreadMocks.cc ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #include "PthreadMocks.h"
20
+
21
+ MockPthreadsBase* MockPthreadsBase::mock_=0;
22
+
23
+ #undef USING_DUMA
24
+
25
+ #ifndef USING_DUMA
26
+ int pthread_cond_broadcast (pthread_cond_t *c){
27
+ if(!MockPthreadsBase::mock_)
28
+ return LIBC_SYMBOLS.pthread_cond_broadcast(c);
29
+ return MockPthreadsBase::mock_->pthread_cond_broadcast(c);
30
+ }
31
+ int pthread_cond_destroy (pthread_cond_t *c){
32
+ if(!MockPthreadsBase::mock_)
33
+ return LIBC_SYMBOLS.pthread_cond_destroy(c);
34
+ return MockPthreadsBase::mock_->pthread_cond_destroy(c);
35
+ }
36
+ int pthread_cond_init (pthread_cond_t *c, const pthread_condattr_t *a){
37
+ if(!MockPthreadsBase::mock_)
38
+ return LIBC_SYMBOLS.pthread_cond_init(c,a);
39
+ return MockPthreadsBase::mock_->pthread_cond_init(c,a);
40
+ }
41
+ int pthread_cond_signal (pthread_cond_t *c){
42
+ if(!MockPthreadsBase::mock_)
43
+ return LIBC_SYMBOLS.pthread_cond_signal(c);
44
+ return MockPthreadsBase::mock_->pthread_cond_signal(c);
45
+ }
46
+ int pthread_cond_timedwait (pthread_cond_t *c,
47
+ pthread_mutex_t *m, const struct timespec *t){
48
+ if(!MockPthreadsBase::mock_)
49
+ return LIBC_SYMBOLS.pthread_cond_timedwait(c,m,t);
50
+ return MockPthreadsBase::mock_->pthread_cond_timedwait(c,m,t);
51
+ }
52
+ int pthread_cond_wait (pthread_cond_t *c, pthread_mutex_t *m){
53
+ if(!MockPthreadsBase::mock_)
54
+ return LIBC_SYMBOLS.pthread_cond_wait(c,m);
55
+ return MockPthreadsBase::mock_->pthread_cond_wait(c,m);
56
+ }
57
+ int pthread_create (pthread_t *t, const pthread_attr_t *a,
58
+ void *(*f)(void *), void *d){
59
+ if(!MockPthreadsBase::mock_)
60
+ return LIBC_SYMBOLS.pthread_create(t,a,f,d);
61
+ return MockPthreadsBase::mock_->pthread_create(t,a,f,d);
62
+ }
63
+ int pthread_detach(pthread_t t){
64
+ if(!MockPthreadsBase::mock_)
65
+ return LIBC_SYMBOLS.pthread_detach(t);
66
+ return MockPthreadsBase::mock_->pthread_detach(t);
67
+ }
68
+ int pthread_join (pthread_t t, void **r){
69
+ if(!MockPthreadsBase::mock_)
70
+ return LIBC_SYMBOLS.pthread_join(t,r);
71
+ return MockPthreadsBase::mock_->pthread_join(t,r);
72
+ }
73
+ int pthread_mutex_destroy (pthread_mutex_t *m){
74
+ if(!MockPthreadsBase::mock_)
75
+ return LIBC_SYMBOLS.pthread_mutex_destroy(m);
76
+ return MockPthreadsBase::mock_->pthread_mutex_destroy(m);
77
+ }
78
+ int pthread_mutex_init (pthread_mutex_t *m, const pthread_mutexattr_t *a){
79
+ if(!MockPthreadsBase::mock_)
80
+ return LIBC_SYMBOLS.pthread_mutex_init(m,a);
81
+ return MockPthreadsBase::mock_->pthread_mutex_init(m,a);
82
+ }
83
+
84
+ DECLARE_WRAPPER(int,pthread_mutex_lock,(pthread_mutex_t *m)){
85
+ if(!MockPthreadsBase::mock_)
86
+ return CALL_REAL(pthread_mutex_lock,(m));
87
+ return MockPthreadsBase::mock_->pthread_mutex_lock(m);
88
+ }
89
+
90
+ int pthread_mutex_trylock (pthread_mutex_t *m){
91
+ if(!MockPthreadsBase::mock_)
92
+ return LIBC_SYMBOLS.pthread_mutex_trylock(m);
93
+ return MockPthreadsBase::mock_->pthread_mutex_trylock(m);
94
+ }
95
+
96
+ DECLARE_WRAPPER(int,pthread_mutex_unlock,(pthread_mutex_t *m)){
97
+ if(!MockPthreadsBase::mock_)
98
+ return CALL_REAL(pthread_mutex_unlock,(m));
99
+ return MockPthreadsBase::mock_->pthread_mutex_unlock(m);
100
+ }
101
+ #endif
102
+
103
+ CheckedPthread::ThreadMap CheckedPthread::tmap_;
104
+ CheckedPthread::MutexMap CheckedPthread::mmap_;
105
+ CheckedPthread::CVMap CheckedPthread::cvmap_;
106
+ Mutex CheckedPthread::mx;
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestLogClientEnv.cc ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #include <cppunit/extensions/HelperMacros.h>
20
+ #include "CppAssertHelper.h"
21
+
22
+ #include <string.h>
23
+ #include <zookeeper.h>
24
+
25
+ class Zookeeper_logClientEnv : public CPPUNIT_NS::TestFixture {
26
+ CPPUNIT_TEST_SUITE(Zookeeper_logClientEnv);
27
+ CPPUNIT_TEST(testLogClientEnv);
28
+ CPPUNIT_TEST_SUITE_END();
29
+
30
+ static void log_no_clientenv(const char *message) {
31
+ CPPUNIT_ASSERT(::strstr(message, "Client environment") == NULL);
32
+ }
33
+
34
+ static void log_clientenv(const char *message) {
35
+ static int first;
36
+
37
+ if (!first) {
38
+ CPPUNIT_ASSERT(::strstr(message, "Client environment") != NULL);
39
+ first = 1;
40
+ }
41
+ }
42
+
43
+ public:
44
+
45
+ void testLogClientEnv() {
46
+ zhandle_t* zh;
47
+
48
+ zh = zookeeper_init2("localhost:22181", NULL, 0, NULL, NULL, 0, log_clientenv);
49
+ CPPUNIT_ASSERT(zh != 0);
50
+ zookeeper_close(zh);
51
+
52
+ zh = zookeeper_init2("localhost:22181", NULL, 0, NULL, NULL, ZOO_NO_LOG_CLIENTENV, log_no_clientenv);
53
+ CPPUNIT_ASSERT(zh != 0);
54
+ zookeeper_close(zh);
55
+ }
56
+ };
57
+
58
+ CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_logClientEnv);
59
+
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestReadOnlyClient.cc ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #include <cppunit/extensions/HelperMacros.h>
20
+ #include "CppAssertHelper.h"
21
+
22
+ #include <sys/socket.h>
23
+ #include <unistd.h>
24
+
25
+ #include <zookeeper.h>
26
+
27
+ #include "Util.h"
28
+ #include "WatchUtil.h"
29
+
30
+ #ifdef THREADED
31
+ class Zookeeper_readOnly : public CPPUNIT_NS::TestFixture {
32
+ CPPUNIT_TEST_SUITE(Zookeeper_readOnly);
33
+ CPPUNIT_TEST(testReadOnly);
34
+ #ifdef HAVE_OPENSSL_H
35
+ CPPUNIT_TEST(testReadOnlyWithSSL);
36
+ #endif
37
+ CPPUNIT_TEST_SUITE_END();
38
+
39
+ static void watcher(zhandle_t* zh, int type, int state,
40
+ const char* path, void* v) {
41
+ watchctx_t *ctx = (watchctx_t*)v;
42
+
43
+ if (state==ZOO_CONNECTED_STATE || state==ZOO_READONLY_STATE) {
44
+ ctx->connected = true;
45
+ } else {
46
+ ctx->connected = false;
47
+ }
48
+ if (type != ZOO_SESSION_EVENT) {
49
+ evt_t evt;
50
+ evt.path = path;
51
+ evt.type = type;
52
+ ctx->putEvent(evt);
53
+ }
54
+ }
55
+
56
+ FILE *logfile;
57
+ public:
58
+
59
+ Zookeeper_readOnly() {
60
+ logfile = openlogfile("Zookeeper_readOnly");
61
+ }
62
+
63
+ ~Zookeeper_readOnly() {
64
+ if (logfile) {
65
+ fflush(logfile);
66
+ fclose(logfile);
67
+ logfile = 0;
68
+ }
69
+ }
70
+
71
+ void setUp() {
72
+ zoo_set_log_stream(logfile);
73
+ zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG);
74
+ stopServer();
75
+ }
76
+
77
+ void tearDown()
78
+ {
79
+ startServer();
80
+ }
81
+
82
+ void startServer() {
83
+ char cmd[1024];
84
+ sprintf(cmd, "%s start %s", ZKSERVER_CMD, "127.0.0.1:22181");
85
+ CPPUNIT_ASSERT(system(cmd) == 0);
86
+ }
87
+
88
+ void stopServer() {
89
+ char cmd[1024];
90
+ sprintf(cmd, "%s stop %s", ZKSERVER_CMD, "127.0.0.1:22181");
91
+ CPPUNIT_ASSERT(system(cmd) == 0);
92
+ }
93
+
94
+ void startReadOnly() {
95
+ char cmd[1024];
96
+ sprintf(cmd, "%s startCleanReadOnly", ZKSERVER_CMD);
97
+ CPPUNIT_ASSERT(system(cmd) == 0);
98
+ }
99
+
100
+ void stopPeer() {
101
+ char cmd[1024];
102
+ sprintf(cmd, "%s stop", ZKSERVER_CMD);
103
+ CPPUNIT_ASSERT(system(cmd) == 0);
104
+ }
105
+
106
+ zhandle_t* connectReadOnly(const char *address, watchctx_t *watch) {
107
+ zhandle_t* zh = zookeeper_init(address, watcher, 10000, NULL, watch, ZOO_READONLY);
108
+ watch->zh = zh;
109
+ CPPUNIT_ASSERT(zh != 0);
110
+ sleep(1);
111
+ return zh;
112
+ }
113
+
114
+ void assertCanRead(zhandle_t* zh, const char *znode_path) {
115
+ int len = 1024;
116
+ char buf[len];
117
+ int res = zoo_get(zh, znode_path, 0, buf, &len, 0);
118
+ CPPUNIT_ASSERT_EQUAL((int)ZOK, res);
119
+ }
120
+
121
+ void assertCanNotWrite(zhandle_t* zh, const char *znode_path) {
122
+ char path[1024];
123
+ char buf[1024];
124
+ int res = zoo_create(zh, znode_path, buf, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path, 512);
125
+ CPPUNIT_ASSERT_EQUAL((int)ZNOTREADONLY, res);
126
+ }
127
+
128
+ void testReadOnly()
129
+ {
130
+ startReadOnly();
131
+
132
+ watchctx_t watch;
133
+ zhandle_t* zh = connectReadOnly("localhost:22181", &watch);
134
+
135
+ assertCanRead(zh, "/");
136
+
137
+ assertCanNotWrite(zh, "/test");
138
+
139
+ stopPeer();
140
+ }
141
+
142
+ #ifdef HAVE_OPENSSL_H
143
+
144
+ zhandle_t* connectReadOnlySSL(const char *address, const char *certs, watchctx_t *watch) {
145
+ zhandle_t* zh = zookeeper_init_ssl(address, certs, watcher, 10000, NULL, watch, ZOO_READONLY);
146
+ watch->zh = zh;
147
+ CPPUNIT_ASSERT(zh != 0);
148
+ sleep(1);
149
+ return zh;
150
+ }
151
+
152
+ void testReadOnlyWithSSL() {
153
+ startReadOnly();
154
+
155
+ watchctx_t watch;
156
+ zhandle_t* zh = connectReadOnlySSL("localhost:22281",
157
+ "/tmp/certs/server.crt,/tmp/certs/client.crt,/tmp/certs/clientkey.pem,password",
158
+ &watch);
159
+
160
+ assertCanRead(zh, "/");
161
+
162
+ assertCanNotWrite(zh, "/testSSL");
163
+
164
+ stopPeer();
165
+ }
166
+ #endif
167
+
168
+ };
169
+
170
+ CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_readOnly);
171
+ #endif
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestSASLAuth.cc ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #ifdef THREADED
20
+
21
+ #include <cppunit/extensions/HelperMacros.h>
22
+ #include "CppAssertHelper.h"
23
+
24
+ #include <sys/socket.h>
25
+ #include <unistd.h>
26
+
27
+ #include <zookeeper.h>
28
+
29
+ #include "Util.h"
30
+ #include "WatchUtil.h"
31
+
32
+ class Zookeeper_SASLAuth : public CPPUNIT_NS::TestFixture {
33
+ CPPUNIT_TEST_SUITE(Zookeeper_SASLAuth);
34
+ CPPUNIT_TEST(testServerRequireClientSASL);
35
+ #ifdef HAVE_CYRUS_SASL_H
36
+ CPPUNIT_TEST(testClientSASL);
37
+ #ifdef ZOO_IPV6_ENABLED
38
+ CPPUNIT_TEST(testClientSASLOverIPv6);
39
+ #endif/* ZOO_IPV6_ENABLED */
40
+ CPPUNIT_TEST(testClientSASLReadOnly);
41
+ CPPUNIT_TEST(testClientSASLPacketOrder);
42
+ #endif /* HAVE_CYRUS_SASL_H */
43
+ CPPUNIT_TEST_SUITE_END();
44
+ FILE *logfile;
45
+ static const char hostPorts[];
46
+ static const char jaasConf[];
47
+ static void watcher(zhandle_t *, int type, int state, const char *path,void*v){
48
+ watchctx_t *ctx = (watchctx_t*)v;
49
+
50
+ if (state == ZOO_CONNECTED_STATE || state == ZOO_READONLY_STATE) {
51
+ ctx->connected = true;
52
+ } else {
53
+ ctx->connected = false;
54
+ }
55
+ if (type != ZOO_SESSION_EVENT) {
56
+ evt_t evt;
57
+ evt.path = path;
58
+ evt.type = type;
59
+ ctx->putEvent(evt);
60
+ }
61
+ }
62
+
63
+ public:
64
+ Zookeeper_SASLAuth() {
65
+ logfile = openlogfile("Zookeeper_SASLAuth");
66
+ }
67
+
68
+ ~Zookeeper_SASLAuth() {
69
+ if (logfile) {
70
+ fflush(logfile);
71
+ fclose(logfile);
72
+ logfile = 0;
73
+ }
74
+ }
75
+
76
+ void setUp() {
77
+ zoo_set_log_stream(logfile);
78
+
79
+ // Create SASL configuration file for server.
80
+ FILE *conff = fopen("Zookeeper_SASLAuth.jaas.conf", "wt");
81
+ CPPUNIT_ASSERT(conff);
82
+ size_t confLen = strlen(jaasConf);
83
+ CPPUNIT_ASSERT_EQUAL(fwrite(jaasConf, 1, confLen, conff), confLen);
84
+ CPPUNIT_ASSERT_EQUAL(fclose(conff), 0);
85
+ conff = NULL;
86
+
87
+ // Create password file for client.
88
+ FILE *passf = fopen("Zookeeper_SASLAuth.password", "wt");
89
+ CPPUNIT_ASSERT(passf);
90
+ CPPUNIT_ASSERT(fputs("mypassword", passf) > 0);
91
+ CPPUNIT_ASSERT_EQUAL(fclose(passf), 0);
92
+ passf = NULL;
93
+ }
94
+
95
+ void startServer(bool useJaasConf = true, bool readOnly = false) {
96
+ char cmd[1024];
97
+ sprintf(cmd, "%s startRequireSASLAuth %s %s",
98
+ ZKSERVER_CMD,
99
+ useJaasConf ? "Zookeeper_SASLAuth.jaas.conf" : "",
100
+ readOnly ? "true" : "");
101
+ CPPUNIT_ASSERT(system(cmd) == 0);
102
+ }
103
+
104
+ void stopServer() {
105
+ char cmd[1024];
106
+ sprintf(cmd, "%s stop", ZKSERVER_CMD);
107
+ CPPUNIT_ASSERT(system(cmd) == 0);
108
+ }
109
+
110
+ void testServerRequireClientSASL() {
111
+ startServer(false);
112
+
113
+ watchctx_t ctx;
114
+ int rc = 0;
115
+ zhandle_t *zk = zookeeper_init(hostPorts, watcher, 10000, 0, &ctx, 0);
116
+ ctx.zh = zk;
117
+ CPPUNIT_ASSERT(zk);
118
+
119
+ // Wait for handle to be connected.
120
+ CPPUNIT_ASSERT(ctx.waitForConnected(zk));
121
+
122
+ char pathbuf[80];
123
+ struct Stat stat_a = {0};
124
+
125
+ rc = zoo_create2(zk, "/serverRequireClientSASL", "", 0,
126
+ &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, sizeof(pathbuf), &stat_a);
127
+ CPPUNIT_ASSERT_EQUAL((int)ZSESSIONCLOSEDREQUIRESASLAUTH, rc);
128
+
129
+ stopServer();
130
+ }
131
+
132
+ #ifdef HAVE_CYRUS_SASL_H
133
+
134
+ // We need to disable the deprecation warnings as Apple has
135
+ // decided to deprecate all of CyrusSASL's functions with OS 10.11
136
+ // (see MESOS-3030, ZOOKEEPER-4201). We are using GCC pragmas also
137
+ // for covering clang.
138
+ #ifdef __APPLE__
139
+ #pragma GCC diagnostic push
140
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
141
+ #endif
142
+
143
+ void testClientSASLHelper(const char *hostPorts, const char *path) {
144
+ startServer();
145
+
146
+ // Initialize Cyrus SASL.
147
+ CPPUNIT_ASSERT_EQUAL(sasl_client_init(NULL), SASL_OK);
148
+
149
+ // Initialize SASL parameters.
150
+ zoo_sasl_params_t sasl_params = { 0 };
151
+
152
+ sasl_params.service = "zookeeper";
153
+ sasl_params.host = "zk-sasl-md5";
154
+ sasl_params.mechlist = "DIGEST-MD5";
155
+ sasl_params.callbacks = zoo_sasl_make_basic_callbacks(
156
+ "myuser", NULL, "Zookeeper_SASLAuth.password");
157
+
158
+ // Connect.
159
+ watchctx_t ctx;
160
+ int rc = 0;
161
+ zhandle_t *zk = zookeeper_init_sasl(hostPorts, watcher, 10000, NULL,
162
+ &ctx, /*flags*/0, /*log_callback*/NULL, &sasl_params);
163
+ ctx.zh = zk;
164
+ CPPUNIT_ASSERT(zk);
165
+
166
+ // Wait for SASL auth to complete and handle to be connected.
167
+ CPPUNIT_ASSERT(ctx.waitForConnected(zk));
168
+
169
+ // Leave mark.
170
+ char pathbuf[80];
171
+ struct Stat stat_a = {0};
172
+ rc = zoo_create2(zk, path, "", 0,
173
+ &ZOO_OPEN_ACL_UNSAFE, 0, pathbuf, sizeof(pathbuf), &stat_a);
174
+ CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
175
+
176
+ // Stop and restart the server to test automatic reconnect & re-auth.
177
+ stopServer();
178
+ CPPUNIT_ASSERT(ctx.waitForDisconnected(zk));
179
+ startServer();
180
+
181
+ // Wait for automatic SASL re-auth to complete.
182
+ CPPUNIT_ASSERT(ctx.waitForConnected(zk));
183
+
184
+ // Check mark left above.
185
+ rc = zoo_exists(zk, path, /*watch*/false, &stat_a);
186
+ CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
187
+
188
+ stopServer();
189
+ }
190
+
191
+ void testClientSASL() {
192
+ testClientSASLHelper(hostPorts, "/clientSASL");
193
+ }
194
+
195
+ void testClientSASLOverIPv6() {
196
+ const char *ipAndPort = "::1:22181";
197
+
198
+ testClientSASLHelper(ipAndPort, "/clientSASLOverIPv6");
199
+ }
200
+
201
+ void testClientSASLReadOnly() {
202
+ startServer(/*useJaasConf*/ true, /*readOnly*/ true);
203
+
204
+ // Initialize Cyrus SASL.
205
+ CPPUNIT_ASSERT_EQUAL(sasl_client_init(NULL), SASL_OK);
206
+
207
+ // Initialize SASL parameters.
208
+ zoo_sasl_params_t sasl_params = { 0 };
209
+
210
+ sasl_params.service = "zookeeper";
211
+ sasl_params.host = "zk-sasl-md5";
212
+ sasl_params.mechlist = "DIGEST-MD5";
213
+ sasl_params.callbacks = zoo_sasl_make_basic_callbacks(
214
+ "myuser", NULL, "Zookeeper_SASLAuth.password");
215
+
216
+ // Connect.
217
+ watchctx_t ctx;
218
+ int rc = 0;
219
+ zhandle_t *zk = zookeeper_init_sasl(hostPorts, watcher, 10000, NULL,
220
+ &ctx, /*flags*/ZOO_READONLY, /*log_callback*/NULL, &sasl_params);
221
+ ctx.zh = zk;
222
+ CPPUNIT_ASSERT(zk);
223
+
224
+ // Wait for SASL auth to complete and handle to be connected.
225
+ CPPUNIT_ASSERT(ctx.waitForConnected(zk));
226
+
227
+ // Assert can read.
228
+ char buf[1024];
229
+ int len = sizeof(buf);
230
+ rc = zoo_get(zk, "/", 0, buf, &len, 0);
231
+ CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
232
+
233
+ // Assert can not write.
234
+ char path[1024];
235
+ rc = zoo_create(zk, "/test", "hello", 5, &ZOO_OPEN_ACL_UNSAFE, 0, path, sizeof(path));
236
+ CPPUNIT_ASSERT_EQUAL((int)ZNOTREADONLY, rc);
237
+
238
+ stopServer();
239
+ }
240
+
241
+ void testClientSASLPacketOrder() {
242
+ startServer();
243
+
244
+ // Initialize Cyrus SASL.
245
+ CPPUNIT_ASSERT_EQUAL(sasl_client_init(NULL), SASL_OK);
246
+
247
+ // Initialize SASL parameters.
248
+ zoo_sasl_params_t sasl_params = { 0 };
249
+
250
+ sasl_params.service = "zookeeper";
251
+ sasl_params.host = "zk-sasl-md5";
252
+ sasl_params.mechlist = "DIGEST-MD5";
253
+ sasl_params.callbacks = zoo_sasl_make_basic_callbacks(
254
+ "myuser", NULL, "Zookeeper_SASLAuth.password");
255
+
256
+ // Connect.
257
+ watchctx_t ctx;
258
+ int rc = 0;
259
+ zhandle_t *zk = zookeeper_init_sasl(hostPorts, watcher, 10000, NULL,
260
+ &ctx, /*flags*/0, /*log_callback*/NULL, &sasl_params);
261
+ ctx.zh = zk;
262
+ CPPUNIT_ASSERT(zk);
263
+
264
+ // No wait: try and queue a packet before SASL auth is complete.
265
+ char buf[1024];
266
+ int len = sizeof(buf);
267
+ rc = zoo_get(zk, "/", 0, buf, &len, 0);
268
+ CPPUNIT_ASSERT_EQUAL((int)ZOK, rc);
269
+
270
+ stopServer();
271
+ }
272
+
273
+ #ifdef __APPLE__
274
+ #pragma GCC diagnostic pop
275
+ #endif
276
+
277
+ #endif /* HAVE_CYRUS_SASL_H */
278
+ };
279
+
280
+ const char Zookeeper_SASLAuth::hostPorts[] = "127.0.0.1:22181";
281
+
282
+ const char Zookeeper_SASLAuth::jaasConf[] =
283
+ "Server {\n"
284
+ " org.apache.zookeeper.server.auth.DigestLoginModule required\n"
285
+ " user_myuser=\"mypassword\";\n"
286
+ "};\n";
287
+
288
+ CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_SASLAuth);
289
+
290
+ #endif /* THREADED */
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/TestZookeeperClose.cc ADDED
@@ -0,0 +1,473 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #include <cppunit/extensions/HelperMacros.h>
20
+
21
+ #include "ZKMocks.h"
22
+
23
+ #ifdef THREADED
24
+ #include "PthreadMocks.h"
25
+ #endif
26
+
27
+ using namespace std;
28
+
29
+ class Zookeeper_close : public CPPUNIT_NS::TestFixture
30
+ {
31
+ CPPUNIT_TEST_SUITE(Zookeeper_close);
32
+ #ifdef THREADED
33
+ CPPUNIT_TEST(testIOThreadStoppedOnExpire);
34
+ #endif
35
+ CPPUNIT_TEST(testCloseUnconnected);
36
+ CPPUNIT_TEST(testCloseUnconnected1);
37
+ CPPUNIT_TEST(testCloseConnected1);
38
+ CPPUNIT_TEST(testCloseFromWatcher1);
39
+ CPPUNIT_TEST_SUITE_END();
40
+ zhandle_t *zh;
41
+ static void watcher(zhandle_t *, int, int, const char *,void*){}
42
+ FILE *logfile;
43
+ public:
44
+
45
+ Zookeeper_close() {
46
+ logfile = openlogfile("Zookeeper_close");
47
+ }
48
+
49
+ ~Zookeeper_close() {
50
+ if (logfile) {
51
+ fflush(logfile);
52
+ fclose(logfile);
53
+ logfile = 0;
54
+ }
55
+ }
56
+
57
+ void setUp()
58
+ {
59
+ zoo_set_log_stream(logfile);
60
+
61
+ zoo_deterministic_conn_order(0);
62
+ zh=0;
63
+ }
64
+
65
+ void tearDown()
66
+ {
67
+ zookeeper_close(zh);
68
+ }
69
+
70
+ class CloseOnSessionExpired: public WatcherAction{
71
+ public:
72
+ CloseOnSessionExpired(bool callClose=true):
73
+ callClose_(callClose),rc(ZOK){}
74
+ virtual void onSessionExpired(zhandle_t* zh){
75
+ memcpy(&lzh,zh,sizeof(lzh));
76
+ if(callClose_)
77
+ rc=zookeeper_close(zh);
78
+ }
79
+ zhandle_t lzh;
80
+ bool callClose_;
81
+ int rc;
82
+ };
83
+
84
+ #ifndef THREADED
85
+ void testCloseUnconnected()
86
+ {
87
+ zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0);
88
+ CPPUNIT_ASSERT(zh!=0);
89
+
90
+ // do not actually free the memory while in zookeeper_close()
91
+ Mock_free_noop freeMock;
92
+ // make a copy of zhandle before close() overwrites some of
93
+ // it members with NULLs
94
+ zhandle_t lzh;
95
+ memcpy(&lzh,zh,sizeof(lzh));
96
+ int rc=zookeeper_close(zh);
97
+ zhandle_t* savezh=zh; zh=0;
98
+ freeMock.disable(); // disable mock's fake free()- use libc's free() instead
99
+
100
+ // verify that zookeeper_close has done its job
101
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
102
+ // memory
103
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
104
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
105
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data));
106
+ // This cannot be maintained properly CPPUNIT_ASSERT_EQUAL(9,freeMock.callCounter);
107
+ }
108
+ void testCloseUnconnected1()
109
+ {
110
+ zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0);
111
+ CPPUNIT_ASSERT(zh!=0);
112
+ // simulate connected state
113
+ zh->fd->sock=ZookeeperServer::FD;
114
+ zh->state=ZOO_CONNECTED_STATE;
115
+ Mock_flush_send_queue zkMock;
116
+ // do not actually free the memory while in zookeeper_close()
117
+ Mock_free_noop freeMock;
118
+ // make a copy of zhandle before close() overwrites some of
119
+ // it members with NULLs
120
+ zhandle_t lzh;
121
+ memcpy(&lzh,zh,sizeof(lzh));
122
+ int rc=zookeeper_close(zh);
123
+ zhandle_t* savezh=zh; zh=0;
124
+ freeMock.disable(); // disable mock's fake free()- use libc's free() instead
125
+
126
+ // verify that zookeeper_close has done its job
127
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
128
+ // memory
129
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
130
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
131
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data));
132
+ // the close request sent?
133
+ CPPUNIT_ASSERT_EQUAL(1,zkMock.counter);
134
+ }
135
+ void testCloseConnected1()
136
+ {
137
+ ZookeeperServer zkServer;
138
+ // poll() will called from zookeeper_close()
139
+ Mock_poll pollMock(&zkServer,ZookeeperServer::FD);
140
+
141
+ zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0);
142
+ CPPUNIT_ASSERT(zh!=0);
143
+ CPPUNIT_ASSERT_EQUAL(ZOO_NOTCONNECTED_STATE, zoo_state(zh));
144
+
145
+ Mock_gettimeofday timeMock;
146
+
147
+ int fd=0;
148
+ int interest=0;
149
+ timeval tv;
150
+ int rc=zookeeper_interest(zh,&fd,&interest,&tv);
151
+
152
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
153
+ CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh));
154
+ CPPUNIT_ASSERT_EQUAL(ZOOKEEPER_READ|ZOOKEEPER_WRITE,interest);
155
+
156
+ rc=zookeeper_process(zh,interest);
157
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
158
+ CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh));
159
+
160
+ rc=zookeeper_interest(zh,&fd,&interest,&tv);
161
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
162
+ rc=zookeeper_process(zh,interest);
163
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
164
+ CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTED_STATE,zoo_state(zh));
165
+ // do not actually free the memory while in zookeeper_close()
166
+ Mock_free_noop freeMock;
167
+ // make a copy of zhandle before close() overwrites some of
168
+ // it members with NULLs
169
+ zhandle_t lzh;
170
+ memcpy(&lzh,zh,sizeof(lzh));
171
+ zookeeper_close(zh);
172
+ zhandle_t* savezh=zh; zh=0;
173
+ freeMock.disable(); // disable mock's fake free()- use libc's free() instead
174
+ // memory
175
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
176
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
177
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data));
178
+ // the close request sent?
179
+ CPPUNIT_ASSERT_EQUAL(1,(int)zkServer.closeSent);
180
+ }
181
+ void testCloseFromWatcher1()
182
+ {
183
+ Mock_gettimeofday timeMock;
184
+
185
+ ZookeeperServer zkServer;
186
+ // make the server return a non-matching session id
187
+ zkServer.returnSessionExpired();
188
+ // poll() will called from zookeeper_close()
189
+ Mock_poll pollMock(&zkServer,ZookeeperServer::FD);
190
+
191
+ CloseOnSessionExpired closeAction;
192
+ zh=zookeeper_init("localhost:2121",activeWatcher,10000,
193
+ TEST_CLIENT_ID,&closeAction,0);
194
+ CPPUNIT_ASSERT(zh!=0);
195
+
196
+ int fd=0;
197
+ int interest=0;
198
+ timeval tv;
199
+ // initiate connection
200
+ int rc=zookeeper_interest(zh,&fd,&interest,&tv);
201
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
202
+ CPPUNIT_ASSERT_EQUAL(ZOO_CONNECTING_STATE,zoo_state(zh));
203
+ CPPUNIT_ASSERT_EQUAL(ZOOKEEPER_READ|ZOOKEEPER_WRITE,interest);
204
+ rc=zookeeper_process(zh,interest);
205
+ // make sure the handshake in progress
206
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
207
+ CPPUNIT_ASSERT_EQUAL(ZOO_ASSOCIATING_STATE,zoo_state(zh));
208
+ rc=zookeeper_interest(zh,&fd,&interest,&tv);
209
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
210
+
211
+ // do not actually free the memory while in zookeeper_close()
212
+ Mock_free_noop freeMock;
213
+ // should call the watcher with ZOO_EXPIRED_SESSION_STATE state
214
+ rc=zookeeper_process(zh,interest);
215
+ zhandle_t* savezh=zh; zh=0;
216
+ freeMock.disable(); // disable mock's fake free()- use libc's free() instead
217
+
218
+ CPPUNIT_ASSERT_EQUAL(ZOO_EXPIRED_SESSION_STATE,zoo_state(savezh));
219
+ // memory
220
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
221
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.hostname));
222
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.addrs.data));
223
+ // make sure the close request NOT sent
224
+ CPPUNIT_ASSERT_EQUAL(0,(int)zkServer.closeSent);
225
+ }
226
+ #else
227
+ void testCloseUnconnected()
228
+ {
229
+ // disable threading
230
+ MockPthreadZKNull pthreadMock;
231
+ zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0);
232
+
233
+ CPPUNIT_ASSERT(zh!=0);
234
+ adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv;
235
+ CPPUNIT_ASSERT(adaptor!=0);
236
+
237
+ // do not actually free the memory while in zookeeper_close()
238
+ Mock_free_noop freeMock;
239
+ // make a copy of zhandle before close() overwrites some of
240
+ // it members with NULLs
241
+ zhandle_t lzh;
242
+ memcpy(&lzh,zh,sizeof(lzh));
243
+ int rc=zookeeper_close(zh);
244
+ zhandle_t* savezh=zh; zh=0;
245
+ // we're done, disable mock's fake free(), use libc's free() instead
246
+ freeMock.disable();
247
+
248
+ // verify that zookeeper_close has done its job
249
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
250
+ // memory
251
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
252
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
253
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data));
254
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor));
255
+ // Cannot be maintained accurately: CPPUNIT_ASSERT_EQUAL(10,freeMock.callCounter);
256
+ // threads
257
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(adaptor->io));
258
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(adaptor->completion));
259
+ // mutexes
260
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->to_process.lock));
261
+ CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->to_process.lock));
262
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->to_send.lock));
263
+ CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->to_send.lock));
264
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->sent_requests.lock));
265
+ CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->sent_requests.lock));
266
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->completions_to_process.lock));
267
+ CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->completions_to_process.lock));
268
+ // conditionals
269
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->sent_requests.cond));
270
+ CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->sent_requests.cond));
271
+ CPPUNIT_ASSERT_EQUAL(1,MockPthreadsNull::getDestroyCounter(&savezh->completions_to_process.cond));
272
+ CPPUNIT_ASSERT_EQUAL(0,MockPthreadsNull::getInvalidAccessCounter(&savezh->completions_to_process.cond));
273
+ }
274
+ void testCloseUnconnected1()
275
+ {
276
+ for(int i=0; i<100;i++){
277
+ zh=zookeeper_init("localhost:2121",watcher,10000,0,0,0);
278
+ CPPUNIT_ASSERT(zh!=0);
279
+ adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv;
280
+ CPPUNIT_ASSERT(adaptor!=0);
281
+ int rc=zookeeper_close(zh);
282
+ zh=0;
283
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
284
+ }
285
+ }
286
+ void testCloseConnected1()
287
+ {
288
+ // frozen time -- no timeouts and no pings
289
+ Mock_gettimeofday timeMock;
290
+
291
+ for(int i=0;i<100;i++){
292
+ ZookeeperServer zkServer;
293
+ Mock_poll pollMock(&zkServer,ZookeeperServer::FD);
294
+ // use a checked version of pthread calls
295
+ CheckedPthread threadMock;
296
+ // do not actually free the memory while in zookeeper_close()
297
+ Mock_free_noop freeMock;
298
+
299
+ zh=zookeeper_init("localhost:2121",watcher,10000,TEST_CLIENT_ID,0,0);
300
+ CPPUNIT_ASSERT(zh!=0);
301
+ // make sure the client has connected
302
+ CPPUNIT_ASSERT(ensureCondition(ClientConnected(zh),1000)<1000);
303
+ // make a copy of zhandle before close() overwrites some of
304
+ // its members with NULLs
305
+ zhandle_t lzh;
306
+ memcpy(&lzh,zh,sizeof(lzh));
307
+ int rc=zookeeper_close(zh);
308
+ zhandle_t* savezh=zh; zh=0;
309
+ // we're done, disable mock's fake free(), use libc's free() instead
310
+ freeMock.disable();
311
+
312
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,rc);
313
+ adaptor_threads* adaptor=(adaptor_threads*)lzh.adaptor_priv;
314
+ // memory
315
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(savezh));
316
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.hostname));
317
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh.addrs.data));
318
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor));
319
+ // threads
320
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->io));
321
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->completion));
322
+ // mutexes
323
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->to_process.lock));
324
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->to_process.lock));
325
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->to_send.lock));
326
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->to_send.lock));
327
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->sent_requests.lock));
328
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->sent_requests.lock));
329
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->completions_to_process.lock));
330
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->completions_to_process.lock));
331
+ // conditionals
332
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->sent_requests.cond));
333
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->sent_requests.cond));
334
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&savezh->completions_to_process.cond));
335
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&savezh->completions_to_process.cond));
336
+ }
337
+ }
338
+
339
+ struct PointerFreed{
340
+ PointerFreed(Mock_free_noop& freeMock,void* ptr):
341
+ freeMock_(freeMock),ptr_(ptr){}
342
+ bool operator()() const{return freeMock_.isFreed(ptr_); }
343
+ Mock_free_noop& freeMock_;
344
+ void* ptr_;
345
+ };
346
+ // test if zookeeper_close may be called from a watcher callback on
347
+ // SESSION_EXPIRED event
348
+ void testCloseFromWatcher1()
349
+ {
350
+ // frozen time -- no timeouts and no pings
351
+ Mock_gettimeofday timeMock;
352
+
353
+ for(int i=0;i<100;i++){
354
+ ZookeeperServer zkServer;
355
+ // make the server return a non-matching session id
356
+ zkServer.returnSessionExpired();
357
+
358
+ Mock_poll pollMock(&zkServer,ZookeeperServer::FD);
359
+ // use a checked version of pthread calls
360
+ CheckedPthread threadMock;
361
+ // do not actually free the memory while in zookeeper_close()
362
+ Mock_free_noop freeMock;
363
+
364
+ CloseOnSessionExpired closeAction;
365
+ zh=zookeeper_init("localhost:2121",activeWatcher,10000,
366
+ TEST_CLIENT_ID,&closeAction,0);
367
+
368
+ CPPUNIT_ASSERT(zh!=0);
369
+ // we rely on the fact that zh is freed the last right before
370
+ // zookeeper_close() returns...
371
+ CPPUNIT_ASSERT(ensureCondition(PointerFreed(freeMock,zh),1000)<1000);
372
+ zhandle_t* lzh=zh;
373
+ zh=0;
374
+ // we're done, disable mock's fake free(), use libc's free() instead
375
+ freeMock.disable();
376
+
377
+ CPPUNIT_ASSERT_EQUAL((int)ZOK,closeAction.rc);
378
+ adaptor_threads* adaptor=(adaptor_threads*)closeAction.lzh.adaptor_priv;
379
+ // memory
380
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh));
381
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.hostname));
382
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.addrs.data));
383
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor));
384
+ // threads
385
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->io));
386
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->completion));
387
+ // mutexes
388
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_process.lock));
389
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_process.lock));
390
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_send.lock));
391
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_send.lock));
392
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.lock));
393
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.lock));
394
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.lock));
395
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.lock));
396
+ // conditionals
397
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.cond));
398
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.cond));
399
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.cond));
400
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.cond));
401
+ }
402
+ }
403
+
404
+ void testIOThreadStoppedOnExpire()
405
+ {
406
+ // frozen time -- no timeouts and no pings
407
+ Mock_gettimeofday timeMock;
408
+
409
+ for(int i=0;i<100;i++){
410
+ ZookeeperServer zkServer;
411
+ // make the server return a non-matching session id
412
+ zkServer.returnSessionExpired();
413
+
414
+ Mock_poll pollMock(&zkServer,ZookeeperServer::FD);
415
+ // use a checked version of pthread calls
416
+ CheckedPthread threadMock;
417
+ // do not call zookeeper_close() from the watcher
418
+ CloseOnSessionExpired closeAction(false);
419
+ zh=zookeeper_init("localhost:2121",activeWatcher,10000,
420
+ &testClientId,&closeAction,0);
421
+
422
+ // this is to ensure that if any assert fires, zookeeper_close()
423
+ // will still be called while all the mocks are in the scope!
424
+ CloseFinally guard(&zh);
425
+
426
+ CPPUNIT_ASSERT(zh!=0);
427
+ CPPUNIT_ASSERT(ensureCondition(SessionExpired(zh),1000)<1000);
428
+ CPPUNIT_ASSERT(ensureCondition(IOThreadStopped(zh),1000)<1000);
429
+ // make sure the watcher has been processed
430
+ CPPUNIT_ASSERT(ensureCondition(closeAction.isWatcherTriggered(),1000)<1000);
431
+ // make sure the threads have not been destroyed yet
432
+ adaptor_threads* adaptor=(adaptor_threads*)zh->adaptor_priv;
433
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getDestroyCounter(adaptor->io));
434
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getDestroyCounter(adaptor->completion));
435
+ // about to call zookeeper_close() -- no longer need the guard
436
+ guard.disarm();
437
+
438
+ // do not actually free the memory while in zookeeper_close()
439
+ Mock_free_noop freeMock;
440
+ zookeeper_close(zh);
441
+ zhandle_t* lzh=zh; zh=0;
442
+ // we're done, disable mock's fake free(), use libc's free() instead
443
+ freeMock.disable();
444
+
445
+ // memory
446
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(lzh));
447
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.hostname));
448
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(closeAction.lzh.addrs.data));
449
+ CPPUNIT_ASSERT_EQUAL(1,freeMock.getFreeCount(adaptor));
450
+ // threads
451
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->io));
452
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(adaptor->completion));
453
+ // mutexes
454
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_process.lock));
455
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_process.lock));
456
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->to_send.lock));
457
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->to_send.lock));
458
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.lock));
459
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.lock));
460
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.lock));
461
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.lock));
462
+ // conditionals
463
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->sent_requests.cond));
464
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->sent_requests.cond));
465
+ CPPUNIT_ASSERT_EQUAL(1,CheckedPthread::getDestroyCounter(&lzh->completions_to_process.cond));
466
+ CPPUNIT_ASSERT_EQUAL(0,CheckedPthread::getInvalidAccessCounter(&lzh->completions_to_process.cond));
467
+ }
468
+ }
469
+
470
+ #endif
471
+ };
472
+
473
+ CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_close);
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/ThreadingUtil.cc ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #include <sys/types.h>
20
+ #include "ThreadingUtil.h"
21
+ #include "LibCSymTable.h"
22
+
23
+ #ifdef THREADED
24
+
25
+ // ****************************************************************************
26
+ // Mutex wrapper
27
+ struct Mutex::Impl{
28
+ Impl(){
29
+ LIBC_SYMBOLS.pthread_mutex_init(&mut_, 0);
30
+ }
31
+ ~Impl(){
32
+ LIBC_SYMBOLS.pthread_mutex_destroy(&mut_);
33
+ }
34
+ pthread_mutex_t mut_;
35
+ };
36
+
37
+ Mutex::Mutex():impl_(new Impl) {}
38
+ Mutex::~Mutex() { delete impl_;}
39
+ void Mutex::acquire() {
40
+ LIBC_SYMBOLS.pthread_mutex_lock(&impl_->mut_);
41
+ }
42
+ void Mutex::release() {
43
+ LIBC_SYMBOLS.pthread_mutex_unlock(&impl_->mut_);
44
+ }
45
+
46
+ // ****************************************************************************
47
+ // Atomics
48
+ int32_t atomic_post_incr(volatile int32_t* operand, int32_t incr)
49
+ {
50
+ #if defined(__GNUC__)
51
+ return __sync_fetch_and_add(operand,incr);
52
+ #else
53
+ int32_t result;
54
+ __asm__ __volatile__(
55
+ "lock xaddl %0,%1\n"
56
+ : "=r"(result), "=m"(*operand)
57
+ : "0"(incr)
58
+ : "memory");
59
+ return result;
60
+ #endif
61
+ }
62
+ int32_t atomic_fetch_store(volatile int32_t *ptr, int32_t value)
63
+ {
64
+ #if defined(__GNUC__)
65
+ return __sync_lock_test_and_set(ptr,value);
66
+ #else
67
+ int32_t result;
68
+ __asm__ __volatile__("lock xchgl %0,%1\n"
69
+ : "=r"(result), "=m"(*ptr)
70
+ : "0"(value)
71
+ : "memory");
72
+ return result;
73
+ #endif
74
+ }
75
+ #else
76
+ int32_t atomic_post_incr(volatile int32_t* operand, int32_t incr){
77
+ int32_t v=*operand;
78
+ *operand+=incr;
79
+ return v;
80
+ }
81
+ int32_t atomic_fetch_store(volatile int32_t *ptr, int32_t value)
82
+ {
83
+ int32_t result=*ptr;
84
+ *ptr=value;
85
+ return result;
86
+ }
87
+ #endif // THREADED
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/Util.h ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ #ifndef UTIL_H_
20
+ #define UTIL_H_
21
+
22
+ #include <map>
23
+ #include <vector>
24
+ #include <string>
25
+
26
+ #include "zookeeper_log.h"
27
+
28
+ // number of elements in array
29
+ #define COUNTOF(array) sizeof(array)/sizeof(array[0])
30
+
31
+ #define DECLARE_WRAPPER(ret,sym,sig) \
32
+ extern "C" ret __real_##sym sig; \
33
+ extern "C" ret __wrap_##sym sig
34
+
35
+ #define CALL_REAL(sym,params) \
36
+ __real_##sym params
37
+
38
+ // must include "src/zookeeper_log.h" to be able to use this macro
39
+ #define TEST_TRACE(x...) \
40
+ log_message(LOGSTREAM, ZOO_LOG_LEVEL_DEBUG,__LINE__,__func__,x)
41
+
42
+ extern const std::string EMPTY_STRING;
43
+
44
+ // *****************************************************************************
45
+ // A bit of wizardry to get to the bare type from a reference or a pointer
46
+ // to the type
47
+ template <class T>
48
+ struct TypeOp {
49
+ typedef T BareT;
50
+ typedef T ArgT;
51
+ };
52
+
53
+ // partial specialization for reference types
54
+ template <class T>
55
+ struct TypeOp<T&>{
56
+ typedef T& ArgT;
57
+ typedef typename TypeOp<T>::BareT BareT;
58
+ };
59
+
60
+ // partial specialization for pointers
61
+ template <class T>
62
+ struct TypeOp<T*>{
63
+ typedef T* ArgT;
64
+ typedef typename TypeOp<T>::BareT BareT;
65
+ };
66
+
67
+ // *****************************************************************************
68
+ // Container utilities
69
+
70
+ template <class K, class V>
71
+ void putValue(std::map<K,V>& map,const K& k, const V& v){
72
+ typedef std::map<K,V> Map;
73
+ typename Map::const_iterator it=map.find(k);
74
+ if(it==map.end())
75
+ map.insert(typename Map::value_type(k,v));
76
+ else
77
+ map[k]=v;
78
+ }
79
+
80
+ template <class K, class V>
81
+ bool getValue(const std::map<K,V>& map,const K& k,V& v){
82
+ typedef std::map<K,V> Map;
83
+ typename Map::const_iterator it=map.find(k);
84
+ if(it==map.end())
85
+ return false;
86
+ v=it->second;
87
+ return true;
88
+ }
89
+
90
+ // *****************************************************************************
91
+ // misc utils
92
+
93
+ // millisecond sleep
94
+ void millisleep(int ms);
95
+ FILE *openlogfile(const char* name);
96
+ // evaluate given predicate until it returns true or the timeout
97
+ // (in millis) has expired
98
+ template<class Predicate>
99
+ int ensureCondition(const Predicate& p,int timeout){
100
+ int elapsed=0;
101
+ while(!p() && elapsed<timeout){
102
+ millisleep(2);
103
+ elapsed+=2;
104
+ }
105
+ return elapsed;
106
+ };
107
+
108
+ // *****************************************************************************
109
+ // test global configuration data
110
+ class TestConfig{
111
+ typedef std::vector<std::string> CmdLineOptList;
112
+ public:
113
+ typedef CmdLineOptList::const_iterator const_iterator;
114
+ TestConfig(){}
115
+ ~TestConfig(){}
116
+ void addConfigFromCmdLine(int argc, char* argv[]){
117
+ if(argc>=2)
118
+ testName_=argv[1];
119
+ for(int i=2; i<argc;++i)
120
+ cmdOpts_.push_back(argv[i]);
121
+ }
122
+ const_iterator getExtraOptBegin() const {return cmdOpts_.begin();}
123
+ const_iterator getExtraOptEnd() const {return cmdOpts_.end();}
124
+ size_t getExtraOptCount() const {
125
+ return cmdOpts_.size();
126
+ }
127
+ const std::string& getTestName() const {
128
+ return testName_=="all"?EMPTY_STRING:testName_;
129
+ }
130
+ private:
131
+ CmdLineOptList cmdOpts_;
132
+ std::string testName_;
133
+ };
134
+
135
+ extern TestConfig globalTestConfig;
136
+
137
+ #endif /*UTIL_H_*/
local-test-zookeeper-delta-02/afc-zookeeper/zookeeper-client/zookeeper-client-c/tests/zoo.cfg ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tickTime=500
2
+ initLimit=10
3
+ syncLimit=5
4
+ dataDir=TMPDIR/zkdata
5
+ maxClientCnxns=MAXCLIENTCONNECTIONS
6
+ localSessionsEnabled=true
7
+
8
+ clientPort=CLIENTPORT
9
+ secureClientPort=22281
10
+ serverCnxnFactory=org.apache.zookeeper.server.NettyServerCnxnFactory
11
+ ssl.keyStore.location=CERTDIR/server.jks
12
+ ssl.keyStore.password=password
13
+ ssl.trustStore.location=CERTDIR/servertrust.jks
14
+ ssl.trustStore.password=password
15
+