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+ create_scope, delete_collection, delete_scope, ensure_manifest , generate_string_value,
2122 try_until,
2223} ;
2324use crate :: common:: test_config:: run_test;
2425use common:: helpers;
2526use couchbase_core:: agent:: Agent ;
2627use couchbase_core:: cbconfig:: CollectionManifest ;
27- use couchbase_core:: features:: BucketFeature ;
28- use couchbase_core:: mgmtx:: bucket_settings:: { BucketSettings , BucketType } ;
28+ use couchbase_core:: mgmtx:: bucket_settings:: { BucketSettings , BucketType , StorageBackend } ;
2929use couchbase_core:: options:: management:: {
3030 CreateBucketOptions , CreateCollectionOptions , DeleteBucketOptions , EnsureBucketOptions ,
3131 GetBucketOptions , GetCollectionManifestOptions , UpdateBucketOptions ,
@@ -70,14 +70,32 @@ fn test_scopes() {
7070 } ) ;
7171}
7272
73+ #[ serial]
7374#[ test]
74- fn test_collections ( ) {
75+ fn test_collections_history_retention ( ) {
7576 run_test ( async |mut agent| {
76- let history_supported = feature_supported ( & agent, BucketFeature :: NonDedupedHistory ) . await ;
77+ if !agent. supports_feature ( & TestFeatureCode :: HistoryRetention ) {
78+ return ;
79+ }
7780
7881 let scope_name = generate_string_value ( 10 ) ;
7982 let collection_name = generate_string_value ( 10 ) ;
80- let bucket_name = agent. test_setup_config . bucket . clone ( ) ;
83+ let bucket_name = generate_string_value ( 10 ) ;
84+
85+ let settings = BucketSettings :: default ( )
86+ . bucket_type ( BucketType :: COUCHBASE )
87+ . storage_backend ( StorageBackend :: MAGMA )
88+ . history_retention_seconds ( 5 )
89+ . ram_quota_mb ( 1024 ) ;
90+
91+ let opts = & CreateBucketOptions :: new ( & bucket_name, & settings) ;
92+
93+ agent. create_bucket ( opts) . await . unwrap ( ) ;
94+
95+ agent
96+ . ensure_bucket ( & EnsureBucketOptions :: new ( & bucket_name, false ) )
97+ . await
98+ . unwrap ( ) ;
8199
82100 let resp = create_scope ( & agent, & bucket_name, & scope_name)
83101 . await
@@ -86,12 +104,11 @@ fn test_collections() {
86104
87105 helpers:: ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
88106
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- } ;
107+ let mut opts = CreateCollectionOptions :: new ( & bucket_name, & scope_name, & collection_name)
108+ . history_enabled ( true ) ;
109+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
110+ opts = opts. max_ttl ( 25 ) ;
111+ }
95112
96113 let resp = agent. create_collection ( & opts) . await . unwrap ( ) ;
97114 assert ! ( !resp. manifest_uid. is_empty( ) ) ;
@@ -106,13 +123,80 @@ fn test_collections() {
106123
107124 assert ! ( collection_found. is_some( ) ) ;
108125 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 ) ) ;
126+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
127+ assert_eq ! ( collection_found. max_ttl, Some ( 25 ) ) ;
115128 }
129+ assert_eq ! ( collection_found. history, Some ( true ) ) ;
130+
131+ let resp = delete_collection ( & agent, & bucket_name, & scope_name, & collection_name)
132+ . await
133+ . unwrap ( ) ;
134+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
135+
136+ ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
137+
138+ let manifest = get_manifest ( & agent, & bucket_name) . await . unwrap ( ) ;
139+
140+ let mut scope_found = find_scope ( & manifest, & scope_name) ;
141+ let scope_found = scope_found. unwrap ( ) ;
142+ let mut collection_found = find_collection ( & scope_found, & collection_name) ;
143+ assert ! ( collection_found. is_none( ) ) ;
144+
145+ let resp = delete_scope ( & agent, & bucket_name, & scope_name)
146+ . await
147+ . unwrap ( ) ;
148+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
149+
150+ let _ = agent
151+ . delete_bucket ( & DeleteBucketOptions :: new ( & bucket_name) )
152+ . await ;
153+
154+ // We can't fire and forget the delete, the server will error if we try to update a bucket
155+ // whilst one is being deleted which could fail other tests.
156+ agent
157+ . ensure_bucket ( & EnsureBucketOptions :: new ( & bucket_name, true ) )
158+ . await
159+ . unwrap ( ) ;
160+ } ) ;
161+ }
162+
163+ #[ test]
164+ fn test_collections ( ) {
165+ run_test ( async |mut agent| {
166+ let scope_name = generate_string_value ( 10 ) ;
167+ let collection_name = generate_string_value ( 10 ) ;
168+ let bucket_name = agent. test_setup_config . bucket . clone ( ) ;
169+
170+ let resp = create_scope ( & agent, & bucket_name, & scope_name)
171+ . await
172+ . unwrap ( ) ;
173+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
174+
175+ ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
176+
177+ let mut opts = CreateCollectionOptions :: new ( & bucket_name, & scope_name, & collection_name) ;
178+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
179+ opts = opts. max_ttl ( 25 ) ;
180+ }
181+
182+ let resp = agent. create_collection ( & opts) . await . unwrap ( ) ;
183+ assert ! ( !resp. manifest_uid. is_empty( ) ) ;
184+
185+ ensure_manifest ( & agent, & bucket_name, resp. manifest_uid ) . await ;
186+
187+ let manifest = get_manifest ( & agent, & bucket_name) . await . unwrap ( ) ;
188+ assert ! ( !manifest. uid. is_empty( ) ) ;
189+
190+ let scope_found = find_scope ( & manifest, & scope_name) . unwrap ( ) ;
191+ let mut collection_found = find_collection ( & scope_found, & collection_name) ;
192+
193+ assert ! ( collection_found. is_some( ) ) ;
194+ let collection_found = collection_found. unwrap ( ) ;
195+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
196+ assert_eq ! ( collection_found. max_ttl, Some ( 25 ) ) ;
197+ }
198+ // Depending on server version the collection may have inherited the bucket default.
199+ assert ! ( collection_found. history. is_none( ) || collection_found. history == Some ( false ) ) ;
116200
117201 let resp = delete_collection ( & agent, & bucket_name, & scope_name, & collection_name)
118202 . await
@@ -241,9 +325,11 @@ fn test_update_bucket() {
241325 . await
242326 . unwrap ( ) ;
243327
244- let update_settings = BucketSettings :: default ( )
245- . ram_quota_mb ( 200 )
246- . max_ttl ( Duration :: from_secs ( 3600 ) ) ;
328+ let mut update_settings = BucketSettings :: default ( ) . ram_quota_mb ( 200 ) ;
329+
330+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
331+ update_settings = update_settings. max_ttl ( Duration :: from_secs ( 3600 ) ) ;
332+ }
247333
248334 agent
249335 . update_bucket ( & UpdateBucketOptions :: new ( & bucket_name, & update_settings) )
@@ -276,10 +362,13 @@ fn test_update_bucket() {
276362 . unwrap ( ) ;
277363
278364 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- ) ;
365+
366+ if agent. supports_feature ( & TestFeatureCode :: CollectionMaxExpiry ) {
367+ assert_eq ! (
368+ bucket. bucket_settings. max_ttl,
369+ Some ( Duration :: from_secs( 3600 ) )
370+ ) ;
371+ }
283372 } ) ;
284373}
285374
0 commit comments