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
@@ -671,27 +671,54 @@ TEST_F(MutateUnitTest, testSetDefault)
671
671
  lcb_wait(instance, LCB_WAIT_DEFAULT);
672
672
  }
673
673
 
674
+ struct lookup_result {
675
+ bool called{false};
676
+ lcb_STATUS rc{LCB_ERR_GENERIC};
677
+
678
+ lcb_STATUS rc_expiry{LCB_ERR_GENERIC};
679
+ std::uint32_t expiry{0};
680
+
681
+ lcb_STATUS rc_cas{LCB_ERR_GENERIC};
682
+ std::uint64_t cas{0};
683
+ };
684
+
674
685
  static void preserve_expiry_get_expiry(lcb_INSTANCE *, int, const lcb_RESPSUBDOC *resp)
675
686
  {
676
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_respsubdoc_status(resp));
677
- ASSERT_EQ(1, lcb_respsubdoc_result_size(resp));
678
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_respsubdoc_result_status(resp, 0));
687
+ lookup_result *cookie = nullptr;
688
+ lcb_respsubdoc_cookie(resp, reinterpret_cast<void **>(&cookie));
689
+
690
+ cookie->called = true;
691
+ cookie->rc = lcb_respsubdoc_status(resp);
692
+ ASSERT_EQ(2, lcb_respsubdoc_result_size(resp));
679
693
 
680
694
  const char *value = nullptr;
681
695
  std::size_t value_len = 0;
682
- lcb_respsubdoc_result_value(resp, 0, &value, &value_len);
696
+
697
+ cookie->rc_expiry = lcb_respsubdoc_result_status(resp, 0);
698
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_respsubdoc_result_value(resp, 0, &value, &value_len));
683
699
  ASSERT_GT(value_len, 0);
700
+ cookie->expiry = std::strtoul(value, nullptr, 10);
684
701
 
685
- std::uint32_t *cookie = nullptr;
686
- lcb_respsubdoc_cookie(resp, reinterpret_cast<void **>(&cookie));
687
- *cookie = std::strtoul(value, nullptr, 10);
702
+ cookie->rc_cas = lcb_respsubdoc_result_status(resp, 1);
703
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_respsubdoc_result_value(resp, 1, &value, &value_len));
704
+ // CAS is encoded as string of HEX number, so the length should be at least greater than strlen("\"0x\"")
705
+ ASSERT_GT(value_len, 4);
706
+ cookie->cas = std::strtoull(value + 1, nullptr, 16);
688
707
  }
689
708
 
709
+ struct store_result {
710
+ bool called{false};
711
+ lcb_STATUS rc{LCB_ERR_GENERIC};
712
+ std::uint64_t cas{0};
713
+ };
714
+
690
715
  static void preserve_expiry_upsert(lcb_INSTANCE *, int, const lcb_RESPSTORE *resp)
691
716
  {
692
- lcb_STATUS *rc;
693
- lcb_respstore_cookie(resp, (void **)&rc);
694
- *rc = lcb_respstore_status(resp);
717
+ store_result *res = nullptr;
718
+ lcb_respstore_cookie(resp, (void **)&res);
719
+ res->called = true;
720
+ res->rc = lcb_respstore_status(resp);
721
+ lcb_respstore_cas(resp, &res->cas);
695
722
  }
696
723
 
697
724
  TEST_F(MutateUnitTest, testUpsertPreservesExpiry)
@@ -709,6 +736,7 @@ TEST_F(MutateUnitTest, testUpsertPreservesExpiry)
709
736
  lcb_install_callback(instance, LCB_CALLBACK_STORE, reinterpret_cast<lcb_RESPCALLBACK>(preserve_expiry_upsert));
710
737
 
711
738
  std::uint32_t birthday = 1878422400;
739
+ std::uint64_t cas = 0;
712
740
 
713
741
  {
714
742
  std::string value = R"({"foo": "bar"})";
@@ -718,64 +746,83 @@ TEST_F(MutateUnitTest, testUpsertPreservesExpiry)
718
746
  lcb_cmdstore_key(cmd, key.c_str(), key.size());
719
747
  lcb_cmdstore_value(cmd, value.c_str(), value.size());
720
748
  lcb_cmdstore_expiry(cmd, birthday);
721
- lcb_STATUS cookie = LCB_ERR_GENERIC;
722
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &cookie, cmd));
749
+ store_result res{};
750
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &res, cmd));
723
751
  lcb_cmdstore_destroy(cmd);
