couchbase 3.2.3 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/deps/lcb/CMakeLists.txt +1 -1
  2. package/deps/lcb/CONTRIBUTING.md +1 -1
  3. package/deps/lcb/README.markdown +2 -2
  4. package/deps/lcb/RELEASE_NOTES.markdown +72 -17
  5. package/deps/lcb/cmake/Modules/GetVersionInfo.cmake +1 -1
  6. package/deps/lcb/contrib/cbsasl/src/scram-sha/scram_utils.cc +22 -26
  7. package/deps/lcb/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +20 -6
  8. package/deps/lcb/doc/Doxyfile +1 -1
  9. package/deps/lcb/example/minimal/query.c +9 -7
  10. package/deps/lcb/gyp_config/common/libcouchbase/configuration.h +3 -3
  11. package/deps/lcb/include/libcouchbase/couchbase.h +3 -1
  12. package/deps/lcb/include/libcouchbase/error.h +2 -0
  13. package/deps/lcb/include/libcouchbase/ixmgmt.h +15 -10
  14. package/deps/lcb/include/libcouchbase/tracing.h +2 -2
  15. package/deps/lcb/include/memcached/protocol_binary.h +21 -0
  16. package/deps/lcb/libcouchbase.gyp +347 -349
  17. package/deps/lcb/packaging/deb/control +1 -1
  18. package/deps/lcb/src/analytics/analytics_handle.cc +7 -5
  19. package/deps/lcb/src/analytics/analytics_handle.hh +28 -0
  20. package/deps/lcb/src/capi/cmd_counter.hh +6 -0
  21. package/deps/lcb/src/capi/cmd_exists.hh +6 -0
  22. package/deps/lcb/src/capi/cmd_get.hh +5 -0
  23. package/deps/lcb/src/capi/cmd_get_replica.hh +6 -0
  24. package/deps/lcb/src/capi/cmd_remove.hh +6 -0
  25. package/deps/lcb/src/capi/cmd_search.hh +6 -0
  26. package/deps/lcb/src/capi/cmd_store.hh +16 -21
  27. package/deps/lcb/src/capi/cmd_subdoc.hh +18 -0
  28. package/deps/lcb/src/capi/cmd_touch.hh +6 -0
  29. package/deps/lcb/src/capi/cmd_unlock.hh +6 -0
  30. package/deps/lcb/src/capi/cmd_view.hh +6 -0
  31. package/deps/lcb/src/capi/collection_qualifier.hh +2 -2
  32. package/deps/lcb/src/cntl.cc +42 -8
  33. package/deps/lcb/src/dns-srv.cc +5 -3
  34. package/deps/lcb/src/errmap.cc +5 -9
  35. package/deps/lcb/src/errmap.h +7 -3
  36. package/deps/lcb/src/handler.cc +24 -18
  37. package/deps/lcb/src/lcbio/ctx.cc +4 -2
  38. package/deps/lcb/src/mcserver/mcserver.cc +8 -5
  39. package/deps/lcb/src/mcserver/negotiate.cc +39 -17
  40. package/deps/lcb/src/n1ql/ixmgmt.cc +1 -2
  41. package/deps/lcb/src/n1ql/query_handle.cc +27 -16
  42. package/deps/lcb/src/n1ql/query_handle.hh +27 -1
  43. package/deps/lcb/src/operations/counter.cc +1 -1
  44. package/deps/lcb/src/operations/exists.cc +2 -2
  45. package/deps/lcb/src/operations/get.cc +2 -2
  46. package/deps/lcb/src/operations/observe.cc +1 -1
  47. package/deps/lcb/src/operations/remove.cc +1 -1
  48. package/deps/lcb/src/operations/store.cc +1 -1
  49. package/deps/lcb/src/operations/subdoc.cc +1 -2
  50. package/deps/lcb/src/operations/touch.cc +2 -2
  51. package/deps/lcb/src/operations/unlock.cc +2 -2
  52. package/deps/lcb/src/search/search_handle.cc +27 -8
  53. package/deps/lcb/src/search/search_handle.hh +29 -0
  54. package/deps/lcb/src/ssl/ssl_common.c +6 -7
  55. package/deps/lcb/src/tracing/span.cc +43 -10
  56. package/deps/lcb/src/tracing/tracing-internal.h +105 -93
  57. package/deps/lcb/src/views/view_handle.cc +13 -5
  58. package/deps/lcb/src/views/view_handle.hh +29 -0
  59. package/deps/lcb/tests/CMakeLists.txt +21 -0
  60. package/deps/lcb/tests/basic/t_ctlcodes.cc +24 -3
  61. package/deps/lcb/tests/basic/t_jsparse.cc +8 -0
  62. package/deps/lcb/tests/iotests/mock-environment.cc +15 -0
  63. package/deps/lcb/tests/iotests/mock-environment.h +47 -0
  64. package/deps/lcb/tests/iotests/mock-unit-test.cc +96 -5
  65. package/deps/lcb/tests/iotests/mock-unit-test.h +32 -0
  66. package/deps/lcb/tests/iotests/t_collections.cc +1 -1
  67. package/deps/lcb/tests/iotests/t_confmon.cc +4 -2
  68. package/deps/lcb/tests/iotests/t_get.cc +14 -4
  69. package/deps/lcb/tests/iotests/t_n1ql.cc +17 -1
  70. package/deps/lcb/tests/iotests/t_views.cc +1 -0
  71. package/deps/lcb/tests/iotests/testutil.cc +168 -0
  72. package/deps/lcb/tests/iotests/testutil.h +111 -0
  73. package/deps/lcb/tests/mocksupport/procutil.c +32 -28
  74. package/deps/lcb/tests/mocksupport/server.c +0 -1
  75. package/deps/lcb/tools/cbc.cc +7 -0
  76. package/dist/analyticsindexmanager.js +3 -3
  77. package/dist/binding.d.ts +2 -0
  78. package/dist/bindingutilities.js +4 -0
  79. package/dist/bucketmanager.d.ts +31 -1
  80. package/dist/bucketmanager.js +28 -2
  81. package/dist/collection.js +2 -2
  82. package/dist/collectionmanager.js +2 -2
  83. package/dist/connection.js +3 -0
  84. package/dist/errors.d.ts +18 -0
  85. package/dist/errors.js +26 -2
  86. package/dist/eventingfunctionmanager.js +6 -6
  87. package/dist/queryindexmanager.js +3 -3
  88. package/dist/searchexecutor.js +3 -0
  89. package/dist/searchindexmanager.js +1 -1
  90. package/dist/searchquery.d.ts +17 -0
  91. package/dist/searchquery.js +22 -1
  92. package/dist/searchtypes.d.ts +7 -2
  93. package/dist/searchtypes.js +2 -2
  94. package/dist/usermanager.js +1 -1
  95. package/dist/viewindexmanager.js +1 -1
  96. package/package.json +1 -1
  97. package/src/connection.cpp +2 -0
  98. package/src/constants.cpp +2 -0
  99. package/src/instance.cpp +8 -1
  100. package/src/instance.h +1 -0
