couchbase 3.2.0 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. package/README.md +24 -18
  2. package/binding.gyp +88 -85
  3. package/deps/lcb/CMakeLists.txt +1 -1
  4. package/deps/lcb/CONTRIBUTING.md +1 -1
  5. package/deps/lcb/README.markdown +2 -2
  6. package/deps/lcb/RELEASE_NOTES.markdown +99 -14
  7. package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
  8. package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
  9. package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -7
  10. package/deps/lcb/doc/Doxyfile +1 -1
  11. package/deps/lcb/example/CMakeLists.txt +4 -4
  12. package/deps/lcb/example/libuvdirect/main.c +39 -12
  13. package/deps/lcb/example/minimal/durability.cc +149 -0
  14. package/deps/lcb/example/minimal/query.c +11 -9
  15. package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
  16. package/deps/lcb/gyp_config/linux/arm64/config.h +243 -0
  17. package/deps/lcb/include/libcouchbase/couchbase.h +80 -5
  18. package/deps/lcb/include/libcouchbase/error.h +2 -0
  19. package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
  20. package/deps/lcb/include/libcouchbase/tracing.h +2 -2
  21. package/deps/lcb/include/memcached/protocol_binary.h +21 -0
  22. package/deps/lcb/libcouchbase.gyp +347 -349
  23. package/deps/lcb/packaging/deb/control +1 -1
  24. package/deps/lcb/src/analytics/analytics_handle.cc +13 -5
  25. package/deps/lcb/src/analytics/analytics_handle.hh +29 -0
  26. package/deps/lcb/src/bootstrap.cc +6 -3
  27. package/deps/lcb/src/capi/cmd_analytics.cc +12 -1
  28. package/deps/lcb/src/capi/cmd_analytics.hh +30 -0
  29. package/deps/lcb/src/capi/cmd_counter.hh +23 -0
  30. package/deps/lcb/src/capi/cmd_exists.hh +24 -1
  31. package/deps/lcb/src/capi/cmd_get.hh +22 -0
  32. package/deps/lcb/src/capi/cmd_get_replica.hh +23 -0
  33. package/deps/lcb/src/capi/cmd_http.hh +7 -0
  34. package/deps/lcb/src/capi/cmd_query.cc +11 -1
  35. package/deps/lcb/src/capi/cmd_query.hh +31 -0
  36. package/deps/lcb/src/capi/cmd_remove.hh +23 -0
  37. package/deps/lcb/src/capi/cmd_search.cc +6 -0
  38. package/deps/lcb/src/capi/cmd_search.hh +23 -0
  39. package/deps/lcb/src/capi/cmd_store.hh +33 -21
  40. package/deps/lcb/src/capi/cmd_subdoc.hh +35 -0
  41. package/deps/lcb/src/capi/cmd_touch.hh +23 -0
  42. package/deps/lcb/src/capi/cmd_unlock.hh +23 -0
  43. package/deps/lcb/src/capi/cmd_view.hh +6 -0
  44. package/deps/lcb/src/capi/collection_qualifier.hh +2 -2
  45. package/deps/lcb/src/cntl.cc +45 -11
  46. package/deps/lcb/src/crypto.cc +2 -2
  47. package/deps/lcb/src/dns-srv.cc +5 -3
  48. package/deps/lcb/src/errmap.cc +5 -9
  49. package/deps/lcb/src/errmap.h +7 -3
  50. package/deps/lcb/src/handler.cc +24 -18
  51. package/deps/lcb/src/hostlist.h +2 -2
  52. package/deps/lcb/src/http/http-priv.h +2 -2
  53. package/deps/lcb/src/http/http.cc +5 -2
  54. package/deps/lcb/src/instance.cc +20 -11
  55. package/deps/lcb/src/internal.h +9 -0
  56. package/deps/lcb/src/lcbio/connect.cc +14 -2
  57. package/deps/lcb/src/lcbio/connect.h +2 -2
  58. package/deps/lcb/src/lcbio/ctx.cc +4 -2
  59. package/deps/lcb/src/lcbio/ioutils.cc +9 -10
  60. package/deps/lcb/src/lcbio/manager.cc +1 -1
  61. package/deps/lcb/src/mcserver/mcserver.cc +9 -6
  62. package/deps/lcb/src/mcserver/negotiate.cc +39 -17
  63. package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
  64. package/deps/lcb/src/n1ql/query_handle.cc +41 -19
  65. package/deps/lcb/src/n1ql/query_handle.hh +28 -1
  66. package/deps/lcb/src/operations/counter.cc +18 -5
  67. package/deps/lcb/src/operations/exists.cc +25 -4
  68. package/deps/lcb/src/operations/get.cc +39 -19
  69. package/deps/lcb/src/operations/get_replica.cc +28 -8
  70. package/deps/lcb/src/operations/observe.cc +1 -1
  71. package/deps/lcb/src/operations/ping.cc +8 -8
  72. package/deps/lcb/src/operations/pktfwd.cc +2 -1
  73. package/deps/lcb/src/operations/remove.cc +39 -22
  74. package/deps/lcb/src/operations/store.cc +18 -5
  75. package/deps/lcb/src/operations/subdoc.cc +18 -6
  76. package/deps/lcb/src/operations/touch.cc +34 -16
  77. package/deps/lcb/src/operations/unlock.cc +24 -5
  78. package/deps/lcb/src/packetutils.h +3 -2
  79. package/deps/lcb/src/retryq.cc +24 -5
  80. package/deps/lcb/src/search/search.cc +1 -0
  81. package/deps/lcb/src/search/search_handle.cc +30 -8
  82. package/deps/lcb/src/search/search_handle.hh +29 -0
  83. package/deps/lcb/src/settings.cc +1 -1
  84. package/deps/lcb/src/ssl/ssl_common.c +6 -7
  85. package/deps/lcb/src/tracing/span.cc +47 -14
  86. package/deps/lcb/src/tracing/tracer.cc +11 -2
  87. package/deps/lcb/src/tracing/tracing-internal.h +105 -93
  88. package/deps/lcb/src/utilities.cc +43 -0
  89. package/deps/lcb/src/utilities.h +53 -0
  90. package/deps/lcb/src/vbucket/vbucket.c +34 -33
  91. package/deps/lcb/src/views/view_handle.cc +13 -5
  92. package/deps/lcb/src/views/view_handle.hh +29 -0
  93. package/deps/lcb/tests/CMakeLists.txt +21 -0
  94. package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
  95. package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
  96. package/deps/lcb/tests/basic/t_n1qlstrings.cc +73 -0
  97. package/deps/lcb/tests/iotests/mock-environment.cc +30 -1
  98. package/deps/lcb/tests/iotests/mock-environment.h +49 -0
  99. package/deps/lcb/tests/iotests/mock-unit-test.cc +104 -6
  100. package/deps/lcb/tests/iotests/mock-unit-test.h +34 -0
  101. package/deps/lcb/tests/iotests/t_collections.cc +1 -1
  102. package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
  103. package/deps/lcb/tests/iotests/t_get.cc +109 -7
  104. package/deps/lcb/tests/iotests/t_http.cc +9 -4
  105. package/deps/lcb/tests/iotests/t_lock.cc +18 -0
  106. package/deps/lcb/tests/iotests/t_mutate.cc +157 -63
  107. package/deps/lcb/tests/iotests/t_n1ql.cc +330 -33
  108. package/deps/lcb/tests/iotests/t_views.cc +1 -0
  109. package/deps/lcb/tests/iotests/testutil.cc +168 -0
  110. package/deps/lcb/tests/iotests/testutil.h +116 -0
  111. package/deps/lcb/tests/mocksupport/procutil.c +32 -28
  112. package/deps/lcb/tests/mocksupport/server.c +0 -1
  113. package/deps/lcb/tests/mocksupport/timeout.c +2 -2
  114. package/deps/lcb/tools/cbc.cc +7 -0
  115. package/dist/analyticsindexmanager.js +512 -524
  116. package/dist/binding.d.ts +3 -0
  117. package/dist/bindingutilities.js +4 -0
  118. package/dist/bucket.js +1 -1
  119. package/dist/bucketmanager.d.ts +31 -1
  120. package/dist/bucketmanager.js +194 -186
  121. package/dist/cluster.d.ts +7 -0
  122. package/dist/cluster.js +48 -38
  123. package/dist/collection.js +11 -17
  124. package/dist/collectionmanager.js +181 -197
  125. package/dist/connection.d.ts +3 -1
  126. package/dist/connection.js +27 -16
  127. package/dist/couchbase.d.ts +1 -0
  128. package/dist/couchbase.js +3 -13
  129. package/dist/datastructures.js +239 -310
  130. package/dist/diagnosticsexecutor.js +70 -85
  131. package/dist/errors.d.ts +70 -0
  132. package/dist/errors.js +96 -2
  133. package/dist/eventingfunctionmanager.d.ts +804 -0
  134. package/dist/eventingfunctionmanager.js +993 -0
  135. package/dist/httpexecutor.d.ts +2 -1
  136. package/dist/httpexecutor.js +30 -37
  137. package/dist/queryindexmanager.js +240 -266
  138. package/dist/scope.js +10 -4
  139. package/dist/sdspecs.d.ts +1 -1
  140. package/dist/searchexecutor.js +3 -0
  141. package/dist/searchindexmanager.js +240 -271
  142. package/dist/searchquery.d.ts +17 -0
  143. package/dist/searchquery.js +22 -1
  144. package/dist/searchtypes.d.ts +7 -2
  145. package/dist/searchtypes.js +2 -2
  146. package/dist/usermanager.js +251 -264
  147. package/dist/utilities.d.ts +2 -0
  148. package/dist/utilities.js +7 -2
  149. package/dist/viewexecutor.js +1 -1
  150. package/dist/viewindexmanager.js +131 -150
  151. package/package.json +1 -1
  152. package/src/addondata.cpp +58 -0
  153. package/src/addondata.h +40 -0
  154. package/src/binding.cpp +3 -1
  155. package/src/cas.h +2 -2
  156. package/src/connection.cpp +25 -178
  157. package/src/connection.h +8 -65
  158. package/src/connection_ops.cpp +57 -34
  159. package/src/constants.cpp +3 -0
  160. package/src/instance.cpp +235 -0
  161. package/src/instance.h +102 -0
  162. package/src/{connection_callbacks.cpp → instance_callbacks.cpp} +34 -34
  163. package/src/logger.cpp +11 -1
  164. package/src/logger.h +3 -0
  165. package/src/metrics.cpp +10 -0
  166. package/src/metrics.h +3 -0
  167. package/src/mutationtoken.h +2 -2
  168. package/src/opbuilder.h +13 -15
  169. package/src/respreader.cpp +1 -0
  170. package/src/respreader.h +6 -4
  171. package/src/tracespan.h +11 -11
  172. package/src/tracing.cpp +11 -0
  173. package/src/tracing.h +3 -0
  174. package/src/valueparser.h +5 -0
  175. package/deps/lcb/example/observe/durability.c +0 -110