724
752
  lcb_wait(instance, LCB_WAIT_DEFAULT);
725
- ASSERT_STATUS_EQ(LCB_SUCCESS, cookie);
753
+ ASSERT_TRUE(res.called);
754
+ ASSERT_NE(0, res.cas);
755
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
756
+ cas = res.cas;
726
757
  }
727
758
 
728
759
  std::string expiry_path = "$document.exptime";
760
+ std::string cas_path = "$document.CAS";
729
761
 
730
762
  {
731
- std::uint32_t expiry = 0;
763
+ lookup_result res{};
732
764
 
733
765
  lcb_CMDSUBDOC *cmd;
734
766
  lcb_cmdsubdoc_create(&cmd);
735
767
  lcb_cmdsubdoc_key(cmd, key.data(), key.size());
736
768
  lcb_SUBDOCSPECS *ops;
737
- lcb_subdocspecs_create(&ops, 1);
769
+ lcb_subdocspecs_create(&ops, 2);
738
770
  lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(), expiry_path.size());
771
+ lcb_subdocspecs_get(ops, 1, LCB_SUBDOCSPECS_F_XATTRPATH, cas_path.c_str(), cas_path.size());
739
772
  lcb_cmdsubdoc_specs(cmd, ops);
740
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &expiry, cmd));
773
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
741
774
  lcb_subdocspecs_destroy(ops);
742
775
  lcb_cmdsubdoc_destroy(cmd);
743
776
  lcb_wait(instance, LCB_WAIT_DEFAULT);
744
777
 
745
- ASSERT_EQ(expiry, birthday);
778
+ ASSERT_TRUE(res.called);
779
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
780
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_cas);
781
+ ASSERT_EQ(cas, res.cas);
782
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_expiry);
783
+ ASSERT_EQ(birthday, res.expiry);
746
784
  }
747
785
 
748
786
  {
749
787
  std::string value = R"({"foo": "baz"})";
788
+ store_result res{};
750
789
 
751
790
  lcb_CMDSTORE *cmd;
752
791
  lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
753
792
  lcb_cmdstore_key(cmd, key.c_str(), key.size());
754
793
  lcb_cmdstore_value(cmd, value.c_str(), value.size());
755
794
  lcb_cmdstore_preserve_expiry(cmd, true);
756
- lcb_STATUS cookie = LCB_ERR_GENERIC;
757
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &cookie, cmd));
795
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &res, cmd));
758
796
  lcb_cmdstore_destroy(cmd);
759
797
  lcb_wait(instance, LCB_WAIT_DEFAULT);
760
- ASSERT_STATUS_EQ(LCB_SUCCESS, cookie);
798
+ ASSERT_TRUE(res.called);
799
+ ASSERT_NE(0, res.cas);
800
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
801
+ cas = res.cas;
761
802
  }
762
803
 
763
804
  {
764
- std::uint32_t expiry = 0;
805
+ lookup_result res{};
765
806
 
766
807
  lcb_CMDSUBDOC *cmd;
767
808
  lcb_cmdsubdoc_create(&cmd);
768
809
  lcb_cmdsubdoc_key(cmd, key.data(), key.size());
769
810
  lcb_SUBDOCSPECS *ops;
770
- lcb_subdocspecs_create(&ops, 1);
811
+ lcb_subdocspecs_create(&ops, 2);
771
812
  lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(), expiry_path.size());
813
+ lcb_subdocspecs_get(ops, 1, LCB_SUBDOCSPECS_F_XATTRPATH, cas_path.c_str(), cas_path.size());
772
814
  lcb_cmdsubdoc_specs(cmd, ops);
773
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &expiry, cmd));
815
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
774
816
  lcb_subdocspecs_destroy(ops);
775
817
  lcb_cmdsubdoc_destroy(cmd);
776
818
  lcb_wait(instance, LCB_WAIT_DEFAULT);
777
819
 