@@ -26,6 +26,13 @@
26
26
  #include <queue>
27
27
  #include <map>
28
28
  #include <string>
29
+ #include <memory>
30
+
31
+ LCB_INTERNAL_API
32
+ void lcbtrace_span_add_system_tags(lcbtrace_SPAN *span, const lcb_settings *settings, lcbtrace_THRESHOLDOPTS svc);
33
+ LIBCOUCHBASE_API
34
+ void lcbtrace_span_add_tag_str_nocopy(lcbtrace_SPAN *span, const char *name, const char *value);
35
+ void lcbtrace_span_add_host_and_port(lcbtrace_SPAN *span, lcbio_CONNINFO *info);
29
36
 
30
37
  namespace lcb
31
38
  {
@@ -45,6 +52,7 @@ class Span
45
52
  return m_finish - m_start;
46
53
  }
47
54
 
55
+ void add_tag(const char *name, const std::string &value);
48
56
  void add_tag(const char *name, int copy, const char *value, int copy_value);
49
57
  void add_tag(const char *name, int copy_key, const char *value, size_t value_len, int copy_value);
50
58
  void add_tag(const char *name, int copy, uint64_t value);
@@ -141,7 +149,7 @@ class ThresholdLoggingTracer
141
149
  QueueEntry convert(lcbtrace_SPAN *span);
142
150
 
143
151
  public:
