libcouchbase 0.3.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libcouchbase/CMakeLists.txt +6 -8
  3. data/ext/libcouchbase/README.markdown +2 -2
  4. data/ext/libcouchbase/RELEASE_NOTES.markdown +229 -2
  5. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
  6. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +18 -0
  7. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +3 -2
  8. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  9. data/ext/libcouchbase/cmake/config-cmake.h.in +4 -0
  10. data/ext/libcouchbase/cmake/defs.mk.in +0 -2
  11. data/ext/libcouchbase/cmake/source_files.cmake +21 -5
  12. data/ext/libcouchbase/contrib/cJSON/cJSON.c +1 -1
  13. data/ext/libcouchbase/contrib/cbsasl/src/client.c +2 -0
  14. data/ext/libcouchbase/example/users/README +48 -0
  15. data/ext/libcouchbase/example/users/users.c +147 -0
  16. data/ext/libcouchbase/include/libcouchbase/auth.h +175 -31
  17. data/ext/libcouchbase/include/libcouchbase/cntl.h +82 -1
  18. data/ext/libcouchbase/include/libcouchbase/couchbase.h +45 -3
  19. data/ext/libcouchbase/include/libcouchbase/error.h +19 -1
  20. data/ext/libcouchbase/include/libcouchbase/iops.h +3 -0
  21. data/ext/libcouchbase/include/libcouchbase/n1ql.h +31 -1
  22. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +4 -1
  23. data/ext/libcouchbase/include/libcouchbase/subdoc.h +36 -2
  24. data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
  25. data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
  26. data/ext/libcouchbase/include/memcached/protocol_binary.h +24 -1146
  27. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  28. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
  29. data/ext/libcouchbase/src/README.md +0 -2
  30. data/ext/libcouchbase/src/auth-priv.h +23 -4
  31. data/ext/libcouchbase/src/auth.cc +51 -43
  32. data/ext/libcouchbase/src/bootstrap.cc +244 -0
  33. data/ext/libcouchbase/src/bootstrap.h +58 -38
  34. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +120 -158
  35. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  36. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +526 -0
  37. data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
  38. data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
  39. data/ext/libcouchbase/src/bucketconfig/clconfig.h +410 -386
  40. data/ext/libcouchbase/src/bucketconfig/confmon.cc +393 -0
  41. data/ext/libcouchbase/src/cbft.cc +22 -27
  42. data/ext/libcouchbase/src/cntl.cc +56 -22
  43. data/ext/libcouchbase/src/connspec.cc +47 -6
  44. data/ext/libcouchbase/src/connspec.h +27 -0
  45. data/ext/libcouchbase/src/dns-srv.cc +147 -0
  46. data/ext/libcouchbase/src/dump.cc +3 -3
  47. data/ext/libcouchbase/src/errmap.cc +173 -0
  48. data/ext/libcouchbase/src/errmap.h +198 -0
  49. data/ext/libcouchbase/src/getconfig.cc +7 -33
  50. data/ext/libcouchbase/src/handler.cc +118 -7
  51. data/ext/libcouchbase/src/hostlist.cc +0 -36
  52. data/ext/libcouchbase/src/hostlist.h +44 -62
  53. data/ext/libcouchbase/src/http/http-priv.h +125 -112
  54. data/ext/libcouchbase/src/http/http.cc +27 -35
  55. data/ext/libcouchbase/src/http/http.h +1 -34
  56. data/ext/libcouchbase/src/http/http_io.cc +28 -36
  57. data/ext/libcouchbase/src/instance.cc +131 -34
  58. data/ext/libcouchbase/src/internal.h +58 -26
  59. data/ext/libcouchbase/src/jsparse/parser.cc +136 -210
  60. data/ext/libcouchbase/src/jsparse/parser.h +84 -98
  61. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  62. data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
  63. data/ext/libcouchbase/src/lcbio/connect.cc +569 -0
  64. data/ext/libcouchbase/src/lcbio/connect.h +16 -7
  65. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  66. data/ext/libcouchbase/src/lcbio/iotable.h +101 -16
  67. data/ext/libcouchbase/src/lcbio/{ioutils.c → ioutils.cc} +30 -51
  68. data/ext/libcouchbase/src/lcbio/ioutils.h +29 -90
  69. data/ext/libcouchbase/src/lcbio/manager.cc +543 -0
  70. data/ext/libcouchbase/src/lcbio/manager.h +133 -96
  71. data/ext/libcouchbase/src/lcbio/protoctx.c +2 -2
  72. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  73. data/ext/libcouchbase/src/mc/mcreq.c +11 -2
  74. data/ext/libcouchbase/src/mc/mcreq.h +9 -2
  75. data/ext/libcouchbase/src/mcserver/mcserver.cc +175 -43
  76. data/ext/libcouchbase/src/mcserver/mcserver.h +9 -13
  77. data/ext/libcouchbase/src/mcserver/negotiate.cc +181 -62
  78. data/ext/libcouchbase/src/mcserver/negotiate.h +1 -3
  79. data/ext/libcouchbase/src/mctx-helper.h +51 -0
  80. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
  81. data/ext/libcouchbase/src/n1ql/n1ql.cc +74 -42
  82. data/ext/libcouchbase/src/netbuf/netbuf.c +4 -4
  83. data/ext/libcouchbase/src/newconfig.cc +6 -6
  84. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  85. data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
  86. data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
  87. data/ext/libcouchbase/src/operations/durability.cc +6 -26
  88. data/ext/libcouchbase/src/operations/durability_internal.h +6 -3
  89. data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
  90. data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +68 -93
  91. data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
  92. data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
  93. data/ext/libcouchbase/src/operations/stats.cc +3 -8
  94. data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
  95. data/ext/libcouchbase/src/operations/subdoc.cc +129 -42
  96. data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
  97. data/ext/libcouchbase/src/packetutils.h +30 -2
  98. data/ext/libcouchbase/src/probes.d +1 -1
  99. data/ext/libcouchbase/src/rdb/rope.c +1 -1
  100. data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +2 -3
  101. data/ext/libcouchbase/src/retryq.cc +52 -14
  102. data/ext/libcouchbase/src/retryq.h +3 -3
  103. data/ext/libcouchbase/src/settings.c +5 -0
  104. data/ext/libcouchbase/src/settings.h +11 -0
  105. data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
  106. data/ext/libcouchbase/src/ssl/ssl_common.c +2 -0
  107. data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
  108. data/ext/libcouchbase/src/strcodecs/strcodecs.h +1 -1
  109. data/ext/libcouchbase/src/trace.h +4 -4
  110. data/ext/libcouchbase/src/vbucket/vbucket.c +6 -10
  111. data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
  112. data/ext/libcouchbase/src/views/docreq.h +24 -30
  113. data/ext/libcouchbase/src/views/viewreq.cc +318 -0
  114. data/ext/libcouchbase/src/views/viewreq.h +43 -13
  115. data/ext/libcouchbase/tests/basic/t_connstr.cc +88 -50
  116. data/ext/libcouchbase/tests/basic/t_creds.cc +47 -5
  117. data/ext/libcouchbase/tests/basic/t_host.cc +67 -75
  118. data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -82
  119. data/ext/libcouchbase/tests/basic/t_misc.cc +1 -1
  120. data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +0 -1
  121. data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
  122. data/ext/libcouchbase/tests/ioserver/connection.cc +1 -1
  123. data/ext/libcouchbase/tests/ioserver/ioserver.cc +19 -6
  124. data/ext/libcouchbase/tests/iotests/mock-environment.cc +28 -2
  125. data/ext/libcouchbase/tests/iotests/mock-environment.h +51 -1
  126. data/ext/libcouchbase/tests/iotests/t_behavior.cc +1 -7
  127. data/ext/libcouchbase/tests/iotests/t_confmon.cc +97 -115
  128. data/ext/libcouchbase/tests/iotests/t_durability.cc +0 -1
  129. data/ext/libcouchbase/tests/iotests/t_eerrs.cc +119 -0
  130. data/ext/libcouchbase/tests/iotests/t_errmap.cc +178 -0
  131. data/ext/libcouchbase/tests/iotests/t_misc.cc +3 -3
  132. data/ext/libcouchbase/tests/iotests/t_netfail.cc +1 -1
  133. data/ext/libcouchbase/tests/iotests/t_obseqno.cc +0 -1
  134. data/ext/libcouchbase/tests/iotests/t_subdoc.cc +18 -11
  135. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  136. data/ext/libcouchbase/tests/socktests/socktest.cc +7 -10
  137. data/ext/libcouchbase/tests/socktests/socktest.h +2 -3
  138. data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
  139. data/ext/libcouchbase/tests/socktests/t_manager.cc +5 -6
  140. data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
  141. data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
  142. data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
  143. data/ext/libcouchbase/tests/vbucket/t_config.cc +35 -5
  144. data/ext/libcouchbase/tools/CMakeLists.txt +2 -2
  145. data/ext/libcouchbase/tools/cbc-handlers.h +128 -0
  146. data/ext/libcouchbase/tools/cbc-n1qlback.cc +64 -10
  147. data/ext/libcouchbase/tools/cbc-pillowfight.cc +2 -2
  148. data/ext/libcouchbase/tools/cbc.cc +143 -10
  149. data/ext/libcouchbase/tools/docgen/loc.h +1 -1
  150. data/lib/libcouchbase/connection.rb +4 -3
  151. data/lib/libcouchbase/version.rb +1 -1
  152. metadata +37 -28
  153. data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
  154. data/ext/libcouchbase/src/bootstrap.c +0 -269
  155. data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
  156. data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
  157. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
  158. data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
  159. data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
  160. data/ext/libcouchbase/src/lcbio/connect.c +0 -557
  161. data/ext/libcouchbase/src/lcbio/manager.c +0 -584
  162. data/ext/libcouchbase/src/packetutils.c +0 -37
  163. data/ext/libcouchbase/src/simplestring.c +0 -211
  164. data/ext/libcouchbase/src/simplestring.h +0 -228
  165. data/ext/libcouchbase/src/ssobuf.h +0 -82
  166. data/ext/libcouchbase/src/views/viewreq.c +0 -358
  167. data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -112,7 +112,7 @@ std::vector<int> MockEnvironment::getMcPorts(std::string bucket)