778
- ASSERT_EQ(expiry, birthday);
820
+ ASSERT_TRUE(res.called);
821
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
822
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_cas);
823
+ ASSERT_EQ(cas, res.cas);
824
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_expiry);
825
+ ASSERT_EQ(birthday, res.expiry);
779
826
  }
780
827
 
781
828
  {
@@ -785,37 +832,50 @@ TEST_F(MutateUnitTest, testUpsertPreservesExpiry)
785
832
  lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
786
833
  lcb_cmdstore_key(cmd, key.c_str(), key.size());
787
834
  lcb_cmdstore_value(cmd, value.c_str(), value.size());
788
- lcb_STATUS cookie = LCB_ERR_GENERIC;
789
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &cookie, cmd));
835
+ store_result res{};
836
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &res, cmd));
790
837
  lcb_cmdstore_destroy(cmd);
791
838
  lcb_wait(instance, LCB_WAIT_DEFAULT);
792
- ASSERT_STATUS_EQ(LCB_SUCCESS, cookie);
839
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
840
+
841
+ ASSERT_TRUE(res.called);
842
+ ASSERT_NE(0, res.cas);
843
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
844
+ cas = res.cas;
793
845
  }
794
846
 
795
847
  {
796
- std::uint32_t expiry = 0;
848
+ lookup_result res{};
797
849
 
798
850
  lcb_CMDSUBDOC *cmd;
799
851
  lcb_cmdsubdoc_create(&cmd);
800
852
  lcb_cmdsubdoc_key(cmd, key.data(), key.size());
801
853
  lcb_SUBDOCSPECS *ops;
802
- lcb_subdocspecs_create(&ops, 1);
854
+ lcb_subdocspecs_create(&ops, 2);
803
855
  lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(), expiry_path.size());
856
+ lcb_subdocspecs_get(ops, 1, LCB_SUBDOCSPECS_F_XATTRPATH, cas_path.c_str(), cas_path.size());
804
857
  lcb_cmdsubdoc_specs(cmd, ops);
805
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &expiry, cmd));
858
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
806
859
  lcb_subdocspecs_destroy(ops);
807
860
  lcb_cmdsubdoc_destroy(cmd);
808
861
  lcb_wait(instance, LCB_WAIT_DEFAULT);
809
862
 
810
- ASSERT_EQ(expiry, 0);
863
+ ASSERT_TRUE(res.called);
864
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
865
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_cas);
866
+ ASSERT_EQ(cas, res.cas);
867
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_expiry);
868
+ ASSERT_EQ(0, res.expiry);
811
869
  }
812
870
  }
813
871
 
814
872
  static void preserve_expiry_subdoc(lcb_INSTANCE *, int, const lcb_RESPSUBDOC *resp)
815
873
  {
816
- lcb_STATUS *rc;
817
- lcb_respsubdoc_cookie(resp, (void **)&rc);
818
- *rc = lcb_respsubdoc_status(resp);
874
+ store_result *res = nullptr;
875
+ lcb_respsubdoc_cookie(resp, (void **)&res);
876
+ res->called = true;
877
+ res->rc = lcb_respsubdoc_status(resp);
878
+ lcb_respsubdoc_cas(resp, &res->cas);
819
879
  }
820
880
 
821
881
  TEST_F(MutateUnitTest, testMutateInPreservesExpiry)
@@ -834,83 +894,108 @@ TEST_F(MutateUnitTest, testMutateInPreservesExpiry)
834
894
  lcb_install_callback(instance, LCB_CALLBACK_STORE, reinterpret_cast<lcb_RESPCALLBACK>(preserve_expiry_upsert));
835
895
 
836
896
  std::uint32_t birthday = 1878422400;
897
+ std::uint64_t cas = 0;
837
898
 
838
899
  {
900
+ store_result res{};
839
901
  std::string value = R"({"foo": "bar"})";
840
902
 
841
903
  lcb_CMDSTORE *cmd;
842
904
  lcb_cmdstore_create(&cmd, LCB_STORE_UPSERT);
843
- lcb_cmdstore_key(cmd, key.c_str(), key.size());
844
- lcb_cmdstore_value(cmd, value.c_str(), value.size());
845
- lcb_cmdstore_expiry(cmd, birthday);
846
- lcb_STATUS cookie = LCB_ERR_GENERIC;
847
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &cookie, cmd));
905
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdstore_key(cmd, key.c_str(), key.size()));
906
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdstore_value(cmd, value.c_str(), value.size()));
907
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdstore_expiry(cmd, birthday));
908
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_store(instance, &res, cmd));
848
909
  lcb_cmdstore_destroy(cmd);