144
- ThresholdLoggingTracer(lcb_INSTANCE *instance);
152
+ explicit ThresholdLoggingTracer(lcb_INSTANCE *instance);
145
153
 
146
154
  lcbtrace_TRACER *wrap();
147
155
  void add_orphan(lcbtrace_SPAN *span);
@@ -156,108 +164,112 @@ class ThresholdLoggingTracer
156
164
  lcb::io::Timer<ThresholdLoggingTracer, &ThresholdLoggingTracer::flush_threshold> m_tflush;
157
165
  };
158
166
 
159
- } // namespace trace
160
- } // namespace lcb
161
-
162
- extern "C" {
163
- #endif /* __cplusplus */
164
- LCB_INTERNAL_API
165
- void lcbtrace_span_add_system_tags(lcbtrace_SPAN *span, lcb_settings *settings, lcbtrace_THRESHOLDOPTS svc);
166
- LCB_INTERNAL_API
167
- void lcbtrace_span_set_parent(lcbtrace_SPAN *span, lcbtrace_SPAN *parent);
168
- LCB_INTERNAL_API
169
- void lcbtrace_span_set_orphaned(lcbtrace_SPAN *span, int val);
170
- LIBCOUCHBASE_API
171
- void lcbtrace_span_add_tag_str_nocopy(lcbtrace_SPAN *span, const char *name, const char *value);
172
-
173
- const char *dur_level_to_string(lcb_DURABILITY_LEVEL dur_level);
174
- void lcbtrace_span_add_host_and_port(lcbtrace_SPAN *span, lcbio_CONNINFO *info);
175
- #ifdef __cplusplus
176
- #define LCBTRACE_ADD_RETRIES(span, retries) \
177
- if (span) { \
178
- span->find_outer_or_this()->add_tag(LCBTRACE_TAG_RETRIES, 0, (uint64_t)retries); \
167
+ template <typename COMMAND>
168
+ lcbtrace_SPAN *start_kv_span(const lcb_settings *settings, const mc_PACKET *packet, std::shared_ptr<COMMAND> cmd)
169
+ {
170
+ if (settings == nullptr || settings->tracer == nullptr) {
171
+ return nullptr;
172
+ }
173
+ lcbtrace_SPAN *span;
174
+ lcbtrace_SPAN *parent_span = cmd->parent_span();
175
+ if (parent_span != nullptr && parent_span->is_outer() && settings->tracer->flags & LCBTRACE_F_THRESHOLD) {
176
+ span = parent_span;
177
+ span->should_finish(false);
178
+ } else {
179
+ lcbtrace_REF ref;
180
+ ref.type = LCBTRACE_REF_CHILD_OF;
181
+ ref.span = parent_span;
182
+ bool is_dispatch = (parent_span != nullptr && parent_span->is_outer());
183
+ span = lcbtrace_span_start((settings)->tracer,
184
+ is_dispatch ? LCBTRACE_OP_DISPATCH_TO_SERVER : cmd->operation_name().c_str(),
185
+ LCBTRACE_NOW, &ref);
186
+ span->should_finish(true);
187
+ span->is_outer(!is_dispatch);
179
188
  }
189
+ span->is_dispatch(true);
190
+ std::string operation_id = std::to_string(packet->opaque);
191
+ lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_OPERATION_ID, operation_id.c_str());
192
+ lcbtrace_span_add_system_tags(span, settings, LCBTRACE_THRESHOLD_KV);
193
+ span->add_tag(LCBTRACE_TAG_SCOPE, cmd->collection().scope());
194
+ span->add_tag(LCBTRACE_TAG_COLLECTION, cmd->collection().collection());
195
+ span->add_tag(LCBTRACE_TAG_OPERATION, cmd->operation_name());
196
+ return span;
197
+ }
180
198
 
181
- // called by lcb_query, etc... The underlying lcb_http call will fill in the dispatch span tags
182
- #define LCBTRACE_HTTP_START(settings, opaque, pspan, operation_name, svc, outspan) \
183
- LCBTRACE_START(settings, opaque, pspan, operation_name, svc, outspan)
199
+ void finish_kv_span(const mc_PIPELINE *pipeline, const mc_PACKET *request_pkt, const MemcachedResponse *response_pkt);
184
200
 
185
- #define LCBTRACE_KV_START(settings, opaque, cmd, operation_name, outspan) \
186
- if (nullptr != (settings)->tracer) { \
187
- lcbtrace_SPAN *pspan = cmd->parent_span(); \
188
- char opid[20] = {}; \
189
- snprintf(opid, sizeof(opid), "%p", reinterpret_cast<void *>(opaque)); \
190
- LCBTRACE_START(settings, opid, pspan, operation_name, LCBTRACE_THRESHOLD_KV, outspan) \
201
+ template <typename COMMAND>
202
+ lcbtrace_SPAN *start_kv_span_with_durability(const lcb_settings *settings, const mc_PACKET *packet,
203
+ std::shared_ptr<COMMAND> cmd)
204
+ {
205
+ lcbtrace_SPAN *span = start_kv_span(settings, packet, cmd);
206
+ if (span != nullptr && cmd->durability_level() != LCB_DURABILITYLEVEL_NONE) {
207
+ span->add_tag(LCBTRACE_TAG_DURABILITY, 0, dur_level_to_string(cmd->durability_level()), 0);
191
208
  }
209
+ return span;
210
+ }
192
211
 
193
- // don't create a span if passed an outer parent, if we are the threshold logger,
194
- // and use its close to determine times, etc...
195
- #define LCBTRACE_START(settings, opaque, pspan, operation_name, svc, outspan) \
196
- if (nullptr != (settings)->tracer) { \
197
- if (nullptr != pspan && pspan->is_outer() && (settings)->tracer->flags & LCBTRACE_F_THRESHOLD) { \
198
- outspan = pspan; \
199
- outspan->should_finish(false); \
200
- } else { \
201
- lcbtrace_REF ref; \
202
- ref.type = LCBTRACE_REF_CHILD_OF; \
203
- ref.span = pspan; \
204
- bool is_dispatch = (pspan && pspan->is_outer()); \
205
- outspan = \
206
- lcbtrace_span_start((settings)->tracer, is_dispatch ? LCBTRACE_OP_DISPATCH_TO_SERVER : operation_name, \
207
- LCBTRACE_NOW, &ref); \
208
- outspan->should_finish(true); \
209
- outspan->is_outer(!is_dispatch); \
210
- } \
211
- outspan->is_dispatch(true); \
212
- if (opaque) { \
213
- lcbtrace_span_add_tag_str(outspan, LCBTRACE_TAG_OPERATION_ID, opaque); \
214
- } \
215
- lcbtrace_span_add_system_tags(outspan, settings, svc); \
216
- } else { \
217
- outspan = nullptr; \
212
+ template <typename COMMAND>
213
+ lcbtrace_SPAN *start_http_span(const lcb_settings *settings, const COMMAND *cmd)
214
+ {
215
+ if (settings == nullptr || settings->tracer == nullptr) {
216
+ return nullptr;
217
+ }
218
+ lcbtrace_SPAN *span;
219
+ lcbtrace_SPAN *parent_span = cmd->parent_span();
220
+ if (parent_span != nullptr && parent_span->is_outer() && settings->tracer->flags & LCBTRACE_F_THRESHOLD) {
221
+ span = parent_span;
222
+ span->should_finish(false);
223
+ } else {
224
+ lcbtrace_REF ref;
225
+ ref.type = LCBTRACE_REF_CHILD_OF;
226
+ ref.span = parent_span;
227
+ bool is_dispatch = (parent_span != nullptr && parent_span->is_outer());
228
+ span = lcbtrace_span_start((settings)->tracer,
229
+ is_dispatch ? LCBTRACE_OP_DISPATCH_TO_SERVER : cmd->operation_name().c_str(),
230
+ LCBTRACE_NOW, &ref);
231
+ span->should_finish(true);
232
+ span->is_outer(!is_dispatch);
218
233
  }
234
+ span->is_dispatch(true);
235
+ lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_OPERATION_ID, cmd->client_context_id().c_str());
236
+ lcbtrace_span_add_system_tags(span, settings, cmd->service());
237
+ span->add_tag(LCBTRACE_TAG_OPERATION, cmd->operation_name());
238
+ return span;
239
+ }
219
240
 
220
- #define LCBTRACE_KVSTORE_START(settings, opaque, cmd, operation_name, outspan) \
221
- LCBTRACE_KV_START(settings, opaque, cmd, operation_name, outspan) \
222
- if ((settings)->tracer) { \
223
- outspan->add_tag(LCBTRACE_TAG_DURABILITY, 0, dur_level_to_string(cmd->durability_level()), 0); \
241
+ template <typename COMMAND>
242
+ lcbtrace_SPAN *start_http_span_with_statement(const lcb_settings *settings, const COMMAND *cmd,
243
+ const std::string &statement)
244
+ {
245
+ lcbtrace_SPAN *span = start_http_span(settings, cmd);
246
+ if (span != nullptr && !statement.empty()) {
247
+ span->add_tag(LCBTRACE_TAG_STATEMENT, statement);
224
248
  }
249
+ return span;
250
+ }
225
251
 
226
- #define LCBTRACE_KV_FINISH(pipeline, request, resp, server_duration) \
227
- do { \
228
- lcbtrace_SPAN *dispatch_span__ = MCREQ_PKT_RDATA(request)->span; \
229
- if (dispatch_span__) { \
230
- dispatch_span__->increment_server(server_duration); \
231
- lcb::Server *server = static_cast<lcb::Server *>(pipeline); \
232
- dispatch_span__->find_outer_or_this()->add_tag(LCBTRACE_TAG_RETRIES, 0, (uint64_t)request->retries); \
233
- lcbtrace_span_add_tag_str_nocopy(dispatch_span__, LCBTRACE_TAG_TRANSPORT, "IP.TCP"); \
234
- lcbio_CTX *ctx = server->connctx; \
235
- if (ctx) { \
236
- char local_id[34] = {}; \
237
- snprintf(local_id, sizeof(local_id), "%016" PRIx64 "/%016" PRIx64, \
238
- (uint64_t)server->get_settings()->iid, (uint64_t)ctx->sock->id); \
239
- lcbtrace_span_add_tag_str(dispatch_span__, LCBTRACE_TAG_LOCAL_ID, local_id); \
240
- lcbtrace_span_add_host_and_port(dispatch_span__, ctx->sock->info); \
241
- } \
242
- if (dispatch_span__->should_finish()) { \
243
- lcbtrace_span_finish(dispatch_span__, LCBTRACE_NOW); \
244
- } \
245
- } \
246
- } while (0)
247
-
248
- #define LCBTRACE_HTTP_FINISH(span) \
249
- if (nullptr != span) { \
250
- lcbtrace_span_add_tag_str_nocopy(span, LCBTRACE_TAG_TRANSPORT, "IP.TCP"); \
251
- if (span->should_finish()) { \
252
- lcbtrace_span_finish(span, LCBTRACE_NOW); \
253
- } \
254
- span = nullptr; \
252
+ template <typename COMMAND>
253
+ void finish_http_span(lcbtrace_SPAN *span, const COMMAND *cmd)
254
+ {
255
+ if (span != nullptr) {
256
+ span->find_outer_or_this()->add_tag(LCBTRACE_TAG_RETRIES, 0, (uint64_t)cmd->retries());
257
+ if (span->should_finish()) {
258
+ lcbtrace_span_finish(span, LCBTRACE_NOW);
259
+ }
255
260
  }
256
261
  }
257
- #else
258
- #define LCBTRACE_KVSTORE_START(settings, opaque, cmd, operation_name, outspan)
259
- #define LCBTRACE_HTTP_START(settings, opaque, pspan, operation_name, svc, outspan)
260
- #define LCBTRACE_KV_FINISH(pipeline, request, server_duration)
261
- #define LCBTRACE_HTTP_FINISH(span)
262
+
263
+ } // namespace trace
264
+ } // namespace lcb
265
+
266
+ extern "C" {
267
+ #endif /* __cplusplus */
268
+ LCB_INTERNAL_API
269
+ void lcbtrace_span_set_orphaned(lcbtrace_SPAN *span, int val);
270
+
271
+ const char *dur_level_to_string(lcb_DURABILITY_LEVEL dur_level);
272
+ #ifdef __cplusplus
273
+ }
262
274
  #endif /* __cplusplus*/
263
275
  #endif /* LCB_TRACING_INTERNAL_H */
@@ -80,8 +80,8 @@ void lcb_VIEW_HANDLE_::invoke_last(lcb_STATUS err)
80
80
  if (http_response_ && http_response_->ctx.response_code != 200 && http_response_->ctx.body_len) {
81
81
  // chances that were not able to parse response
82
82
  Json::Value meta;
83
- if (Json::Reader().parse(http_response_->ctx.body, http_response_->ctx.body + http_response_->ctx.body_len,
84
- meta)) {
83
+ if (Json::Reader(Json::Features::strictMode())
84
+ .parse(http_response_->ctx.body, http_response_->ctx.body + http_response_->ctx.body_len, meta)) {
85
85
  const Json::Value &error = meta["error"];
86
86
  if (error.isString()) {
87
87
  first_error_code_ = error.asString();
@@ -101,7 +101,10 @@ void lcb_VIEW_HANDLE_::invoke_last(lcb_STATUS err)
101
101
  resp.ctx.rc = LCB_ERR_VIEW_NOT_FOUND;
102
102
  }
103
103
 
104
- LCBTRACE_HTTP_FINISH(span_);
104
+ if (span_ != nullptr) {
105
+ lcb::trace::finish_http_span(span_, this);
106
+ span_ = nullptr;
107
+ }
105
108
  if (http_request_ != nullptr) {
106
109
  http_request_->span = nullptr;
107
110
  }
@@ -379,11 +382,16 @@ lcb_VIEW_HANDLE_::lcb_VIEW_HANDLE_(lcb_INSTANCE *instance, void *cookie, const l
379
382
  document_queue_->max_pending_response = cmd->max_concurrent_documents();
380
383
  }
381
384
  }
385
+ {
386
+ char buf[32];
387
+ size_t nbuf = snprintf(buf, sizeof(buf), "%016" PRIx64, lcb_next_rand64());
388
+ client_context_id_.assign(buf, nbuf);
389
+ }
382
390
 
383
391
  lcb_aspend_add(&instance_->pendops, LCB_PENDTYPE_COUNTER, nullptr);
384
392
  if (instance->settings->tracer) {
385
- LCBTRACE_HTTP_START(instance_->settings, nullptr, cmd->parent_span(), LCBTRACE_TAG_SERVICE_VIEW,
386
- LCBTRACE_THRESHOLD_VIEW, span_);
393
+ parent_span_ = cmd->parent_span();
394
+ span_ = lcb::trace::start_http_span(instance_->settings, this);
387
395
  }
388
396
  last_error_ = request_http(cmd);
389
397
  }
@@ -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, NULL);
67
+ err = lcb_create(&instance, nullptr);
65
68
  ASSERT_EQ(LCB_SUCCESS, err);
66
- ASSERT_FALSE(instance == NULL);
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
- {NULL, 0}};
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);
@@ -556,6 +568,9 @@ void MockEnvironment::SetUp()
556
568
  featureRegistry.insert("replica_read");