@@ -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"
@@ -407,6 +408,8 @@ class MockEnvironment : public ::testing::Environment
407
408
  void createConnection(lcb_INSTANCE **instance);
408
409
 
409
410
  void createConnection(HandleWrap &handle, lcb_INSTANCE **instance);
411
+ void createConnection(HandleWrap &handle, lcb_INSTANCE **instance, const std::string &username,
412
+ const std::string &password);
410
413
  void createConnection(HandleWrap &handle, lcb_INSTANCE **instance, const lcb_CREATEOPTS *options) const;
411
414
 
412
415
  /**
@@ -449,6 +452,16 @@ class MockEnvironment : public ::testing::Environment
449
452
  std::cerr << std::endl;
450
453
  }
451
454
 
455
+ TestTracer &getTracer()
456
+ {
457
+ return test_tracer;
458
+ }
459
+
460
+ TestMeter &getMeter()
461
+ {
462
+ return test_meter;
463
+ }
464
+
452
465
  explicit MockEnvironment(const char **argv, const std::string &name = "default");
453
466
  ~MockEnvironment() override;
454
467
  void postCreate(lcb_INSTANCE *instance) const;
@@ -476,11 +489,47 @@ class MockEnvironment : public ::testing::Environment
476
489
  std::string userName;
477
490
  const char **argv_{nullptr};
478
491
  void clearAndReset();
492
+ TestTracer test_tracer;
493
+ TestMeter test_meter;
479
494
 
480
495
  private:
481
496
  lcb_INSTANCE *innerClient{nullptr};
482
497
  };
483
498
 
499
+ class tracing_guard
500
+ {
501
+ public:
502
+ tracing_guard()
503
+ {
504
+ was_enabled_ = MockEnvironment::getInstance()->getTracer().set_enabled(true);
505
+ }
506
+
507
+ ~tracing_guard()
508
+ {
509
+ MockEnvironment::getInstance()->getTracer().set_enabled(was_enabled_);
510
+ }
511
+
512
+ private:
513
+ bool was_enabled_{false};
514
+ };
515
+
516
+ class metrics_guard
517
+ {
518
+ public:
519
+ metrics_guard()
520
+ {
521
+ was_enabled_ = MockEnvironment::getInstance()->getMeter().set_enabled(true);
522
+ }
523
+
524
+ ~metrics_guard()
525
+ {
526
+ MockEnvironment::getInstance()->getMeter().set_enabled(was_enabled_);
527
+ }
528
+
529
+ private:
530
+ bool was_enabled_{false};
531
+ };
532
+
484
533
  #define LCB_TEST_REQUIRE_CLUSTER_VERSION(v) \
485
534
  if (!MockEnvironment::getInstance()->isRealCluster()) { \
486
535
  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 "bucketconfig/bc_http.h"
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,21 +29,21 @@
29
29
  */