112
112
 
113
113
  std::vector<int> ret;
114
114
 
115
- for (int ii = 0; ii < payload.size(); ii++) {
115
+ for (int ii = 0; ii < (int)payload.size(); ii++) {
116
116
  ret.push_back(payload[ii].asInt());
117
117
  }
118
118
  return ret;
@@ -143,6 +143,31 @@ void MockEnvironment::setCCCP(bool enabled, std::string bucket,
143
143
  getResponse();
144
144
  }
145
145
 
146
+ void MockEnvironment::setEnhancedErrors(bool enabled, std::string bucket,
147
+ const std::vector<int>* nodes)
148
+ {
149
+ MockCommand cmd(MockCommand::SET_ENHANCED_ERRORS);
150
+ cmd.set("enabled", enabled);
151
+
152
+ if (!bucket.empty()) {
153
+ cmd.set("bucket", bucket);
154
+ }
155
+
156
+ if (nodes != NULL) {
157
+ const std::vector<int>& v = *nodes;
158
+ Json::Value array(Json::arrayValue);
159
+
160
+ for (std::vector<int>::const_iterator ii = v.begin(); ii != v.end(); ii++) {
161
+ array.append(*ii);
162
+ }
163
+
164
+ cmd.set("servers", array);
165
+ }
166
+
167
+ sendCommand(cmd);
168
+ getResponse();
169
+ }
170
+
146
171
  void MockEnvironment::sendCommand(MockCommand &cmd)
147
172
  {
148
173
  std::string s = cmd.encode();
@@ -166,6 +191,7 @@ void MockEnvironment::getResponse(MockResponse& ret)
166
191
  ret.assign(rbuf);
167
192
  if (!ret.isOk()) {
168
193
  std::cerr << "Mock command failed!" << std::endl;
194
+ std::cerr << ret.constResp()["error"].asString() << std::endl;
169
195
  std::cerr << ret;
170
196
  }
171
197
  }
@@ -386,7 +412,7 @@ void MockEnvironment::SetUp()
386
412
  }