557
569
  featureRegistry.insert("lock");
558
570
 
571
+ test_tracer = TestTracer();
572
+ test_meter = TestMeter();
573
+
559
574
  clearAndReset();
560
575
  }
561
576
 
@@ -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"
@@ -451,6 +452,16 @@ class MockEnvironment : public ::testing::Environment
451
452
  std::cerr << std::endl;
452
453
  }
453
454
 
455
+ TestTracer &getTracer()
456
+ {
457
+ return test_tracer;
458
+ }
459
+
460
+ TestMeter &getMeter()
461
+ {
462
+ return test_meter;
463
+ }
464
+
454
465
  explicit MockEnvironment(const char **argv, const std::string &name = "default");
455
466
  ~MockEnvironment() override;
456
467
  void postCreate(lcb_INSTANCE *instance) const;
@@ -478,11 +489,47 @@ class MockEnvironment : public ::testing::Environment
478
489
  std::string userName;
479
490
  const char **argv_{nullptr};
480
491
  void clearAndReset();
492
+ TestTracer test_tracer;
493
+ TestMeter test_meter;
481
494
 
482
495
  private:
483
496
  lcb_INSTANCE *innerClient{nullptr};
484
497
  };
485
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
+
486
533
  #define LCB_TEST_REQUIRE_CLUSTER_VERSION(v) \
487
534
  if (!MockEnvironment::getInstance()->isRealCluster()) { \
488
535
  MockEnvironment::printSkipMessage(__FILE__, __LINE__, "need real cluster"); \