30
30
  void MockUnitTest::SetUp()
31
31
  {
32
- srand(time(NULL));
32
+ srand(time(nullptr));
33
33
  MockEnvironment::Reset();
34
34
  }
35
35
 
36
36
  void checkConnectCommon(lcb_INSTANCE *instance)
37
37
  {
38
- ASSERT_EQ(LCB_SUCCESS, lcb_connect(instance));
38
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_connect(instance));
39
39
  lcb_wait(instance, LCB_WAIT_DEFAULT);
40
40
  ASSERT_EQ(LCB_SUCCESS, lcb_get_bootstrap_status(instance));
41
41
  }
42
42
 
43
43
  void MockUnitTest::createClusterConnection(HandleWrap &handle, lcb_INSTANCE **instance)
44
44
  {
45
- lcb_CREATEOPTS *options = NULL;
46
- MockEnvironment::getInstance()->makeConnectParams(options, NULL, LCB_TYPE_CLUSTER);
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);
@@ -55,6 +55,13 @@ void MockUnitTest::createConnection(HandleWrap &handle, lcb_INSTANCE **instance)
55
55
  checkConnectCommon(handle.getLcb());
56
56
  }
57
57
 
58
+ void MockUnitTest::createConnection(HandleWrap &handle, lcb_INSTANCE **instance, const std::string &username,
59
+ const std::string &password)
60
+ {
61
+ MockEnvironment::getInstance()->createConnection(handle, instance, username, password);
62
+ checkConnectCommon(handle.getLcb());
63
+ }
64
+
58
65
  void MockUnitTest::createConnection(lcb_INSTANCE **instance)