387
413
  serverParams = ServerParams(http,
388
414
  bucketName.c_str(),
389
- bucketName.c_str(),
415
+ userName.c_str(),
390
416
  NULL);
391
417
 
392
418
  // Mock 0.6
@@ -71,7 +71,11 @@ class MockCommand
71
71
  X(GET_MCPORTS) \
72
72
  X(SET_CCCP) \
73
73
  X(REGEN_VBCOORDS) \
74
- X(RESET_QUERYSTATE)
74
+ X(RESET_QUERYSTATE) \
75
+ X(OPFAIL) \
76
+ X(START_RETRY_VERIFY) \
77
+ X(CHECK_RETRY_VERIFY) \
78
+ X(SET_ENHANCED_ERRORS)
75
79
 
76
80
  public:
77
81
  enum Code {
@@ -164,6 +168,38 @@ protected:
164
168
  std::string bucket;
165
169
  };
166
170
 
171
+ class MockOpfailCommand : public MockCommand
172
+ {
173
+ public:
174
+ MockOpfailCommand(uint16_t errcode, int index, int count = -1,
175
+ std::string bucketstr = "default")
176
+ : MockCommand(OPFAIL) {
177
+ set("count", count);
178
+ set("bucket", bucketstr);
179
+ set("code", errcode);
180
+
181
+ Json::Value srvlist(Json::arrayValue);
182
+ srvlist.append(index);
183
+ set("servers", srvlist);
184
+ }
185
+ };
186
+
187
+ class MockOpFailClearCommand : public MockCommand {
188
+ public:
189
+ MockOpFailClearCommand(size_t nservers, std::string bucketstr = "default")
190
+ : MockCommand(OPFAIL) {
191
+ set("count", -1);
192
+ set("bucket", bucketstr);
193
+ set("code", 0);
194
+
195
+ Json::Value srvlist(Json::arrayValue);
196
+ for (size_t ii = 0; ii < nservers; ++ii) {
197
+ srvlist.append(static_cast<int>(ii));
198
+ }
199
+ set("servers", srvlist);
200
+ }
201
+ };
202
+
167
203
  class MockResponse