849
910
  lcb_wait(instance, LCB_WAIT_DEFAULT);
850
- ASSERT_STATUS_EQ(LCB_SUCCESS, cookie);
911
+ ASSERT_TRUE(res.called);
912
+ ASSERT_NE(0, res.cas);
913
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
914
+ cas = res.cas;
851
915
  }
852
916
 
853
917
  std::string expiry_path = "$document.exptime";
918
+ std::string cas_path = "$document.CAS";
854
919
 
855
920
  {
856
- std::uint32_t expiry = 0;
921
+ lookup_result res{};
857
922
 
858
923
  lcb_CMDSUBDOC *cmd;
859
924
  lcb_cmdsubdoc_create(&cmd);
860
925
  lcb_cmdsubdoc_key(cmd, key.data(), key.size());
861
926
  lcb_SUBDOCSPECS *ops;
862
- lcb_subdocspecs_create(&ops, 1);
863
- lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(), expiry_path.size());
864
- lcb_cmdsubdoc_specs(cmd, ops);
865
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &expiry, cmd));
927
+ lcb_subdocspecs_create(&ops, 2);
928
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(),
929
+ expiry_path.size()));
930
+ ASSERT_STATUS_EQ(LCB_SUCCESS,
931
+ lcb_subdocspecs_get(ops, 1, LCB_SUBDOCSPECS_F_XATTRPATH, cas_path.c_str(), cas_path.size()));
932
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdsubdoc_specs(cmd, ops));
933
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
866
934
  lcb_subdocspecs_destroy(ops);
867
935
  lcb_cmdsubdoc_destroy(cmd);
868
936
  lcb_wait(instance, LCB_WAIT_DEFAULT);
869
937
 
870
- ASSERT_EQ(expiry, birthday);
938
+ ASSERT_TRUE(res.called);
939
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
940
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_cas);
941
+ ASSERT_EQ(cas, res.cas);
942
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_expiry);
943
+ ASSERT_EQ(birthday, res.expiry);
871
944
  }
872
945
 
873
946
  {
874
947
  std::string path = "foo";
875
948
  std::string value = R"("baz")";
949
+ store_result res{};
876
950
 
877
951
  lcb_CMDSUBDOC *cmd;
878
952
  lcb_cmdsubdoc_create(&cmd);
879
953
  lcb_cmdsubdoc_key(cmd, key.data(), key.size());
880
954
  lcb_SUBDOCSPECS *ops;
881
955
  lcb_subdocspecs_create(&ops, 1);
882
- lcb_subdocspecs_replace(ops, 0, 0, path.c_str(), path.size(), value.c_str(), value.size());
883
- lcb_cmdsubdoc_specs(cmd, ops);
884
- lcb_cmdsubdoc_preserve_expiry(cmd, true);
885
- lcb_STATUS cookie = LCB_ERR_GENERIC;
886
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &cookie, cmd));
956
+ ASSERT_STATUS_EQ(LCB_SUCCESS,
957
+ lcb_subdocspecs_replace(ops, 0, 0, path.c_str(), path.size(), value.c_str(), value.size()));
958
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdsubdoc_specs(cmd, ops));
959
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_cmdsubdoc_preserve_expiry(cmd, true));
960
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
887
961
  lcb_subdocspecs_destroy(ops);
888
962
  lcb_cmdsubdoc_destroy(cmd);
889
963
  lcb_wait(instance, LCB_WAIT_DEFAULT);
890
- ASSERT_STATUS_EQ(LCB_SUCCESS, cookie);
964
+
965
+ ASSERT_TRUE(res.called);
966
+ ASSERT_NE(0, res.cas);
967
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
968
+ cas = res.cas;
891
969
  }
892
970
 