59
66
  {
60
67
  MockEnvironment::getInstance()->createConnection(instance);
@@ -63,7 +70,7 @@ void MockUnitTest::createConnection(lcb_INSTANCE **instance)
63
70
 
64
71
  void MockUnitTest::createConnection(HandleWrap &handle)
65
72
  {
66
- lcb_INSTANCE *instance = NULL;
73
+ lcb_INSTANCE *instance = nullptr;
67
74
  createConnection(handle, &instance);
68
75
  }
69
76
 
@@ -74,3 +81,94 @@ lcb_STATUS MockUnitTest::tryCreateConnection(HandleWrap &hw, lcb_INSTANCE **inst
74
81
  lcb_wait(*instance, LCB_WAIT_DEFAULT);
75
82
  return lcb_get_bootstrap_status(*instance);
76
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:
@@ -51,9 +68,18 @@ class MockUnitTest : public ::testing::Test
51
68
  virtual void createConnection(lcb_INSTANCE **instance);
52
69
  virtual void createConnection(HandleWrap &handle);
53
70
  virtual void createConnection(HandleWrap &handle, lcb_INSTANCE **instance);
71
+ virtual void createConnection(HandleWrap &handle, lcb_INSTANCE **instance, const std::string &username,
72
+ const std::string &password);
54
73
  virtual void createClusterConnection(HandleWrap &handle, lcb_INSTANCE **instance);
55
74
  virtual lcb_STATUS tryCreateConnection(HandleWrap &hw, lcb_INSTANCE **instance, lcb_CREATEOPTS *&crparams);
56
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
+
57
83
  // A mock "Transaction"
58
84
  void doMockTxn(MockCommand &cmd)
59
85
  {
@@ -64,4 +90,12 @@ class MockUnitTest : public ::testing::Test
64
90
  }
65
91
  };
66
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
+
67
101
  #endif
@@ -572,7 +572,7 @@ TEST_F(CollectionUnitTest, testDroppedScope)
572
572
  *
573
573
  * Collection creations are successful
574
574
  */
575
- TEST_F(CollectionUnitTest, testMaxCollectionsPerScope)
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" {
@@ -845,6 +859,7 @@ TEST_F(GetUnitTest, testPessimisticLock)
845
859
  lcb_install_callback(instance, LCB_CALLBACK_UNLOCK, reinterpret_cast<lcb_RESPCALLBACK>(pl_unlock_callback));
846
860
 
847
861
  std::string key(unique_name("testPessimisticLock"));
862
+ std::uint32_t lock_time_s = 10;
848
863
 
849
864
  std::uint64_t cas{0};
850
865
  {
@@ -870,7 +885,7 @@ TEST_F(GetUnitTest, testPessimisticLock)
870
885
  lcb_CMDGET *cmd = nullptr;
871
886
  lcb_cmdget_create(&cmd);
872
887
  lcb_cmdget_key(cmd, key.c_str(), key.size());
873
- lcb_cmdget_locktime(cmd, 5);
888
+ lcb_cmdget_locktime(cmd, lock_time_s);
874
889
  lcb_get(instance, &res, cmd);
875
890
  lcb_cmdget_destroy(cmd);
876
891
  lcb_wait(instance, LCB_WAIT_DEFAULT);
@@ -902,7 +917,7 @@ TEST_F(GetUnitTest, testPessimisticLock)
902
917
  lcb_CMDGET *cmd = nullptr;
903
918
  lcb_cmdget_create(&cmd);
904
919
  lcb_cmdget_key(cmd, key.c_str(), key.size());
905
- lcb_cmdget_locktime(cmd, 5);
920
+ lcb_cmdget_locktime(cmd, lock_time_s);
906
921
  lcb_get(instance, &res, cmd);
907
922
  lcb_cmdget_destroy(cmd);
908
923
  lcb_wait(instance, LCB_WAIT_DEFAULT);
@@ -949,7 +964,7 @@ TEST_F(GetUnitTest, testPessimisticLock)
949
964
  lcb_CMDGET *cmd = nullptr;
950
965
  lcb_cmdget_create(&cmd);
951
966
  lcb_cmdget_key(cmd, key.c_str(), key.size());
952
- lcb_cmdget_locktime(cmd, 5);
967
+ lcb_cmdget_locktime(cmd, lock_time_s);
953
968
  lcb_get(instance, &res, cmd);
954
969
  lcb_cmdget_destroy(cmd);
955
970
  lcb_wait(instance, LCB_WAIT_DEFAULT);
@@ -1096,10 +1111,6 @@ TEST_F(GetUnitTest, testChangePassword)
1096
1111
  createConnection(hwHttp, &instanceHttp);
1097
1112
  (void)lcb_install_callback(instanceHttp, LCB_CALLBACK_HTTP, (lcb_RESPCALLBACK)change_password_http_callback);
1098
1113
 
1099
- // Set short timeout
1100
- lcb_uint32_t tmoval = 100000;
1101
- lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_OP_TIMEOUT, &tmoval);
1102
-
1103
1114
  // store keys
1104
1115
  // run one set to connect to only one node
1105
1116
  // the goal is to change the password then try to connect others nodes
@@ -1179,3 +1190,94 @@ TEST_F(GetUnitTest, testChangePassword)
1179
1190
  }