168
204
  {
169
205
  public:
@@ -277,6 +313,19 @@ public:
277
313
  std::string bucket = "",
278
314
  const std::vector<int>* nodes = NULL);
279
315
 
316
+ /**
317
+ * Enable enhanced errors on the mock cluster
318
+ *
319
+ * This includes generation event id (ref), and setting context for some errors
320
+ * .
321
+ * @param bucket the bucket on which to enable enhanced errors
322
+ * @param nodes a list of by-index nodes on which to enable Enhanced Errors. If NULL
323
+ * then all nodes are enabled
324
+ */
325
+ void setEnhancedErrors(bool enabled,
326
+ std::string bucket = "",
327
+ const std::vector<int>* nodes = NULL);
328
+
280
329
  /**
281
330
  * Create a connection to the mock/real server.
282
331
  *
@@ -352,6 +401,7 @@ protected:
352
401
  lcb_io_opt_st *iops;
353
402
  std::set<std::string> featureRegistry;
354
403
  std::string bucketName;
404
+ std::string userName;
355
405
  const char **argv;
356
406
  void clearAndReset();
357
407
 
@@ -212,13 +212,7 @@ TEST_F(Behavior, BadPluginEnvironment)
212
212
 
213
213
  // Find a DLL that we know can be loaded, but doesn't have the symbols
214
214
  // we need. For windows, we use the unqualified name,
215
- #ifdef _WIN32
216
- const char *dllname = "kernel32.dll.";
217
- #elif __APPLE__
218
- const char *dllname = "libm.dylib";
219
- #else
220
- const char *dllname = "libm.so";
221
- #endif
215
+ const char *dllname = TEST_SHARED_OBJECT;
222
216
 
223
217
  setPluginEnv(dllname, "nonexist-symbol");
224
218
  ASSERT_EQ(lcb_create(&instance2, NULL), LCB_DLSYM_FAILED);
@@ -7,130 +7,115 @@
7
7
  #include <lcbio/iotable.h>
8
8
  #include <set>
9
9
 
10
- class Confmon : public ::testing::Test
10
+ using namespace lcb::clconfig;
11
+
12
+ class ConfmonTest : public ::testing::Test
11
13
  {
12
14
  void SetUp() {
13
15
  MockEnvironment::Reset();
14
16
  }
15
17
  };
16
18
 
17
- struct evstop_listener {
18
- clconfig_listener base;
19
+ struct evstop_listener : Listener {
19
20
  lcbio_pTABLE io;
20
21
  int called;
22
+
23
+ void clconfig_lsn(EventType event, ConfigInfo*) {
24
+ if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
25
+ return;
26
+ }
27
+ called = 1;
28
+ IOT_STOP(io);
29
+ }
30
+
31
+ evstop_listener() : Listener(), io(NULL), called(0) {
32
+ }
21
33
  };
22
34
 
23
35
  extern "C" {
24
- static void listen_callback1(clconfig_listener *lsn, clconfig_event_t event,
25
- clconfig_info *info)
36
+ static void listen_callback1(Listener *lsn, EventType event,
37
+ ConfigInfo *info)
26
38
  {
27
- if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
28
- return;
29
- }
30
-
31
- evstop_listener *me = reinterpret_cast<evstop_listener*>(lsn);
32
- me->called = 1;
33
- IOT_STOP(me->io);
34
39
  }
35
40
  }
36
41
 
37
- TEST_F(Confmon, testBasic)
42
+ TEST_F(ConfmonTest, testBasic)
38
43
  {
39
44
  HandleWrap hw;
40
45
  lcb_t instance;
41
46
  MockEnvironment::getInstance()->createConnection(hw, instance);
42
47
 
43
48
 
44
- lcb_confmon *mon = lcb_confmon_create(instance->settings, instance->iotable);
45
- clconfig_provider *http = lcb_confmon_get_provider(mon, LCB_CLCONFIG_HTTP);
46
- lcb_clconfig_http_enable(http);
47
- lcb_clconfig_http_set_nodes(http, instance->ht_nodes);
49
+ Confmon *mon = new Confmon(instance->settings, instance->iotable);
50
+ Provider *http = mon->get_provider(CLCONFIG_HTTP);
51
+ http->enable();
52
+ http->configure_nodes(*instance->ht_nodes);
48
53
 
49
- lcb_confmon_prepare(mon);
54
+ mon->prepare();
50
55
 
51
- EXPECT_EQ(NULL, lcb_confmon_get_config(mon));
52
- EXPECT_EQ(LCB_SUCCESS, lcb_confmon_start(mon));
53
- EXPECT_EQ(LCB_SUCCESS, lcb_confmon_start(mon));
54
- EXPECT_EQ(LCB_SUCCESS, lcb_confmon_stop(mon));
55
- EXPECT_EQ(LCB_SUCCESS, lcb_confmon_stop(mon));
56
+ EXPECT_EQ(NULL, mon->get_config());
57
+ mon->start();
58
+ mon->start(); // Twice!
59
+ mon->stop();
60
+ mon->stop();
56
61
 
57
62
  // Try to find a provider..
58
- clconfig_provider *provider = lcb_confmon_get_provider(mon, LCB_CLCONFIG_HTTP);
63
+ Provider *provider = mon->get_provider(CLCONFIG_HTTP);
59
64
  ASSERT_NE(0, provider->enabled);
60
65
 
61
- struct evstop_listener listener;
62
- memset(&listener, 0, sizeof(listener));
63
-
64
- listener.base.callback = listen_callback1;
65
- listener.base.parent = mon;
66
+ evstop_listener listener;
66
67
  listener.io = instance->iotable;
67
-
68
- lcb_confmon_add_listener(mon, &listener.base);
69
- lcb_confmon_start(mon);
68
+ mon->add_listener(&listener);
69
+ mon->start();
70
70
  IOT_START(instance->iotable);
71
71
  ASSERT_NE(0, listener.called);
72
-
73
- lcb_confmon_destroy(mon);
72
+ delete mon;
74
73
  }
75
74
 
76
75
 
77
- struct listener2 {
78
- clconfig_listener base;
76
+ struct listener2 : Listener {
79
77
  int call_count;
80
78
  lcbio_pTABLE io;
81
- clconfig_method_t last_source;
82
- std::set<clconfig_event_t> expected_events;
79
+ Method last_source;
80
+ std::set<EventType> expected_events;
83
81
 
84
82
  void reset() {
85
83
  call_count = 0;
86
- last_source = LCB_CLCONFIG_PHONY;
84
+ last_source = CLCONFIG_PHONY;
87
85
  expected_events.clear();
88
86
  }
89
87
 
90
- listener2() {
91
- memset(&base, 0, sizeof(base));
88
+ listener2() : Listener() {
92
89
  io = NULL;
93
90
  reset();
94
91
  }
95
- };
96
92
 
97
- static struct listener2* getListener2(const void *p)
98
- {
99
- return reinterpret_cast<struct listener2*>(const_cast<void*>(p));
100
- }
93
+ void clconfig_lsn(EventType event, ConfigInfo *info) {
94
+ if (event == CLCONFIG_EVENT_MONITOR_STOPPED) {
95
+ IOT_START(io);
96
+ return;
97
+ }
101
98
 
102
- extern "C" {
103
- static void listen_callback2(clconfig_listener *prov,
104
- clconfig_event_t event,
105
- clconfig_info *info)
106
- {
107
- // Increase the number of times we've received a callback..
108
- struct listener2* lsn = getListener2(prov);
99
+ if (!expected_events.empty()) {
100
+ if (expected_events.end() ==
101
+ expected_events.find(event)) {
102
+ return;
103
+ }
104
+ }
109
105
 
110
- if (event == CLCONFIG_EVENT_MONITOR_STOPPED) {
111
- IOT_START(lsn->io);
112
- return;
113
- }
106
+ call_count++;
107
+ last_source = info->get_origin();
108
+ IOT_STOP(io);
114
109
 
115
- if (!lsn->expected_events.empty()) {
116
- if (lsn->expected_events.end() ==
117
- lsn->expected_events.find(event)) {
118
- return;
119
- }
120
110
  }
111
+ };
121
112
 
122
- lsn->call_count++;
123
- lsn->last_source = info->origin;
124
- IOT_STOP(lsn->io);
125
- }
126
- }
127
-
128
- static void runConfmon(lcbio_pTABLE io, lcb_confmon *mon)
113
+ static void runConfmonTest(lcbio_pTABLE io, Confmon *mon)
129
114
  {
130
115
  IOT_START(io);
131
116
  }
132
117
 
133
- TEST_F(Confmon, testCycle)
118
+ TEST_F(ConfmonTest, testCycle)
134
119
  {
135
120
  HandleWrap hw;
136
121
  lcb_t instance;
@@ -143,59 +128,56 @@ TEST_F(Confmon, testCycle)
143
128
 
144
129
  mock->createConnection(hw, instance);
145
130
  instance->settings->bc_http_stream_time = 100000;
146
- instance->memd_sockpool->tmoidle = 100000;
131
+ instance->memd_sockpool->get_options().tmoidle = 100000;
147
132
 
148
- lcb_confmon *mon = lcb_confmon_create(instance->settings, instance->iotable);
133
+ Confmon *mon = new Confmon(instance->settings, instance->iotable);
149
134
 
150
135
  struct listener2 lsn;
151
- lsn.base.callback = listen_callback2;
152
136
  lsn.io = instance->iotable;
153
137
  lsn.reset();
154
-
155
- lcb_confmon_add_listener(mon, &lsn.base);
138
+ mon->add_listener(&lsn);
156
139
 
157
140
  mock->makeConnectParams(cropts, NULL);
158
- clconfig_provider *cccp = lcb_confmon_get_provider(mon, LCB_CLCONFIG_CCCP);
159
- clconfig_provider *http = lcb_confmon_get_provider(mon, LCB_CLCONFIG_HTTP);
141
+ Provider *cccp = mon->get_provider(CLCONFIG_CCCP);
142
+ Provider *http = mon->get_provider(CLCONFIG_HTTP);
160
143
 
161
- hostlist_t hl = hostlist_create();
162
- hostlist_add_stringz(hl, cropts.v.v2.mchosts, 11210);
163
- lcb_clconfig_cccp_enable(cccp, instance);
164
- lcb_clconfig_cccp_set_nodes(cccp, hl);
144
+ lcb::Hostlist hl;
145
+ hl.add(cropts.v.v2.mchosts, 11210);
146
+ cccp->enable(instance);
147
+ cccp->configure_nodes(hl);
165
148
 
166
- lcb_clconfig_http_enable(http);
167
- lcb_clconfig_http_set_nodes(http, instance->ht_nodes);
168
- hostlist_destroy(hl);
149
+ http->enable();
150
+ http->configure_nodes(*instance->ht_nodes);
169
151
 
170
- lcb_confmon_prepare(mon);
171
- lcb_confmon_start(mon);
152
+ mon->prepare();
153
+ mon->start();
172
154
  lsn.expected_events.insert(CLCONFIG_EVENT_GOT_NEW_CONFIG);
173
- runConfmon(lsn.io, mon);
155
+ runConfmonTest(lsn.io, mon);
174
156
 
175
157
  // Ensure CCCP is functioning properly and we're called only once.
176
158
  ASSERT_EQ(1, lsn.call_count);
177
- ASSERT_EQ(LCB_CLCONFIG_CCCP, lsn.last_source);
159
+ ASSERT_EQ(CLCONFIG_CCCP, lsn.last_source);
178
160
 
179
- lcb_confmon_start(mon);
161
+ mon->start();
180
162
  lsn.reset();
181
163
  lsn.expected_events.insert(CLCONFIG_EVENT_GOT_ANY_CONFIG);
182
- runConfmon(lsn.io, mon);
164
+ runConfmonTest(lsn.io, mon);
183
165
  ASSERT_EQ(1, lsn.call_count);
184
- ASSERT_EQ(LCB_CLCONFIG_CCCP, lsn.last_source);
166
+ ASSERT_EQ(CLCONFIG_CCCP, lsn.last_source);
185
167
 
186
168
  mock->setCCCP(false);
187
169
  mock->failoverNode(5);
188
170
  lsn.reset();
189
- lcb_confmon_start(mon);
171
+ mon->start();
190
172
  lsn.expected_events.insert(CLCONFIG_EVENT_GOT_ANY_CONFIG);
191
173
  lsn.expected_events.insert(CLCONFIG_EVENT_GOT_NEW_CONFIG);
192
- runConfmon(lsn.io, mon);
193
- ASSERT_EQ(LCB_CLCONFIG_HTTP, lsn.last_source);
174
+ runConfmonTest(lsn.io, mon);
175
+ ASSERT_EQ(CLCONFIG_HTTP, lsn.last_source);
194
176
  ASSERT_EQ(1, lsn.call_count);
195
- lcb_confmon_destroy(mon);
177
+ delete mon;
196
178
  }
197
179
 
198
- TEST_F(Confmon, testBootstrapMethods)
180
+ TEST_F(ConfmonTest, testBootstrapMethods)
199
181
  {
200
182
  lcb_t instance;
201
183
  HandleWrap hw;
@@ -204,38 +186,38 @@ TEST_F(Confmon, testBootstrapMethods)
204
186
  ASSERT_EQ(LCB_SUCCESS, err);
205
187
 
206
188
  // Try the various bootstrap times
207
- struct lcb_BOOTSTRAP *bs = instance->bootstrap;
208
- hrtime_t last = bs->last_refresh, cur = 0;
189
+ lcb::Bootstrap* bs = instance->bs_state;
190
+ hrtime_t last = bs->get_last_refresh(), cur = 0;
209
191
 
210
192
  // Reset it for the time being
211
- bs->last_refresh = 0;
212
- lcb_confmon_stop(instance->confmon);
193
+ bs->reset_last_refresh();
194
+ instance->confmon->stop();
213
195
 
214
196
  // Refreshing now should work
215
- lcb_bootstrap_common(instance, LCB_BS_REFRESH_THROTTLE);
216
- ASSERT_NE(0, lcb_confmon_is_refreshing(instance->confmon));
197
+ instance->bootstrap(lcb::BS_REFRESH_THROTTLE);
198
+ ASSERT_TRUE(instance->confmon->is_refreshing());
217
199
 
218
- cur = bs->last_refresh;
200
+ cur = bs->get_last_refresh();
219
201
  ASSERT_GT(cur, 0);
220
- ASSERT_EQ(0, bs->errcounter);
202
+ ASSERT_EQ(0, bs->get_errcounter());
221
203
  last = cur;
222
204
 
223
205
  // Stop it, so the state is reset
224
- lcb_confmon_stop(instance->confmon);
225
- ASSERT_EQ(0, lcb_confmon_is_refreshing(instance->confmon));
206
+ instance->confmon->stop();
207
+ ASSERT_FALSE(instance->confmon->is_refreshing());
226
208
 
227
- lcb_bootstrap_common(instance, LCB_BS_REFRESH_THROTTLE|LCB_BS_REFRESH_INCRERR);
228
- ASSERT_EQ(last, bs->last_refresh);
229
- ASSERT_EQ(1, bs->errcounter);
209
+ instance->bootstrap(lcb::BS_REFRESH_THROTTLE|lcb::BS_REFRESH_INCRERR);
210
+ ASSERT_EQ(last, bs->get_last_refresh());
211
+ ASSERT_EQ(1, bs->get_errcounter());
230
212
 
231
213
  // Ensure that a throttled-without-incr doesn't actually incr
232
- lcb_bootstrap_common(instance, LCB_BS_REFRESH_THROTTLE);
233
- ASSERT_EQ(1, bs->errcounter);
214
+ instance->bootstrap(lcb::BS_REFRESH_THROTTLE);
215
+ ASSERT_EQ(1, bs->get_errcounter());
234
216
 
235
217
  // No refresh yet
236
- ASSERT_EQ(0, lcb_confmon_is_refreshing(instance->confmon));
218
+ ASSERT_FALSE(instance->confmon->is_refreshing());
237
219
 
238
- lcb_bootstrap_common(instance, LCB_BS_REFRESH_ALWAYS);
239
- ASSERT_NE(0, lcb_confmon_is_refreshing(instance->confmon));
240
- lcb_confmon_stop(instance->confmon);
220
+ instance->bootstrap(lcb::BS_REFRESH_ALWAYS);
221
+ ASSERT_TRUE(instance->confmon->is_refreshing());
222
+ instance->confmon->stop();
241
223
  }