893
971
  {
894
- std::uint32_t expiry = 0;
972
+ lookup_result res{};
895
973
 
896
974
  lcb_CMDSUBDOC *cmd;
897
975
  lcb_cmdsubdoc_create(&cmd);
898
976
  lcb_cmdsubdoc_key(cmd, key.data(), key.size());
899
977
  lcb_SUBDOCSPECS *ops;
900
- lcb_subdocspecs_create(&ops, 1);
978
+ lcb_subdocspecs_create(&ops, 2);
901
979
  lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(), expiry_path.size());
980
+ lcb_subdocspecs_get(ops, 1, LCB_SUBDOCSPECS_F_XATTRPATH, cas_path.c_str(), cas_path.size());
902
981
  lcb_cmdsubdoc_specs(cmd, ops);
903
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &expiry, cmd));
982
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
904
983
  lcb_subdocspecs_destroy(ops);
905
984
  lcb_cmdsubdoc_destroy(cmd);
906
985
  lcb_wait(instance, LCB_WAIT_DEFAULT);
907
986
 
908
- ASSERT_EQ(expiry, birthday);
987
+ ASSERT_TRUE(res.called);
988
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
989
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_cas);
990
+ ASSERT_EQ(cas, res.cas);
991
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_expiry);
992
+ ASSERT_EQ(birthday, res.expiry);
909
993
  }
910
994
 
911
995
  {
912
996
  std::string path = "foo";
913
997
  std::string value = R"("bar")";
998
+ store_result res{};
914
999
 
915
1000
  lcb_CMDSUBDOC *cmd;
916
1001
  lcb_cmdsubdoc_create(&cmd);
@@ -919,29 +1004,38 @@ TEST_F(MutateUnitTest, testMutateInPreservesExpiry)
919
1004
  lcb_subdocspecs_create(&ops, 1);
920
1005
  lcb_subdocspecs_replace(ops, 0, 0, path.c_str(), path.size(), value.c_str(), value.size());
921
1006
  lcb_cmdsubdoc_specs(cmd, ops);
922
- lcb_STATUS cookie = LCB_ERR_GENERIC;
923
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &cookie, cmd));
1007
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
924
1008
  lcb_subdocspecs_destroy(ops);
925
1009
  lcb_cmdsubdoc_destroy(cmd);
926
1010
  lcb_wait(instance, LCB_WAIT_DEFAULT);
927
- ASSERT_STATUS_EQ(LCB_SUCCESS, cookie);
1011
+
1012
+ ASSERT_TRUE(res.called);
1013
+ ASSERT_NE(0, res.cas);
1014
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
1015
+ cas = res.cas;
928
1016
  }
929
1017
 
930
1018
  {
931
- std::uint32_t expiry = 0;
1019
+ lookup_result res{};
932
1020
 
933
1021
  lcb_CMDSUBDOC *cmd;
934
1022
  lcb_cmdsubdoc_create(&cmd);
935
1023
  lcb_cmdsubdoc_key(cmd, key.data(), key.size());
936
1024
  lcb_SUBDOCSPECS *ops;
937
- lcb_subdocspecs_create(&ops, 1);
1025
+ lcb_subdocspecs_create(&ops, 2);
938
1026
  lcb_subdocspecs_get(ops, 0, LCB_SUBDOCSPECS_F_XATTRPATH, expiry_path.c_str(), expiry_path.size());
1027
+ lcb_subdocspecs_get(ops, 1, LCB_SUBDOCSPECS_F_XATTRPATH, cas_path.c_str(), cas_path.size());
939
1028
  lcb_cmdsubdoc_specs(cmd, ops);
940
- ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &expiry, cmd));
1029
+ ASSERT_STATUS_EQ(LCB_SUCCESS, lcb_subdoc(instance, &res, cmd));
941
1030
  lcb_subdocspecs_destroy(ops);
942
1031
  lcb_cmdsubdoc_destroy(cmd);
943
1032
  lcb_wait(instance, LCB_WAIT_DEFAULT);
944
1033
 
945
- ASSERT_EQ(expiry, 0);
1034
+ ASSERT_TRUE(res.called);
1035
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc);
1036
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_cas);
1037
+ ASSERT_EQ(cas, res.cas);
1038
+ ASSERT_STATUS_EQ(LCB_SUCCESS, res.rc_expiry);
1039
+ ASSERT_EQ(0, res.expiry);
946
1040
  }
947
1041
  }