1180
1191
  EXPECT_EQ(nbCallbacks, counter);
1181
1192
  }
1193
+
1194
+ struct touch_result {
1195
+ bool called{false};
1196
+ lcb_STATUS rc{LCB_ERR_GENERIC};
1197
+ };
1198
+
1199
+ struct gat_result {
1200
+ bool called{false};
1201
+ lcb_STATUS rc{LCB_ERR_GENERIC};
1202
+ std::string value{};
1203
+ };
1204
+
1205
+ extern "C" {
1206
+ static void test_touch_zero_reset(lcb_INSTANCE *, lcb_CALLBACK_TYPE, const lcb_RESPTOUCH *resp)
1207
+ {
1208
+ touch_result *result;
1209
+ lcb_resptouch_cookie(resp, (void **)&result);
1210
+ result->called = true;
1211
+ result->rc = lcb_resptouch_status(resp);
1212
+ }
1213
+
1214
+ static void test_get_and_touch_zero_reset(lcb_INSTANCE *, lcb_CALLBACK_TYPE, const lcb_RESPGET *resp)
1215
+ {
1216
+ gat_result *result;
1217
+ lcb_respget_cookie(resp, (void **)&result);
1218
+ result->called = true;
1219
+ result->rc = lcb_respget_status(resp);
1220
+ const char *value = nullptr;
1221
+ std::size_t value_len = 0;
1222
+ lcb_respget_value(resp, &value, &value_len);
1223
+ if (value_len > 0 && value != nullptr) {
1224
+ result->value.assign(value, value_len);
1225
+ }
1226
+ }
1227
+ }
1228
+
1229
+ TEST_F(GetUnitTest, testTouchWithZeroExpiryResetsExpiry)
1230
+ {
1231
+ std::string key = unique_name("gat_reset_expiry_key");
1232
+ std::string value = unique_name("gat_reset_expiry_value");
1233
+
1234
+ HandleWrap hw;
1235
+ lcb_INSTANCE *instance;
1236
+ createConnection(hw, &instance);
1237
+
1238
+ (void)lcb_install_callback(instance, LCB_CALLBACK_TOUCH, (lcb_RESPCALLBACK)test_touch_zero_reset);
1239
+ (void)lcb_install_callback(instance, LCB_CALLBACK_GET, (lcb_RESPCALLBACK)test_get_and_touch_zero_reset);
1240
+ storeKey(instance, key, value);
1241
+
1242
+ {
1243
+ touch_result res{};
1244
+ lcb_CMDTOUCH *cmd;
1245
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdtouch_create(&cmd));
1246
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdtouch_key(cmd, key.c_str(), key.size()));
1247
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdtouch_expiry(cmd, 1));
1248
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_touch(instance, &res, cmd));
1249
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdtouch_destroy(cmd));
1250
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_wait(instance, LCB_WAIT_DEFAULT));
1251
+ ASSERT_TRUE(res.called);
1252
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
1253
+ }
1254
+
1255
+ {
1256
+ gat_result res{};
1257
+ lcb_CMDGET *cmd;
1258
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_create(&cmd));
1259
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_key(cmd, key.c_str(), key.size()));
1260
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_expiry(cmd, 0));
1261
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_get(instance, &res, cmd));
1262
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_destroy(cmd));
1263
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_wait(instance, LCB_WAIT_DEFAULT));
1264
+ ASSERT_TRUE(res.called);
1265
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
1266
+ ASSERT_EQ(value, res.value);
1267
+ }
1268
+
1269
+ sleep(2);
1270
+
1271
+ {
1272
+ gat_result res{};
1273
+ lcb_CMDGET *cmd;
1274
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_create(&cmd));
1275
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_key(cmd, key.c_str(), key.size()));
1276
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_get(instance, &res, cmd));
1277
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_destroy(cmd));
1278
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_wait(instance, LCB_WAIT_DEFAULT));
1279
+ ASSERT_TRUE(res.called);
1280
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
1281
+ ASSERT_EQ(value, res.value);
1282
+ }
1283
+ }
@@ -464,9 +464,11 @@ TEST_F(HttpUnitTest, testCancelWorks)
464
464
  }
