couchbase 3.2.2 → 3.2.5
Sign up to get free protection for your applications and to get access to all the features.
- package/binding.gyp +5 -0
- package/deps/lcb/CMakeLists.txt +1 -1
- package/deps/lcb/CONTRIBUTING.md +1 -1
- package/deps/lcb/README.markdown +2 -2
- package/deps/lcb/RELEASE_NOTES.markdown +84 -17
- package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
- package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
- package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -6
- package/deps/lcb/doc/Doxyfile +1 -1
- package/deps/lcb/example/minimal/query.c +9 -7
- package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
- package/deps/lcb/gyp_config/linux/arm64/config.h +243 -0
- package/deps/lcb/include/libcouchbase/couchbase.h +55 -1
- package/deps/lcb/include/libcouchbase/error.h +6 -1
- package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
- package/deps/lcb/include/libcouchbase/tracing.h +2 -2
- package/deps/lcb/include/memcached/protocol_binary.h +21 -0
- package/deps/lcb/libcouchbase.gyp +353 -349
- package/deps/lcb/packaging/deb/control +1 -1
- package/deps/lcb/src/analytics/analytics_handle.cc +7 -5
- package/deps/lcb/src/analytics/analytics_handle.hh +28 -0
- package/deps/lcb/src/capi/cmd_counter.hh +18 -0
- package/deps/lcb/src/capi/cmd_exists.hh +18 -0
- package/deps/lcb/src/capi/cmd_get.hh +17 -0
- package/deps/lcb/src/capi/cmd_get_replica.hh +20 -1
- package/deps/lcb/src/capi/cmd_query.cc +13 -0
- package/deps/lcb/src/capi/cmd_query.hh +22 -14
- package/deps/lcb/src/capi/cmd_remove.hh +18 -0
- package/deps/lcb/src/capi/cmd_search.hh +6 -0
- package/deps/lcb/src/capi/cmd_store.hh +28 -21
- package/deps/lcb/src/capi/cmd_subdoc.hh +30 -0
- package/deps/lcb/src/capi/cmd_touch.hh +18 -0
- package/deps/lcb/src/capi/cmd_unlock.hh +18 -0
- package/deps/lcb/src/capi/cmd_view.hh +6 -0
- package/deps/lcb/src/capi/collection_qualifier.hh +6 -8
- package/deps/lcb/src/cntl.cc +42 -8
- package/deps/lcb/src/dns-srv.cc +5 -3
- package/deps/lcb/src/errmap.cc +5 -9
- package/deps/lcb/src/errmap.h +7 -3
- package/deps/lcb/src/handler.cc +24 -18
- package/deps/lcb/src/internal.h +2 -1
- package/deps/lcb/src/lcbio/ctx.cc +4 -2
- package/deps/lcb/src/mcserver/mcserver.cc +8 -5
- package/deps/lcb/src/mcserver/negotiate.cc +42 -17
- package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
- package/deps/lcb/src/n1ql/n1ql.cc +5 -1
- package/deps/lcb/src/n1ql/query_handle.cc +80 -44
- package/deps/lcb/src/n1ql/query_handle.hh +41 -3
- package/deps/lcb/src/operations/counter.cc +13 -1
- package/deps/lcb/src/operations/exists.cc +14 -2
- package/deps/lcb/src/operations/get.cc +14 -2
- package/deps/lcb/src/operations/get_replica.cc +18 -6
- package/deps/lcb/src/operations/observe.cc +1 -1
- package/deps/lcb/src/operations/remove.cc +13 -1
- package/deps/lcb/src/operations/store.cc +13 -1
- package/deps/lcb/src/operations/subdoc.cc +13 -2
- package/deps/lcb/src/operations/touch.cc +14 -2
- package/deps/lcb/src/operations/unlock.cc +14 -2
- package/deps/lcb/src/search/search_handle.cc +26 -8
- package/deps/lcb/src/search/search_handle.hh +29 -0
- package/deps/lcb/src/ssl/ssl_common.c +7 -8
- package/deps/lcb/src/tracing/span.cc +43 -10
- package/deps/lcb/src/tracing/tracing-internal.h +105 -93
- package/deps/lcb/src/utilities.cc +21 -0
- package/deps/lcb/src/utilities.h +3 -0
- package/deps/lcb/src/views/view_handle.cc +13 -5
- package/deps/lcb/src/views/view_handle.hh +29 -0
- package/deps/lcb/tests/CMakeLists.txt +21 -0
- package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
- package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
- package/deps/lcb/tests/iotests/mock-environment.cc +25 -1
- package/deps/lcb/tests/iotests/mock-environment.h +49 -1
- package/deps/lcb/tests/iotests/mock-unit-test.cc +96 -5
- package/deps/lcb/tests/iotests/mock-unit-test.h +32 -0
- package/deps/lcb/tests/iotests/serverparams.h +7 -2
- package/deps/lcb/tests/iotests/t_collections.cc +1 -1
- package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
- package/deps/lcb/tests/iotests/t_get.cc +14 -4
- package/deps/lcb/tests/iotests/t_n1ql.cc +17 -1
- package/deps/lcb/tests/iotests/t_ratelimit.cc +729 -0
- package/deps/lcb/tests/iotests/t_views.cc +1 -0
- package/deps/lcb/tests/iotests/testutil.cc +342 -0
- package/deps/lcb/tests/iotests/testutil.h +164 -0
- package/deps/lcb/tests/mocksupport/procutil.c +32 -28
- package/deps/lcb/tests/mocksupport/server.c +0 -1
- package/deps/lcb/tools/cbc.cc +7 -0
- package/dist/analyticsexecutor.js +2 -2
- package/dist/analyticsindexmanager.js +512 -524
- package/dist/binarycollection.d.ts +17 -0
- package/dist/binding.d.ts +2 -0
- package/dist/binding.js +1 -1
- package/dist/bindingutilities.js +9 -1
- package/dist/bucketmanager.d.ts +32 -23
- package/dist/bucketmanager.js +197 -189
- package/dist/cluster.js +37 -36
- package/dist/collection.js +17 -23
- package/dist/collectionmanager.js +181 -200
- package/dist/connection.js +6 -3
- package/dist/connspec.js +5 -1
- package/dist/couchbase.js +7 -14
- package/dist/datastructures.js +239 -310
- package/dist/diagnosticsexecutor.js +70 -85
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +26 -2
- package/dist/eventingfunctionmanager.js +267 -294
- package/dist/httpexecutor.js +31 -38
- package/dist/logging.js +1 -1
- package/dist/queryexecutor.js +3 -3
- package/dist/queryindexmanager.js +236 -263
- package/dist/scope.js +8 -2
- package/dist/searchexecutor.js +3 -0
- package/dist/searchindexmanager.js +240 -271
- package/dist/searchquery.d.ts +17 -0
- package/dist/searchquery.js +22 -1
- package/dist/searchtypes.d.ts +7 -2
- package/dist/searchtypes.js +2 -2
- package/dist/usermanager.js +250 -263
- package/dist/utilities.d.ts +3 -2
- package/dist/utilities.js +16 -4
- package/dist/viewexecutor.js +1 -1
- package/dist/viewindexmanager.js +131 -150
- package/package.json +1 -1
- package/src/connection.cpp +2 -0
- package/src/constants.cpp +2 -0
- package/src/instance.cpp +8 -1
- package/src/instance.h +1 -0
- package/src/uv-plugin-all.cpp +1 -0
- package/dist/cas.d.ts +0 -0
- package/dist/cas.js +0 -1
@@ -118,6 +118,32 @@ struct lcb_VIEW_HANDLE_ : lcb::jsparse::Parser::Actions {
|
|
118
118
|
return http_request_;
|
119
119
|
}
|
120
120
|
|
121
|
+
static lcbtrace_THRESHOLDOPTS service()
|
122
|
+
{
|
123
|
+
return LCBTRACE_THRESHOLD_VIEW;
|
124
|
+
}
|
125
|
+
|
126
|
+
static const std::string &operation_name()
|
127
|
+
{
|
128
|
+
static std::string name = LCBTRACE_OP_VIEW;
|
129
|
+
return name;
|
130
|
+
}
|
131
|
+
|
132
|
+
lcbtrace_SPAN *parent_span() const
|
133
|
+
{
|
134
|
+
return parent_span_;
|
135
|
+
}
|
136
|
+
|
137
|
+
const std::string &client_context_id() const
|
138
|
+
{
|
139
|
+
return client_context_id_;
|
140
|
+
}
|
141
|
+
|
142
|
+
int retries() const
|
143
|
+
{
|
144
|
+
return retries_;
|
145
|
+
}
|
146
|
+
|
121
147
|
private:
|
122
148
|
/** Current HTTP response to provide in callbacks */
|
123
149
|
const lcb_RESPHTTP *http_response_{nullptr};
|
@@ -134,12 +160,15 @@ struct lcb_VIEW_HANDLE_ : lcb::jsparse::Parser::Actions {
|
|
134
160
|
std::string query_params_{};
|
135
161
|
std::string first_error_code_{};
|
136
162
|
std::string first_error_message_{};
|
163
|
+
std::string client_context_id_{};
|
137
164
|
|
138
165
|
unsigned refcount_{1};
|
139
166
|
bool include_docs_{false};
|
140
167
|
bool do_not_parse_rows_{false};
|
141
168
|
bool spatial_{false};
|
169
|
+
int retries_{0};
|
142
170
|
|
143
171
|
lcb_STATUS last_error_{LCB_SUCCESS};
|
172
|
+
lcbtrace_SPAN *parent_span_{nullptr};
|
144
173
|
lcbtrace_SPAN *span_{nullptr};
|
145
174
|
};
|
@@ -152,8 +152,29 @@ MACRO(DEFINE_MOCKTEST plugin test)
|
|
152
152
|
--tests ${test}
|
153
153
|
--verbose
|
154
154
|
--
|
155
|
+
--gtest_filter="-ContaminatingUnitTest.*"
|
156
|
+
--gtest_throw_on_failure=1
|
155
157
|
--gtest_print_time=1
|
156
158
|
--gtest_output=xml:"${PROJECT_BINARY_DIR}/REPORT_${plugin}_${test}.xml")
|
159
|
+
SET_TESTS_PROPERTIES(check-${plugin}-${test} PROPERTIES LABELS "normal" )
|
160
|
+
|
161
|
+
ADD_TEST(
|
162
|
+
NAME
|
163
|
+
check-contaminating-${plugin}-${test}
|
164
|
+
COMMAND
|
165
|
+
$<TARGET_FILE:check-all>
|
166
|
+
--srcdir "${PROJECT_SOURCE_DIR}"
|
167
|
+
--testdir "$<TARGET_FILE_DIR:check-all>"
|
168
|
+
--libdir "$<TARGET_FILE_DIR:couchbase>"
|
169
|
+
--plugins ${plugin}
|
170
|
+
--tests ${test}
|
171
|
+
--verbose
|
172
|
+
--
|
173
|
+
--gtest_filter="ContaminatingUnitTest.*"
|
174
|
+
--gtest_throw_on_failure=1
|
175
|
+
--gtest_print_time=1
|
176
|
+
--gtest_output=xml:"${PROJECT_BINARY_DIR}/REPORT_${plugin}_${test}.xml")
|
177
|
+
SET_TESTS_PROPERTIES(check-contaminating-${plugin}-${test} PROPERTIES LABELS "contaminating" )
|
157
178
|
ENDMACRO()
|
158
179
|
|
159
180
|
# Since we need a plugin name, we'll use 'select'. However none of these
|
@@ -18,6 +18,9 @@
|
|
18
18
|
#include "config.h"
|
19
19
|
#include <gtest/gtest.h>
|
20
20
|
#include <libcouchbase/couchbase.h>
|
21
|
+
#include <iotests/testutil.h>
|
22
|
+
|
23
|
+
#include "internal.h"
|
21
24
|
|
22
25
|
class CtlTest : public ::testing::Test
|
23
26
|
{
|
@@ -61,9 +64,9 @@ TEST_F(CtlTest, testStringCtls)
|
|
61
64
|
{
|
62
65
|
lcb_INSTANCE *instance;
|
63
66
|
lcb_STATUS err;
|
64
|
-
err = lcb_create(&instance,
|
67
|
+
err = lcb_create(&instance, nullptr);
|
65
68
|
ASSERT_EQ(LCB_SUCCESS, err);
|
66
|
-
ASSERT_FALSE(instance ==
|
69
|
+
ASSERT_FALSE(instance == nullptr);
|
67
70
|
|
68
71
|
// These are all U32
|
69
72
|
PairMap ctlMap[] = {{"operation_timeout", LCB_CNTL_OP_TIMEOUT},
|
@@ -74,7 +77,7 @@ TEST_F(CtlTest, testStringCtls)
|
|
74
77
|
{"error_thresh_delay", LCB_CNTL_CONFDELAY_THRESH},
|
75
78
|
{"config_total_timeout", LCB_CNTL_CONFIGURATION_TIMEOUT},
|
76
79
|
{"config_node_timeout", LCB_CNTL_CONFIG_NODE_TIMEOUT},
|
77
|
-
{
|
80
|
+
{nullptr, 0}};
|
78
81
|
|
79
82
|
for (PairMap *cur = ctlMap; cur->key; cur++) {
|
80
83
|
err = lcb_cntl_string(instance, cur->key, "50");
|
@@ -111,3 +114,21 @@ TEST_F(CtlTest, testStringCtls)
|
|
111
114
|
|
112
115
|
lcb_destroy(instance);
|
113
116
|
}
|
117
|
+
|
118
|
+
TEST_F(CtlTest, testTimeDurationParsing)
|
119
|
+
{
|
120
|
+
lcb_INSTANCE *instance;
|
121
|
+
ASSERT_EQ(LCB_SUCCESS, lcb_create(&instance, nullptr));
|
122
|
+
ASSERT_FALSE(instance == nullptr);
|
123
|
+
|
124
|
+
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cntl_string(instance, "analytics_timeout", "123.456"));
|
125
|
+
ASSERT_EQ(123456000, instance->settings->analytics_timeout);
|
126
|
+
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cntl_string(instance, "analytics_timeout", "42"));
|
127
|
+
ASSERT_EQ(42000000, instance->settings->analytics_timeout);
|
128
|
+
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cntl_string(instance, "analytics_timeout", "42us"));
|
129
|
+
ASSERT_EQ(42, instance->settings->analytics_timeout);
|
130
|
+
ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cntl_string(instance, "analytics_timeout", "5s42us"));
|
131
|
+
ASSERT_EQ(5000042, instance->settings->analytics_timeout);
|
132
|
+
|
133
|
+
lcb_destroy(instance);
|
134
|
+
}
|
@@ -105,3 +105,11 @@ TEST_F(JsonParseTest, testN1QL)
|
|
105
105
|
ASSERT_TRUE(validateJsonRows(JSON_n1ql_empty, sizeof(JSON_n1ql_empty), Parser::MODE_N1QL));
|
106
106
|
ASSERT_TRUE(validateBadParse(JSON_n1ql_bad, sizeof(JSON_n1ql_bad), Parser::MODE_N1QL));
|
107
107
|
}
|
108
|
+
|
109
|
+
TEST_F(JsonParseTest, testInvalidJSON)
|
110
|
+
{
|
111
|
+
std::string input = "503 Service Unavailable";
|
112
|
+
Json::Value meta;
|
113
|
+
ASSERT_TRUE(Json::Reader().parse(input.c_str(), input.c_str() + input.size(), meta));
|
114
|
+
ASSERT_FALSE(Json::Reader(Json::Features::strictMode()).parse(input.c_str(), input.c_str() + input.size(), meta));
|
115
|
+
}
|
@@ -21,6 +21,7 @@
|
|
21
21
|
#include "mock-environment.h"
|
22
22
|
#include <sstream>
|
23
23
|
#include "internal.h" /* settings from lcb_INSTANCE *for logging */
|
24
|
+
#include "testutil.h"
|
24
25
|
|
25
26
|
#define LOGARGS(instance, lvl) instance->settings, "tests-ENV", LCB_LOG_##lvl, __FILE__, __LINE__
|
26
27
|
|
@@ -288,6 +289,7 @@ void MockEnvironment::createConnection(HandleWrap &handle, lcb_INSTANCE **instan
|
|
288
289
|
}
|
289
290
|
|
290
291
|
lcb_createopts_io(&options, io);
|
292
|
+
|
291
293
|
lcb_STATUS err = lcb_create(instance, &options);
|
292
294
|
ASSERT_EQ(LCB_SUCCESS, err);
|
293
295
|
postCreate(*instance);
|
@@ -302,6 +304,15 @@ void MockEnvironment::createConnection(HandleWrap &handle, lcb_INSTANCE **instan
|
|
302
304
|
{
|
303
305
|
lcb_CREATEOPTS *options = nullptr;
|
304
306
|
makeConnectParams(options, nullptr);
|
307
|
+
|
308
|
+
if (test_tracer.enabled()) {
|
309
|
+
lcb_createopts_tracer(options, test_tracer.lcb_tracer());
|
310
|
+
}
|
311
|
+
|
312
|
+
if (test_meter.enabled()) {
|
313
|
+
lcb_createopts_meter(options, test_meter.lcb_meter());
|
314
|
+
}
|
315
|
+
|
305
316
|
createConnection(handle, instance, options);
|
306
317
|
lcb_createopts_destroy(options);
|
307
318
|
}
|
@@ -311,6 +322,7 @@ void MockEnvironment::createConnection(HandleWrap &handle, lcb_INSTANCE **instan
|
|
311
322
|
{
|
312
323
|
lcb_CREATEOPTS *options = nullptr;
|
313
324
|
makeConnectParams(options, nullptr);
|
325
|
+
|
314
326
|
lcb_createopts_credentials(options, username.c_str(), username.size(), password.c_str(), password.size());
|
315
327
|
createConnection(handle, instance, options);
|
316
328
|
lcb_createopts_destroy(options);
|
@@ -411,7 +423,16 @@ static void statsCallback(lcb_INSTANCE *instance, lcb_CALLBACK_TYPE, const lcb_R
|
|
411
423
|
}
|
412
424
|
break;
|
413
425
|
case 7:
|
414
|
-
|
426
|
+
switch (minor) {
|
427
|
+
case 0:
|
428
|
+
version = MockEnvironment::VERSION_70;
|
429
|
+
break;
|
430
|
+
case 1:
|
431
|
+
version = MockEnvironment::VERSION_71;
|
432
|
+
break;
|
433
|
+
default:
|
434
|
+
break;
|
435
|
+
}
|
415
436
|
break;
|
416
437
|
default:
|
417
438
|
break;
|
@@ -556,6 +577,9 @@ void MockEnvironment::SetUp()
|
|
556
577
|
featureRegistry.insert("replica_read");
|
557
578
|
featureRegistry.insert("lock");
|
558
579
|
|
580
|
+
test_tracer = TestTracer();
|
581
|
+
test_meter = TestMeter();
|
582
|
+
|
559
583
|
clearAndReset();
|
560
584
|
}
|
561
585
|
|
@@ -20,6 +20,7 @@
|
|
20
20
|
#include "config.h"
|
21
21
|
#include <gtest/gtest.h>
|
22
22
|
#include <libcouchbase/couchbase.h>
|
23
|
+
#include "testutil.h"
|
23
24
|
|
24
25
|
#include <utility>
|
25
26
|
#include "serverparams.h"
|
@@ -245,7 +246,8 @@ class MockEnvironment : public ::testing::Environment
|
|
245
246
|
VERSION_60 = 10,
|
246
247
|
VERSION_65 = 11,
|
247
248
|
VERSION_66 = 12,
|
248
|
-
VERSION_70 = 13
|
249
|
+
VERSION_70 = 13,
|
250
|
+
VERSION_71 = 14,
|
249
251
|
};
|
250
252
|
|
251
253
|
void SetUp() override;
|
@@ -451,6 +453,16 @@ class MockEnvironment : public ::testing::Environment
|
|
451
453
|
std::cerr << std::endl;
|
452
454
|
}
|
453
455
|
|
456
|
+
TestTracer &getTracer()
|
457
|
+
{
|
458
|
+
return test_tracer;
|
459
|
+
}
|
460
|
+
|
461
|
+
TestMeter &getMeter()
|
462
|
+
{
|
463
|
+
return test_meter;
|
464
|
+
}
|
465
|
+
|
454
466
|
explicit MockEnvironment(const char **argv, const std::string &name = "default");
|
455
467
|
~MockEnvironment() override;
|
456
468
|
void postCreate(lcb_INSTANCE *instance) const;
|
@@ -478,11 +490,47 @@ class MockEnvironment : public ::testing::Environment
|
|
478
490
|
std::string userName;
|
479
491
|
const char **argv_{nullptr};
|
480
492
|
void clearAndReset();
|
493
|
+
TestTracer test_tracer;
|
494
|
+
TestMeter test_meter;
|
481
495
|
|
482
496
|
private:
|
483
497
|
lcb_INSTANCE *innerClient{nullptr};
|
484
498
|
};
|
485
499
|
|
500
|
+
class tracing_guard
|
501
|
+
{
|
502
|
+
public:
|
503
|
+
tracing_guard()
|
504
|
+
{
|
505
|
+
was_enabled_ = MockEnvironment::getInstance()->getTracer().set_enabled(true);
|
506
|
+
}
|
507
|
+
|
508
|
+
~tracing_guard()
|
509
|
+
{
|
510
|
+
MockEnvironment::getInstance()->getTracer().set_enabled(was_enabled_);
|
511
|
+
}
|
512
|
+
|
513
|
+
private:
|
514
|
+
bool was_enabled_{false};
|
515
|
+
};
|
516
|
+
|
517
|
+
class metrics_guard
|
518
|
+
{
|
519
|
+
public:
|
520
|
+
metrics_guard()
|
521
|
+
{
|
522
|
+
was_enabled_ = MockEnvironment::getInstance()->getMeter().set_enabled(true);
|
523
|
+
}
|
524
|
+
|
525
|
+
~metrics_guard()
|
526
|
+
{
|
527
|
+
MockEnvironment::getInstance()->getMeter().set_enabled(was_enabled_);
|
528
|
+
}
|
529
|
+
|
530
|
+
private:
|
531
|
+
bool was_enabled_{false};
|
532
|
+
};
|
533
|
+
|
486
534
|
#define LCB_TEST_REQUIRE_CLUSTER_VERSION(v) \
|
487
535
|
if (!MockEnvironment::getInstance()->isRealCluster()) { \
|
488
536
|
MockEnvironment::printSkipMessage(__FILE__, __LINE__, "need real cluster"); \
|
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
#include "internal.h" /* vbucket_* things from lcb_INSTANCE **/
|
22
22
|
#include <lcbio/iotable.h>
|
23
|
-
#include "
|
23
|
+
#include "libcouchbase/couchbase.h"
|
24
24
|
|
25
25
|
#define LOGARGS(instance, lvl) instance->settings, "tests-MUT", LCB_LOG_##lvl, __FILE__, __LINE__
|
26
26
|
|
@@ -29,7 +29,7 @@
|
|
29
29
|
*/
|
30
30
|
void MockUnitTest::SetUp()
|
31
31
|
{
|
32
|
-
srand(time(
|
32
|
+
srand(time(nullptr));
|
33
33
|
MockEnvironment::Reset();
|
34
34
|
}
|
35
35
|
|
@@ -42,8 +42,8 @@ void checkConnectCommon(lcb_INSTANCE *instance)
|
|
42
42
|
|
43
43
|
void MockUnitTest::createClusterConnection(HandleWrap &handle, lcb_INSTANCE **instance)
|
44
44
|
{
|
45
|
-
lcb_CREATEOPTS *options =
|
46
|
-
MockEnvironment::getInstance()->makeConnectParams(options,
|
45
|
+
lcb_CREATEOPTS *options = nullptr;
|
46
|
+
MockEnvironment::getInstance()->makeConnectParams(options, nullptr, LCB_TYPE_CLUSTER);
|
47
47
|
MockEnvironment::getInstance()->createConnection(handle, instance, options);
|
48
48
|
checkConnectCommon(handle.getLcb());
|
49
49
|
lcb_createopts_destroy(options);
|
@@ -70,7 +70,7 @@ void MockUnitTest::createConnection(lcb_INSTANCE **instance)
|
|
70
70
|
|
71
71
|
void MockUnitTest::createConnection(HandleWrap &handle)
|
72
72
|
{
|
73
|
-
lcb_INSTANCE *instance =
|
73
|
+
lcb_INSTANCE *instance = nullptr;
|
74
74
|
createConnection(handle, &instance);
|
75
75
|
}
|
76
76
|
|
@@ -81,3 +81,94 @@ lcb_STATUS MockUnitTest::tryCreateConnection(HandleWrap &hw, lcb_INSTANCE **inst
|
|
81
81
|
lcb_wait(*instance, LCB_WAIT_DEFAULT);
|
82
82
|
return lcb_get_bootstrap_status(*instance);
|
83
83
|
}
|
84
|
+
|
85
|
+
void MockUnitTest::assert_kv_span(const std::shared_ptr<TestSpan> &span, const std::string &expectedName,
|
86
|
+
const KVSpanAssertions &assertions)
|
87
|
+
{
|
88
|
+
auto bucket = MockEnvironment::getInstance()->getBucket();
|
89
|
+
ASSERT_EQ(expectedName, span->name);
|
90
|
+
ASSERT_EQ("couchbase", span->str_tags["db.system"]);
|
91
|
+
ASSERT_TRUE(span->int_tags.find("db.couchbase.server_duration") != span->int_tags.end());
|
92
|
+
ASSERT_EQ(bucket, span->str_tags["db.name"]);
|
93
|
+
ASSERT_EQ(assertions.scope, span->str_tags["db.couchbase.scope"]);
|
94
|
+
ASSERT_EQ(assertions.collection, span->str_tags["db.couchbase.collection"]);
|
95
|
+
ASSERT_EQ("kv", span->str_tags["db.couchbase.service"]);
|
96
|
+
ASSERT_EQ(expectedName, span->str_tags["db.operation"]);
|
97
|
+
ASSERT_EQ("IP.TCP", span->str_tags["net.transport"]);
|
98
|
+
ASSERT_TRUE(span->str_tags.count("db.couchbase.operation_id") > 0);
|
99
|
+
ASSERT_TRUE(span->str_tags.count("db.couchbase.local_id") > 0);
|
100
|
+
ASSERT_TRUE(span->str_tags.count("net.host.name") > 0);
|
101
|
+
ASSERT_TRUE(span->str_tags.count("net.host.port") > 0);
|
102
|
+
ASSERT_TRUE(span->str_tags.count("net.peer.name") > 0);
|
103
|
+
ASSERT_TRUE(span->str_tags.count("net.peer.port") > 0);
|
104
|
+
ASSERT_TRUE(span->int_tags.count("db.couchbase.retries") > 0);
|
105
|
+
if (assertions.durability_level == LCB_DURABILITYLEVEL_NONE) {
|
106
|
+
ASSERT_TRUE(span->str_tags.count("db.couchbase.durability") == 0);
|
107
|
+
} else {
|
108
|
+
ASSERT_EQ(dur_level_to_string(assertions.durability_level), span->str_tags["db.couchbase.durability"]);
|
109
|
+
}
|
110
|
+
ASSERT_TRUE(span->finished);
|
111
|
+
}
|
112
|
+
|
113
|
+
void MockUnitTest::assert_http_span(const std::shared_ptr<TestSpan> &span, const std::string &expectedName,
|
114
|
+
const HTTPSpanAssertions &assertions)
|
115
|
+
{
|
116
|
+
ASSERT_EQ(expectedName, span->name);
|
117
|
+
ASSERT_EQ("couchbase", span->str_tags["db.system"]);
|
118
|
+
if (!assertions.bucket.empty()) {
|
119
|
+
ASSERT_EQ(assertions.bucket, span->str_tags["db.name"]);
|
120
|
+
}
|
121
|
+
if (!assertions.scope.empty()) {
|
122
|
+
ASSERT_EQ(assertions.scope, span->str_tags["db.couchbase.scope"]);
|
123
|
+
}
|
124
|
+
if (!assertions.collection.empty()) {
|
125
|
+
ASSERT_EQ(assertions.collection, span->str_tags["db.couchbase.collection"]);
|
126
|
+
}
|
127
|
+
if (!assertions.service.empty()) {
|
128
|
+
ASSERT_EQ(assertions.service, span->str_tags["db.couchbase.service"]);
|
129
|
+
}
|
130
|
+
if (!assertions.op.empty()) {
|
131
|
+
ASSERT_EQ(assertions.op, span->str_tags["db.operation"]);
|
132
|
+
}
|
133
|
+
ASSERT_EQ("IP.TCP", span->str_tags["net.transport"]);
|
134
|
+
if (assertions.operation_id.empty()) {
|
135
|
+
ASSERT_TRUE(span->str_tags.find("db.couchbase.operation_id") == span->str_tags.end());
|
136
|
+
} else if (assertions.operation_id == "any") {
|
137
|
+
ASSERT_TRUE(span->str_tags.find("db.couchbase.operation_id") != span->str_tags.end());
|
138
|
+
} else {
|
139
|
+
ASSERT_EQ(assertions.operation_id, span->str_tags["db.couchbase.operation_id"]);
|
140
|
+
}
|
141
|
+
ASSERT_TRUE(span->str_tags.find("net.host.name") != span->str_tags.end());
|
142
|
+
ASSERT_TRUE(span->str_tags.find("net.host.port") != span->str_tags.end());
|
143
|
+
ASSERT_TRUE(span->str_tags.find("net.peer.name") != span->str_tags.end());
|
144
|
+
ASSERT_TRUE(span->str_tags.find("net.peer.port") != span->str_tags.end());
|
145
|
+
ASSERT_TRUE(span->int_tags.find("db.couchbase.retries") != span->int_tags.end());
|
146
|
+
if (!assertions.statement.empty()) {
|
147
|
+
ASSERT_EQ(assertions.statement, span->str_tags["db.statement"]);
|
148
|
+
}
|
149
|
+
ASSERT_TRUE(span->finished);
|
150
|
+
}
|
151
|
+
|
152
|
+
void MockUnitTest::assert_kv_metrics(const std::string &metric_name, const std::string &op, uint32_t length,
|
153
|
+
bool at_least_len)
|
154
|
+
{
|
155
|
+
std::string key = metric_name + ":kv";
|
156
|
+
if (op != "") {
|
157
|
+
key = key + ":" + op;
|
158
|
+
}
|
159
|
+
assert_metrics(key, length, at_least_len);
|
160
|
+
}
|
161
|
+
|
162
|
+
void MockUnitTest::assert_metrics(const std::string &key, uint32_t length, bool at_least_len)
|
163
|
+
{
|
164
|
+
auto meter = MockEnvironment::getInstance()->getMeter();
|
165
|
+
ASSERT_TRUE(meter.recorders.find(key) != meter.recorders.end());
|
166
|
+
if (at_least_len) {
|
167
|
+
ASSERT_TRUE(meter.recorders[key]->values.size() >= length);
|
168
|
+
} else {
|
169
|
+
ASSERT_TRUE(meter.recorders[key]->values.size() == length);
|
170
|
+
}
|
171
|
+
for (const auto value : meter.recorders[key]->values) {
|
172
|
+
ASSERT_NE(0, value);
|
173
|
+
}
|
174
|
+
}
|
@@ -21,6 +21,7 @@
|
|
21
21
|
#include <gtest/gtest.h>
|
22
22
|
#include <libcouchbase/couchbase.h>
|
23
23
|
#include "mock-environment.h"
|
24
|
+
#include "testutil.h"
|
24
25
|
|
25
26
|
class HandleWrap;
|
26
27
|
|
@@ -44,6 +45,22 @@ class HandleWrap;
|
|
44
45
|
return; \
|
45
46
|
}
|
46
47
|
|
48
|
+
struct KVSpanAssertions {
|
49
|
+
lcb_DURABILITY_LEVEL durability_level{LCB_DURABILITYLEVEL_NONE};
|
50
|
+
std::string scope{"_default"};
|
51
|
+
std::string collection{"_default"};
|
52
|
+
};
|
53
|
+
|
54
|
+
struct HTTPSpanAssertions {
|
55
|
+
std::string statement{};
|
56
|
+
std::string scope{};
|
57
|
+
std::string collection{};
|
58
|
+
std::string bucket{};
|
59
|
+
std::string op{};
|
60
|
+
std::string operation_id{};
|
61
|
+
std::string service{};
|
62
|
+
};
|
63
|
+
|
47
64
|
class MockUnitTest : public ::testing::Test
|
48
65
|
{
|
49
66
|
protected:
|
@@ -56,6 +73,13 @@ class MockUnitTest : public ::testing::Test
|
|
56
73
|
virtual void createClusterConnection(HandleWrap &handle, lcb_INSTANCE **instance);
|
57
74
|
virtual lcb_STATUS tryCreateConnection(HandleWrap &hw, lcb_INSTANCE **instance, lcb_CREATEOPTS *&crparams);
|
58
75
|
|
76
|
+
static void assert_kv_span(const std::shared_ptr<TestSpan> &span, const std::string &expectedName,
|
77
|
+
const KVSpanAssertions &assertions);
|
78
|
+
static void assert_http_span(const std::shared_ptr<TestSpan> &span, const std::string &expectedName,
|
79
|
+
const HTTPSpanAssertions &assertions);
|
80
|
+
void assert_kv_metrics(const std::string &metric_name, const std::string &op, uint32_t length, bool at_least_len);
|
81
|
+
void assert_metrics(const std::string &key, uint32_t length, bool at_least_len);
|
82
|
+
|
59
83
|
// A mock "Transaction"
|
60
84
|
void doMockTxn(MockCommand &cmd)
|
61
85
|
{
|
@@ -66,4 +90,12 @@ class MockUnitTest : public ::testing::Test
|
|
66
90
|
}
|
67
91
|
};
|
68
92
|
|
93
|
+
/*
|
94
|
+
* This test class groups tests that might be problematic when executed together with all other tests.
|
95
|
+
* Every test case in this suite must start with Jira ticket number for future.
|
96
|
+
*/
|
97
|
+
class ContaminatingUnitTest : public MockUnitTest
|
98
|
+
{
|
99
|
+
};
|
100
|
+
|
69
101
|
#endif
|
@@ -37,10 +37,15 @@ class ServerParams
|
|
37
37
|
void makeConnectParams(lcb_CREATEOPTS *&crst, lcb_io_opt_t io, lcb_INSTANCE_TYPE type = LCB_TYPE_BUCKET)
|
38
38
|
{
|
39
39
|
lcb_createopts_create(&crst, type);
|
40
|
-
if (host.find("couchbase
|
40
|
+
if (host.find("couchbase") == 0) {
|
41
41
|
connstr = host;
|
42
42
|
// deactivate dnssrv and compression, use cccp bootstrap
|
43
|
-
|
43
|
+
if (host.find("?") == std::string::npos) {
|
44
|
+
connstr += "?";
|
45
|
+
} else {
|
46
|
+
connstr += "&";
|
47
|
+
}
|
48
|
+
connstr += "dnssrv=off&bootstrap_on=cccp&compression=off";
|
44
49
|
} else {
|
45
50
|
if (mcNodes.empty() || type == LCB_TYPE_CLUSTER) {
|
46
51
|
connstr = "couchbase://" + host + "=http";
|
@@ -572,7 +572,7 @@ TEST_F(CollectionUnitTest, testDroppedScope)
|
|
572
572
|
*
|
573
573
|
* Collection creations are successful
|
574
574
|
*/
|
575
|
-
TEST_F(
|
575
|
+
TEST_F(ContaminatingUnitTest, test_CCBC_1483_MaxCollectionsPerScope)
|
576
576
|
{
|
577
577
|
SKIP_IF_MOCK()
|
578
578
|
SKIP_IF_CLUSTER_VERSION_IS_LOWER_THAN(MockEnvironment::VERSION_70)
|
@@ -24,6 +24,9 @@ struct evstop_listener : Listener {
|
|
24
24
|
|
25
25
|
void clconfig_lsn(EventType event, ConfigInfo *)
|
26
26
|
{
|
27
|
+
if (event == CLCONFIG_EVENT_PROVIDERS_CYCLED) {
|
28
|
+
return IOT_STOP(io);
|
29
|
+
}
|
27
30
|
if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
|
28
31
|
return;
|
29
32
|
}
|
@@ -40,7 +43,6 @@ static void listen_callback1(Listener *lsn, EventType event, ConfigInfo *info) {
|
|
40
43
|
|
41
44
|
TEST_F(ConfmonTest, testBasic)
|
42
45
|
{
|
43
|
-
SKIP_UNLESS_MOCK();
|
44
46
|
HandleWrap hw;
|
45
47
|
lcb_INSTANCE *instance;
|
46
48
|
MockEnvironment::getInstance()->createConnection(hw, &instance);
|
@@ -68,8 +70,8 @@ TEST_F(ConfmonTest, testBasic)
|
|
68
70
|
mon->start();
|
69
71
|
|
70
72
|
IOT_START(instance->iotable);
|
71
|
-
ASSERT_NE(0, listener.called);
|
72
73
|
delete mon;
|
74
|
+
ASSERT_NE(0, listener.called);
|
73
75
|
}
|
74
76
|
|
75
77
|
struct listener2 : Listener {
|
@@ -21,6 +21,7 @@
|
|
21
21
|
#include "iotests.h"
|
22
22
|
#include "logging.h"
|
23
23
|
#include "internal.h"
|
24
|
+
#include "testutil.h"
|
24
25
|
|
25
26
|
#define LOGARGS(instance, lvl) instance->settings, "tests-GET", LCB_LOG_##lvl, __FILE__, __LINE__
|
26
27
|
|
@@ -106,6 +107,9 @@ static void testGetHitGetCallback(lcb_INSTANCE *, lcb_CALLBACK_TYPE, const lcb_R
|
|
106
107
|
*/
|
107
108
|
TEST_F(GetUnitTest, testGetHit)
|
108
109
|
{
|
110
|
+
MockEnvironment *mock = MockEnvironment::getInstance();
|
111
|
+
tracing_guard use_tracing;
|
112
|
+
metrics_guard use_metrics;
|
109
113
|
HandleWrap hw;
|
110
114
|
lcb_INSTANCE *instance;
|
111
115
|
createConnection(hw, &instance);
|
@@ -129,6 +133,16 @@ TEST_F(GetUnitTest, testGetHit)
|
|
129
133
|
|
130
134
|
lcb_wait(instance, LCB_WAIT_DEFAULT);
|
131
135
|
EXPECT_EQ(2, numcallbacks);
|
136
|
+
|
137
|
+
auto spans = mock->getTracer().spans;
|
138
|
+
ASSERT_EQ(4, spans.size());
|
139
|
+
auto span = spans[0];
|
140
|
+
assert_kv_span(span, "upsert", {});
|
141
|
+
span = spans[2];
|
142
|
+
assert_kv_span(span, "get", {});
|
143
|
+
|
144
|
+
assert_kv_metrics(METRICS_OPS_METER_NAME, "get", 2, false);
|
145
|
+
assert_kv_metrics(METRICS_OPS_METER_NAME, "upsert", 2, false);
|
132
146
|
}
|
133
147
|
|
134
148
|
extern "C" {
|
@@ -1097,10 +1111,6 @@ TEST_F(GetUnitTest, testChangePassword)
|
|
1097
1111
|
createConnection(hwHttp, &instanceHttp);
|
1098
1112
|
(void)lcb_install_callback(instanceHttp, LCB_CALLBACK_HTTP, (lcb_RESPCALLBACK)change_password_http_callback);
|
1099
1113
|
|
1100
|
-
// Set short timeout
|
1101
|
-
lcb_uint32_t tmoval = 100000;
|
1102
|
-
lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_OP_TIMEOUT, &tmoval);
|
1103
|
-
|
1104
1114
|
// store keys
|
1105
1115
|
// run one set to connect to only one node
|
1106
1116
|
// the goal is to change the password then try to connect others nodes
|
@@ -165,6 +165,8 @@ class QueryUnitTest : public MockUnitTest
|
|
165
165
|
|
166
166
|
TEST_F(QueryUnitTest, testSimple)
|
167
167
|
{
|
168
|
+
MockEnvironment *mock = MockEnvironment::getInstance();
|
169
|
+
tracing_guard use_tracing;
|
168
170
|
lcb_INSTANCE *instance;
|
169
171
|
HandleWrap hw;
|
170
172
|
if (!createQueryConnection(hw, &instance)) {
|
@@ -172,12 +174,26 @@ TEST_F(QueryUnitTest, testSimple)
|
|
172
174
|
}
|
173
175
|
|
174
176
|
N1QLResult res;
|
175
|
-
|
177
|
+
const char *query = "SELECT mockrow";
|
178
|
+
makeCommand(query);
|
179
|
+
|
180
|
+
const char *context_id = "context_id";
|
181
|
+
lcb_cmdquery_client_context_id(cmd, context_id, strlen(context_id));
|
182
|
+
|
176
183
|
lcb_STATUS rc = lcb_query(instance, &res, cmd);
|
177
184
|
ASSERT_STATUS_EQ(LCB_SUCCESS, rc);
|
178
185
|
lcb_wait(instance, LCB_WAIT_DEFAULT);
|
179
186
|
ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
|
180
187
|
ASSERT_EQ(1, res.rows.size());
|
188
|
+
|
189
|
+
auto spans = mock->getTracer().spans;
|
190
|
+
ASSERT_EQ(1, spans.size());
|
191
|
+
auto span = spans[0];
|
192
|
+
HTTPSpanAssertions assertions;
|
193
|
+
assertions.statement = query;
|
194
|
+
assertions.operation_id = context_id;
|
195
|
+
assertions.service = "query";
|
196
|
+
assert_http_span(span, "query", assertions);
|
181
197
|
}
|
182
198
|
|
183
199
|
TEST_F(QueryUnitTest, testQueryError)
|