1616 *
1717 */
1818
19+ use crate :: common:: features:: TestFeatureCode ;
1920use crate :: common:: helpers:: {
20- create_scope, delete_collection, delete_scope, feature_supported, generate_string_value,
21- try_until,
21+ create_scope, delete_collection, delete_scope, generate_string_value, try_until,
2222} ;
2323use crate :: common:: test_config:: run_test;
2424use common:: helpers;
2525use couchbase_core:: agent:: Agent ;
2626use couchbase_core:: cbconfig:: CollectionManifest ;
27- use couchbase_core:: features:: BucketFeature ;
28- use couchbase_core:: mgmtx:: bucket_settings:: { BucketSettings , BucketType } ;
27+ use couchbase_core:: mgmtx:: bucket_settings:: { BucketSettings , BucketType , StorageBackend } ;
2928use couchbase_core:: options:: management:: {
3029 CreateBucketOptions , CreateCollectionOptions , DeleteBucketOptions , EnsureBucketOptions ,
3130 GetBucketOptions , GetCollectionManifestOptions , UpdateBucketOptions ,
@@ -70,14 +69,32 @@ fn test_scopes() {
7069 } ) ;
7170}
7271
72+ #[ serial]
7373#[ test]
74- fn test_collections ( ) {
74+ fn test_collections_history_retention ( ) {
7575 run_test ( async |mut agent| {
76- let history_supported = feature_supported ( & agent, BucketFeature :: NonDedupedHistory ) . await ;
76+ if !agent. supports_feature ( & TestFeatureCode :: HistoryRetention ) {
77+ return ;
78+ }
7779
7880 let scope_name = generate_string_value ( 10 ) ;
7981 let collection_name = generate_string_value ( 10 ) ;
80- let bucket_name = agent. test_setup_config . bucket . clone ( ) ;
82+ let bucket_name = generate_string_value ( 10 ) ;
83+
84+ let settings = BucketSettings :: default ( )
85+ . bucket_type ( BucketType :: COUCHBASE )
86+ . storage_backend ( StorageBackend :: MAGMA )
87+ . history_retention_seconds ( 5 )
88+ . ram_quota_mb ( 1024 ) ;
89+
90+ let opts = & CreateBucketOptions :: new ( & bucket_name, & settings) ;
91+
92+ agent. create_bucket ( opts) . await . unwrap ( ) ;
93+
94+ agent
95+ . ensure_bucket ( & EnsureBucketOptions :: new ( & bucket_name, false ) )
96+ . await
97+ . unwrap ( ) ;
8198
8299 let resp = create_scope ( & agent, & bucket_name, & scope_name)
83100 . await
@@ -86,12 +103,11 @@ fn test_collections() {
86103
87104 helpers:: ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
88105
89- let mut opts =
90- CreateCollectionOptions :: new ( & bucket_name, & scope_name, & collection_name) . max_ttl ( 25 ) ;
91-
92- if history_supported {
93- opts = opts. history_enabled ( true )
94- } ;
106+ let mut opts = CreateCollectionOptions :: new ( & bucket_name, & scope_name, & collection_name)
107+ . history_enabled ( true ) ;
108+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
109+ opts = opts. max_ttl ( 25 ) ;
110+ }
95111
96112 let resp = agent. create_collection ( & opts) . await . unwrap ( ) ;
97113 assert ! ( !resp. manifest_uid. is_empty( ) ) ;
@@ -106,13 +122,80 @@ fn test_collections() {
106122
107123 assert ! ( collection_found. is_some( ) ) ;
108124 let collection_found = collection_found. unwrap ( ) ;
109- assert_eq ! ( collection_found. max_ttl, Some ( 25 ) ) ;
110- if history_supported {
111- assert_eq ! ( collection_found. history, Some ( true ) ) ;
112- } else {
113- // Depending on server version the collection may have inherited the bucket default.
114- assert ! ( collection_found. history. is_none( ) || collection_found. history == Some ( false ) ) ;
125+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
126+ assert_eq ! ( collection_found. max_ttl, Some ( 25 ) ) ;
115127 }
128+ assert_eq ! ( collection_found. history, Some ( true ) ) ;
129+
130+ let resp = delete_collection ( & agent, & bucket_name, & scope_name, & collection_name)
131+ . await
132+ . unwrap ( ) ;
133+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
134+
135+ ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
136+
137+ let manifest = get_manifest ( & agent, & bucket_name) . await . unwrap ( ) ;
138+
139+ let mut scope_found = find_scope ( & manifest, & scope_name) ;
140+ let scope_found = scope_found. unwrap ( ) ;
141+ let mut collection_found = find_collection ( & scope_found, & collection_name) ;
142+ assert ! ( collection_found. is_none( ) ) ;
143+
144+ let resp = delete_scope ( & agent, & bucket_name, & scope_name)
145+ . await
146+ . unwrap ( ) ;
147+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
148+
149+ let _ = agent
150+ . delete_bucket ( & DeleteBucketOptions :: new ( & bucket_name) )
151+ . await ;
152+
153+ // We can't fire and forget the delete, the server will error if we try to update a bucket
154+ // whilst one is being deleted which could fail other tests.
155+ agent
156+ . ensure_bucket ( & EnsureBucketOptions :: new ( & bucket_name, true ) )
157+ . await
158+ . unwrap ( ) ;
159+ } ) ;
160+ }
161+
162+ #[ test]
163+ fn test_collections ( ) {
164+ run_test ( async |mut agent| {
165+ let scope_name = generate_string_value ( 10 ) ;
166+ let collection_name = generate_string_value ( 10 ) ;
167+ let bucket_name = agent. test_setup_config . bucket . clone ( ) ;
168+
169+ let resp = create_scope ( & agent, & bucket_name, & scope_name)
170+ . await
171+ . unwrap ( ) ;
172+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
173+
174+ ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
175+
176+ let mut opts = CreateCollectionOptions :: new ( & bucket_name, & scope_name, & collection_name) ;
177+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
178+ opts = opts. max_ttl ( 25 ) ;
179+ }
180+
181+ let resp = agent. create_collection ( & opts) . await . unwrap ( ) ;
182+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
183+
184+ ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
185+
186+ let manifest = get_manifest ( & agent, & bucket_name) . await . unwrap ( ) ;
187+ assert ! ( !manifest. uid. is_empty( ) ) ;
188+
189+ let scope_found = find_scope ( & manifest, & scope_name) . unwrap ( ) ;
190+ let mut collection_found = find_collection ( & scope_found, & collection_name) ;
191+
192+ assert ! ( collection_found. is_some( ) ) ;
193+ let collection_found = collection_found. unwrap ( ) ;
194+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
195+ assert_eq ! ( collection_found. max_ttl, Some ( 25 ) ) ;
196+ }
197+ // Depending on server version the collection may have inherited the bucket default.
198+ assert ! ( collection_found. history. is_none( ) || collection_found. history == Some ( false ) ) ;
116199
117200 let resp = delete_collection ( & agent, & bucket_name, & scope_name, & collection_name)
118201 . await
@@ -241,9 +324,11 @@ fn test_update_bucket() {
241324 . await
242325 . unwrap ( ) ;
243326
244- let update_settings = BucketSettings :: default ( )
245- . ram_quota_mb ( 200 )
246- . max_ttl ( Duration :: from_secs ( 3600 ) ) ;
327+ let mut update_settings = BucketSettings :: default ( ) . ram_quota_mb ( 200 ) ;
328+
329+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
330+ update_settings = update_settings. max_ttl ( Duration :: from_secs ( 3600 ) ) ;
331+ }
247332
248333 agent
249334 . update_bucket ( & UpdateBucketOptions :: new ( & bucket_name, & update_settings) )
@@ -276,10 +361,13 @@ fn test_update_bucket() {
276361 . unwrap ( ) ;
277362
278363 assert_eq ! ( bucket. bucket_settings. ram_quota_mb, Some ( 200 ) ) ;
279- assert_eq ! (
280- bucket. bucket_settings. max_ttl,
281- Some ( Duration :: from_secs( 3600 ) )
282- ) ;
364+
365+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
366+ assert_eq ! (
367+ bucket. bucket_settings. max_ttl,
368+ Some ( Duration :: from_secs( 3600 ) )
369+ ) ;
370+ }
283371 } ) ;
284372}
285373
0 commit comments