465
465
 
466
466
  extern "C" {
467
- static void noInvoke_callback(lcb_INSTANCE *, int, const lcb_RESPBASE *)
467
+ static void noInvoke_callback(lcb_INSTANCE *, int, const lcb_RESPHTTP *resp)
468
468
  {
469
- EXPECT_FALSE(true) << "This callback should not be invoked!";
469
+ bool *called;
470
+ lcb_resphttp_cookie(resp, (void **)&called);
471
+ *called = true;
470
472
  }
471
473
  }
472
474
  TEST_F(HttpUnitTest, testDestroyWithActiveRequest)
@@ -481,10 +483,13 @@ TEST_F(HttpUnitTest, testDestroyWithActiveRequest)
481
483
  std::string ss;
482
484
  makeAdminReq(&cmd, ss, instance);
483
485
 
484
- lcb_install_callback(instance, LCB_CALLBACK_HTTP, noInvoke_callback);
486
+ lcb_install_callback(instance, LCB_CALLBACK_HTTP, (lcb_RESPCALLBACK)noInvoke_callback);
485
487
  lcb_sched_enter(instance);
486
- ASSERT_EQ(LCB_SUCCESS, lcb_http(instance, nullptr, cmd));
488
+ bool called = false;
489
+ ASSERT_EQ(LCB_SUCCESS, lcb_http(instance, &called, cmd));
487
490
  lcb_cmdhttp_destroy(cmd);
