libcouchbase 0.3.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libcouchbase/CMakeLists.txt +6 -8
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +229 -2
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +18 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +3 -2
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +4 -0
- data/ext/libcouchbase/cmake/defs.mk.in +0 -2
- data/ext/libcouchbase/cmake/source_files.cmake +21 -5
- data/ext/libcouchbase/contrib/cJSON/cJSON.c +1 -1
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +2 -0
- data/ext/libcouchbase/example/users/README +48 -0
- data/ext/libcouchbase/example/users/users.c +147 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +175 -31
- data/ext/libcouchbase/include/libcouchbase/cntl.h +82 -1
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +45 -3
- data/ext/libcouchbase/include/libcouchbase/error.h +19 -1
- data/ext/libcouchbase/include/libcouchbase/iops.h +3 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +31 -1
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +4 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +36 -2
- data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
- data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +24 -1146
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
- data/ext/libcouchbase/src/README.md +0 -2
- data/ext/libcouchbase/src/auth-priv.h +23 -4
- data/ext/libcouchbase/src/auth.cc +51 -43
- data/ext/libcouchbase/src/bootstrap.cc +244 -0
- data/ext/libcouchbase/src/bootstrap.h +58 -38
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +120 -158
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +526 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
- data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +410 -386
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +393 -0
- data/ext/libcouchbase/src/cbft.cc +22 -27
- data/ext/libcouchbase/src/cntl.cc +56 -22
- data/ext/libcouchbase/src/connspec.cc +47 -6
- data/ext/libcouchbase/src/connspec.h +27 -0
- data/ext/libcouchbase/src/dns-srv.cc +147 -0
- data/ext/libcouchbase/src/dump.cc +3 -3
- data/ext/libcouchbase/src/errmap.cc +173 -0
- data/ext/libcouchbase/src/errmap.h +198 -0
- data/ext/libcouchbase/src/getconfig.cc +7 -33
- data/ext/libcouchbase/src/handler.cc +118 -7
- data/ext/libcouchbase/src/hostlist.cc +0 -36
- data/ext/libcouchbase/src/hostlist.h +44 -62
- data/ext/libcouchbase/src/http/http-priv.h +125 -112
- data/ext/libcouchbase/src/http/http.cc +27 -35
- data/ext/libcouchbase/src/http/http.h +1 -34
- data/ext/libcouchbase/src/http/http_io.cc +28 -36
- data/ext/libcouchbase/src/instance.cc +131 -34
- data/ext/libcouchbase/src/internal.h +58 -26
- data/ext/libcouchbase/src/jsparse/parser.cc +136 -210
- data/ext/libcouchbase/src/jsparse/parser.h +84 -98
- data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
- data/ext/libcouchbase/src/lcbio/connect.cc +569 -0
- data/ext/libcouchbase/src/lcbio/connect.h +16 -7
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +101 -16
- data/ext/libcouchbase/src/lcbio/{ioutils.c → ioutils.cc} +30 -51
- data/ext/libcouchbase/src/lcbio/ioutils.h +29 -90
- data/ext/libcouchbase/src/lcbio/manager.cc +543 -0
- data/ext/libcouchbase/src/lcbio/manager.h +133 -96
- data/ext/libcouchbase/src/lcbio/protoctx.c +2 -2
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
- data/ext/libcouchbase/src/mc/mcreq.c +11 -2
- data/ext/libcouchbase/src/mc/mcreq.h +9 -2
- data/ext/libcouchbase/src/mcserver/mcserver.cc +175 -43
- data/ext/libcouchbase/src/mcserver/mcserver.h +9 -13
- data/ext/libcouchbase/src/mcserver/negotiate.cc +181 -62
- data/ext/libcouchbase/src/mcserver/negotiate.h +1 -3
- data/ext/libcouchbase/src/mctx-helper.h +51 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
- data/ext/libcouchbase/src/n1ql/n1ql.cc +74 -42
- data/ext/libcouchbase/src/netbuf/netbuf.c +4 -4
- data/ext/libcouchbase/src/newconfig.cc +6 -6
- data/ext/libcouchbase/src/nodeinfo.cc +2 -2
- data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
- data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
- data/ext/libcouchbase/src/operations/durability.cc +6 -26
- data/ext/libcouchbase/src/operations/durability_internal.h +6 -3
- data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
- data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +68 -93
- data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
- data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
- data/ext/libcouchbase/src/operations/stats.cc +3 -8
- data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
- data/ext/libcouchbase/src/operations/subdoc.cc +129 -42
- data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
- data/ext/libcouchbase/src/packetutils.h +30 -2
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/rdb/rope.c +1 -1
- data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +2 -3
- data/ext/libcouchbase/src/retryq.cc +52 -14
- data/ext/libcouchbase/src/retryq.h +3 -3
- data/ext/libcouchbase/src/settings.c +5 -0
- data/ext/libcouchbase/src/settings.h +11 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
- data/ext/libcouchbase/src/ssl/ssl_common.c +2 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +1 -1
- data/ext/libcouchbase/src/trace.h +4 -4
- data/ext/libcouchbase/src/vbucket/vbucket.c +6 -10
- data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
- data/ext/libcouchbase/src/views/docreq.h +24 -30
- data/ext/libcouchbase/src/views/viewreq.cc +318 -0
- data/ext/libcouchbase/src/views/viewreq.h +43 -13
- data/ext/libcouchbase/tests/basic/t_connstr.cc +88 -50
- data/ext/libcouchbase/tests/basic/t_creds.cc +47 -5
- data/ext/libcouchbase/tests/basic/t_host.cc +67 -75
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -82
- data/ext/libcouchbase/tests/basic/t_misc.cc +1 -1
- data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +0 -1
- data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
- data/ext/libcouchbase/tests/ioserver/connection.cc +1 -1
- data/ext/libcouchbase/tests/ioserver/ioserver.cc +19 -6
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +28 -2
- data/ext/libcouchbase/tests/iotests/mock-environment.h +51 -1
- data/ext/libcouchbase/tests/iotests/t_behavior.cc +1 -7
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +97 -115
- data/ext/libcouchbase/tests/iotests/t_durability.cc +0 -1
- data/ext/libcouchbase/tests/iotests/t_eerrs.cc +119 -0
- data/ext/libcouchbase/tests/iotests/t_errmap.cc +178 -0
- data/ext/libcouchbase/tests/iotests/t_misc.cc +3 -3
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +1 -1
- data/ext/libcouchbase/tests/iotests/t_obseqno.cc +0 -1
- data/ext/libcouchbase/tests/iotests/t_subdoc.cc +18 -11
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tests/socktests/socktest.cc +7 -10
- data/ext/libcouchbase/tests/socktests/socktest.h +2 -3
- data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
- data/ext/libcouchbase/tests/socktests/t_manager.cc +5 -6
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
- data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
- data/ext/libcouchbase/tests/vbucket/t_config.cc +35 -5
- data/ext/libcouchbase/tools/CMakeLists.txt +2 -2
- data/ext/libcouchbase/tools/cbc-handlers.h +128 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +64 -10
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +2 -2
- data/ext/libcouchbase/tools/cbc.cc +143 -10
- data/ext/libcouchbase/tools/docgen/loc.h +1 -1
- data/lib/libcouchbase/connection.rb +4 -3
- data/lib/libcouchbase/version.rb +1 -1
- metadata +37 -28
- data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
- data/ext/libcouchbase/src/bootstrap.c +0 -269
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
- data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
- data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
- data/ext/libcouchbase/src/lcbio/connect.c +0 -557
- data/ext/libcouchbase/src/lcbio/manager.c +0 -584
- data/ext/libcouchbase/src/packetutils.c +0 -37
- data/ext/libcouchbase/src/simplestring.c +0 -211
- data/ext/libcouchbase/src/simplestring.h +0 -228
- data/ext/libcouchbase/src/ssobuf.h +0 -82
- data/ext/libcouchbase/src/views/viewreq.c +0 -358
- 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
|
-
|
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
|
-
|
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
|
-
|
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(
|
25
|
-
|
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(
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
54
|
+
mon->prepare();
|
50
55
|
|
51
|
-
EXPECT_EQ(NULL,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
63
|
+
Provider *provider = mon->get_provider(CLCONFIG_HTTP);
|
59
64
|
ASSERT_NE(0, provider->enabled);
|
60
65
|
|
61
|
-
|
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
|
-
|
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
|
-
|
82
|
-
std::set<
|
79
|
+
Method last_source;
|
80
|
+
std::set<EventType> expected_events;
|
83
81
|
|
84
82
|
void reset() {
|
85
83
|
call_count = 0;
|
86
|
-
last_source =
|
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
|
-
|
98
|
-
{
|
99
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
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(
|
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
|
-
|
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
|
-
|
159
|
-
|
141
|
+
Provider *cccp = mon->get_provider(CLCONFIG_CCCP);
|
142
|
+
Provider *http = mon->get_provider(CLCONFIG_HTTP);
|
160
143
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
144
|
+
lcb::Hostlist hl;
|
145
|
+
hl.add(cropts.v.v2.mchosts, 11210);
|
146
|
+
cccp->enable(instance);
|
147
|
+
cccp->configure_nodes(hl);
|
165
148
|
|
166
|
-
|
167
|
-
|
168
|
-
hostlist_destroy(hl);
|
149
|
+
http->enable();
|
150
|
+
http->configure_nodes(*instance->ht_nodes);
|
169
151
|
|
170
|
-
|
171
|
-
|
152
|
+
mon->prepare();
|
153
|
+
mon->start();
|
172
154
|
lsn.expected_events.insert(CLCONFIG_EVENT_GOT_NEW_CONFIG);
|
173
|
-
|
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(
|
159
|
+
ASSERT_EQ(CLCONFIG_CCCP, lsn.last_source);
|
178
160
|
|
179
|
-
|
161
|
+
mon->start();
|
180
162
|
lsn.reset();
|
181
163
|
lsn.expected_events.insert(CLCONFIG_EVENT_GOT_ANY_CONFIG);
|
182
|
-
|
164
|
+
runConfmonTest(lsn.io, mon);
|
183
165
|
ASSERT_EQ(1, lsn.call_count);
|
184
|
-
ASSERT_EQ(
|
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
|
-
|
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
|
-
|
193
|
-
ASSERT_EQ(
|
174
|
+
runConfmonTest(lsn.io, mon);
|
175
|
+
ASSERT_EQ(CLCONFIG_HTTP, lsn.last_source);
|
194
176
|
ASSERT_EQ(1, lsn.call_count);
|
195
|
-
|
177
|
+
delete mon;
|
196
178
|
}
|
197
179
|
|
198
|
-
TEST_F(
|
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
|
-
|
208
|
-
hrtime_t last = bs->
|
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->
|
212
|
-
|
193
|
+
bs->reset_last_refresh();
|
194
|
+
instance->confmon->stop();
|
213
195
|
|
214
196
|
// Refreshing now should work
|
215
|
-
|
216
|
-
|
197
|
+
instance->bootstrap(lcb::BS_REFRESH_THROTTLE);
|
198
|
+
ASSERT_TRUE(instance->confmon->is_refreshing());
|
217
199
|
|
218
|
-
cur = bs->
|
200
|
+
cur = bs->get_last_refresh();
|
219
201
|
ASSERT_GT(cur, 0);
|
220
|
-
ASSERT_EQ(0, bs->
|
202
|
+
ASSERT_EQ(0, bs->get_errcounter());
|
221
203
|
last = cur;
|
222
204
|
|
223
205
|
// Stop it, so the state is reset
|
224
|
-
|
225
|
-
|
206
|
+
instance->confmon->stop();
|
207
|
+
ASSERT_FALSE(instance->confmon->is_refreshing());
|
226
208
|
|
227
|
-
|
228
|
-
ASSERT_EQ(last, bs->
|
229
|
-
ASSERT_EQ(1, bs->
|
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
|
-
|
233
|
-
ASSERT_EQ(1, bs->
|
214
|
+
instance->bootstrap(lcb::BS_REFRESH_THROTTLE);
|
215
|
+
ASSERT_EQ(1, bs->get_errcounter());
|
234
216
|
|
235
217
|
// No refresh yet
|
236
|
-
|
218
|
+
ASSERT_FALSE(instance->confmon->is_refreshing());
|
237
219
|
|
238
|
-
|
239
|
-
|
240
|
-
|
220
|
+
instance->bootstrap(lcb::BS_REFRESH_ALWAYS);
|
221
|
+
ASSERT_TRUE(instance->confmon->is_refreshing());
|
222
|
+
instance->confmon->stop();
|
241
223
|
}
|