488
491
  lcb_sched_leave(instance);
492
+ fprintf(stderr, "invoke lcb_destroy\n");
489
493
  lcb_destroy(instance);
494
+ ASSERT_TRUE(called) << "lcb_destroy should invoke HTTP callbacks";
490
495
  }
@@ -347,3 +347,21 @@ TEST_F(LockUnitTest, testUnlLockContention)
347
347
  getKey(instance, key, gitm);
348
348
  ASSERT_EQ(gitm.val, newval);
349
349
  }
350
+
351
+ TEST_F(LockUnitTest, testDoesNotAllowToSwitchModeFromLockToTouch)
352
+ {
353
+ lcb_CMDGET *cmd;
354
+ lcb_cmdget_create(&cmd);
355
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_locktime(cmd, 5));
356
+ ASSERT_STATUS_EQ(LCB_ERR_INVALID_ARGUMENT, lcb_cmdget_expiry(cmd, 10));
357
+ lcb_cmdget_destroy(cmd);
358
+ }
359
+
360
+ TEST_F(LockUnitTest, testDoesNotAllowToSwitchModeFromTouchToLock)
361
+ {
362
+ lcb_CMDGET *cmd;
363
+ lcb_cmdget_create(&cmd);
364
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdget_expiry(cmd, 5));
365
+ ASSERT_STATUS_EQ(LCB_ERR_INVALID_ARGUMENT, lcb_cmdget_locktime(cmd, 10));
366
+ lcb_cmdget_destroy(cmd);
367
+ }