@@ -53,6 +53,8 @@ class Couchbase3Exerciser
5353 [ LibraryMethod ]
5454 public async Task InsertTestDocument ( string scopeName , string collectionName , string documentId , string base64EncodedSerializedDocument )
5555 {
56+ using var logger = new ConsoleLogger ( ) ;
57+
5658 var serializedDocument = System . Text . Encoding . UTF8 . GetString ( Convert . FromBase64String ( base64EncodedSerializedDocument ) ) ;
5759 var document = Newtonsoft . Json . JsonConvert . DeserializeObject ( serializedDocument ) ;
5860
@@ -70,6 +72,8 @@ public async Task InsertTestDocument(string scopeName, string collectionName, st
7072 [ LibraryMethod ]
7173 public async Task RemoveTestDocument ( string scopeName , string collectionName , string documentId )
7274 {
75+ using var logger = new ConsoleLogger ( ) ;
76+
7377 var initResponse = await InitializeAsync ( ) ;
7478 await using var cluster = initResponse . Cluster ;
7579 await using var bucket = initResponse . Bucket ;
@@ -84,6 +88,8 @@ public async Task RemoveTestDocument(string scopeName, string collectionName, st
8488 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
8589 public async Task Get ( string scopeName , string collectionName , string documentId )
8690 {
91+ using var logger = new ConsoleLogger ( ) ;
92+
8793 var initResponse = await InitializeAsync ( ) ;
8894 await using var cluster = initResponse . Cluster ;
8995 await using var bucket = initResponse . Bucket ;
@@ -92,9 +98,12 @@ public async Task Get(string scopeName, string collectionName, string documentId
9298 var collection = await GetCollectionAsync ( bucket , scopeName , collectionName ) ;
9399
94100 // get a document
101+ logger . LogToConsole ( "GetAsync" ) ;
95102 using var getResult1 = await collection . GetAsync ( documentId ) ;
103+ logger . LogToConsole ( "GetAnyReplicaAsync" ) ;
96104 using var getResult2 = await collection . GetAnyReplicaAsync ( documentId ) ;
97105 // for some reason, this fails if one of the previous 2 methods isn't called first.
106+ logger . LogToConsole ( "GetAllReplicasAsync" ) ;
98107 var result = await Task . WhenAll ( collection . GetAllReplicasAsync ( documentId ) ) ;
99108 foreach ( var r in result )
100109 r . Dispose ( ) ;
@@ -105,6 +114,8 @@ public async Task Get(string scopeName, string collectionName, string documentId
105114 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
106115 public async Task GetAndLockAndUnlock ( string scopeName , string collectionName , string documentId )
107116 {
117+ using var logger = new ConsoleLogger ( ) ;
118+
108119 var initResponse = await InitializeAsync ( ) ;
109120 await using var cluster = initResponse . Cluster ;
110121 await using var bucket = initResponse . Bucket ;
@@ -113,17 +124,21 @@ public async Task GetAndLockAndUnlock(string scopeName, string collectionName, s
113124 var collection = await GetCollectionAsync ( bucket , scopeName , collectionName ) ;
114125
115126 // get a document and lock it
127+ logger . LogToConsole ( "GetAndLockAsync" ) ;
116128 using var result = await collection . GetAndLockAsync ( documentId , TimeSpan . FromSeconds ( 10 ) ) ;
117129
118130 // unlock the document
119- await collection . UnlockAsync ( documentId , result . Cas ) ;
131+ logger . LogToConsole ( "UnlockAsync" ) ;
132+ await collection . UnlockAsync ( documentId , result . Cas , options => { options . Timeout ( TimeSpan . FromSeconds ( 15 ) ) ; } ) ;
120133 }
121134
122135 [ LibraryMethod ]
123136 [ Transaction ]
124137 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
125138 public async Task Exists ( string scopeName , string collectionName , string documentId )
126139 {
140+ using var logger = new ConsoleLogger ( ) ;
141+
127142 var initResponse = await InitializeAsync ( ) ;
128143 await using var cluster = initResponse . Cluster ;
129144 await using var bucket = initResponse . Bucket ;
@@ -139,6 +154,8 @@ public async Task Exists(string scopeName, string collectionName, string documen
139154 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
140155 public async Task InsertUpsertReplaceAndRemove ( string scopeName , string collectionName , string documentId , string base64EncodedSerializedInsertDocument , string base64EncodedSerializedUpsertDocument , string base64EncodedSerializedReplaceDocument )
141156 {
157+ using var logger = new ConsoleLogger ( ) ;
158+
142159 var serializedInsertDocument = System . Text . Encoding . UTF8 . GetString ( Convert . FromBase64String ( base64EncodedSerializedInsertDocument ) ) ;
143160 var serializedUpsertDocument = System . Text . Encoding . UTF8 . GetString ( Convert . FromBase64String ( base64EncodedSerializedUpsertDocument ) ) ;
144161 var serializedReplaceDocument = System . Text . Encoding . UTF8 . GetString ( Convert . FromBase64String ( base64EncodedSerializedReplaceDocument ) ) ;
@@ -151,15 +168,19 @@ public async Task InsertUpsertReplaceAndRemove(string scopeName, string collecti
151168 var collection = await GetCollectionAsync ( bucket , scopeName , collectionName ) ;
152169
153170 // insert a document
171+ logger . LogToConsole ( "InsertAsync" ) ;
154172 await collection . InsertAsync ( documentId , JsonConvert . DeserializeObject ( serializedInsertDocument ) ) ;
155173
156174 // upsert a document
175+ logger . LogToConsole ( "UpsertAsync" ) ;
157176 await collection . UpsertAsync ( documentId , JsonConvert . DeserializeObject ( serializedUpsertDocument ) ) ;
158177
159178 // replace a document
179+ logger . LogToConsole ( "ReplaceAsync" ) ;
160180 await collection . ReplaceAsync ( documentId , JsonConvert . DeserializeObject ( serializedReplaceDocument ) ) ;
161181
162182 // delete the document
183+ logger . LogToConsole ( "RemoveAsync" ) ;
163184 await collection . RemoveAsync ( documentId ) ;
164185 }
165186
@@ -168,6 +189,8 @@ public async Task InsertUpsertReplaceAndRemove(string scopeName, string collecti
168189 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
169190 public async Task Mutate ( )
170191 {
192+ using var logger = new ConsoleLogger ( ) ;
193+
171194 var initResponse = await InitializeAsync ( ) ;
172195 await using var cluster = initResponse . Cluster ;
173196 await using var bucket = initResponse . Bucket ;
@@ -189,6 +212,8 @@ await hotelCollection.MutateInAsync("hotel_10025",
189212 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
190213 public async Task Lookup ( string scopeName , string collectionName , string documentId )
191214 {
215+ using var logger = new ConsoleLogger ( ) ;
216+
192217 var initResponse = await InitializeAsync ( ) ;
193218 await using var cluster = initResponse . Cluster ;
194219 await using var bucket = initResponse . Bucket ;
@@ -197,9 +222,12 @@ public async Task Lookup(string scopeName, string collectionName, string documen
197222 var collection = await GetCollectionAsync ( bucket , scopeName , collectionName ) ;
198223
199224 // lookup a document
225+ logger . LogToConsole ( "LookupInAsync" ) ;
200226#if NET481_OR_GREATER || NET
201227 using var result1 = await collection . LookupInAsync ( documentId , [ LookupInSpec . Get ( "credit_cards" ) ] ) ;
228+ logger . LogToConsole ( "LookupInAnyReplicaAsync" ) ;
202229 using var result2 = await collection . LookupInAnyReplicaAsync ( documentId , [ LookupInSpec . Get ( "credit_cards" ) ] ) ;
230+ logger . LogToConsole ( "LookupInAllReplicasAsync" ) ;
203231 var results = collection . LookupInAllReplicasAsync ( documentId , [ LookupInSpec . Get ( "credit_cards" ) ] ) ;
204232 await foreach ( var result in results )
205233 {
@@ -216,7 +244,8 @@ public async Task Lookup(string scopeName, string collectionName, string documen
216244 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
217245 public async Task Scan ( )
218246 {
219- Console . WriteLine ( "Scan : Started" ) ;
247+ using var logger = new ConsoleLogger ( ) ;
248+
220249 var initResponse = await InitializeAsync ( ) ;
221250 await using var cluster = initResponse . Cluster ;
222251 await using var bucket = initResponse . Bucket ;
@@ -226,7 +255,6 @@ public async Task Scan()
226255
227256 // scan the collection - we don't care about processing the result
228257 var _ = collection . ScanAsync ( new RangeScan ( ) ) ;
229- Console . WriteLine ( "Scan : Finished" ) ;
230258 }
231259#endif
232260
@@ -235,6 +263,8 @@ public async Task Scan()
235263 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
236264 public async Task Touch ( )
237265 {
266+ using var logger = new ConsoleLogger ( ) ;
267+
238268 var initResponse = await InitializeAsync ( ) ;
239269 await using var cluster = initResponse . Cluster ;
240270 await using var bucket = initResponse . Bucket ;
@@ -247,9 +277,12 @@ public async Task Touch()
247277 await collection . InsertAsync ( key , new { Name = "Ted" , Age = 32 } ) ;
248278
249279 // update the expiry of a document
280+ logger . LogToConsole ( "GetAndTouchAsync" ) ;
250281 using var getResult3 = await collection . GetAndTouchAsync ( key , TimeSpan . FromSeconds ( 10 ) ) ;
282+ logger . LogToConsole ( "TouchAsync" ) ;
251283 await collection . TouchAsync ( key , TimeSpan . FromSeconds ( 5 ) ) ;
252284#if NET481_OR_GREATER || NET
285+ logger . LogToConsole ( "TouchWithCasAsync" ) ;
253286 await collection . TouchWithCasAsync ( key , TimeSpan . FromSeconds ( 2 ) ) ;
254287#endif
255288 }
@@ -259,6 +292,8 @@ public async Task Touch()
259292 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
260293 public async Task ScopeQuery ( )
261294 {
295+ using var logger = new ConsoleLogger ( ) ;
296+
262297 var initResponse = await InitializeAsync ( ) ;
263298 await using var cluster = initResponse . Cluster ;
264299 await using var bucket = initResponse . Bucket ;
@@ -273,6 +308,8 @@ public async Task ScopeQuery()
273308 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
274309 public async Task ClusterQuery ( )
275310 {
311+ using var logger = new ConsoleLogger ( ) ;
312+
276313 var initResponse = await InitializeAsync ( ) ;
277314 await using var cluster = initResponse . Cluster ;
278315 await using var bucket = initResponse . Bucket ;
@@ -300,6 +337,8 @@ public async Task ClusterQuery()
300337 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
301338 public async Task ScopeSearch ( )
302339 {
340+ using var logger = new ConsoleLogger ( ) ;
341+
303342 var initResponse = await InitializeAsync ( ) ;
304343 await using var cluster = initResponse . Cluster ;
305344 await using var bucket = initResponse . Bucket ;
@@ -314,6 +353,8 @@ public async Task ScopeSearch()
314353 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
315354 public async Task ClusterSearch ( )
316355 {
356+ using var logger = new ConsoleLogger ( ) ;
357+
317358 var initResponse = await InitializeAsync ( ) ;
318359 await using var cluster = initResponse . Cluster ;
319360 await using var bucket = initResponse . Bucket ;
@@ -328,6 +369,8 @@ public async Task ClusterSearch()
328369 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
329370 public async Task ClusterAnalytics ( )
330371 {
372+ using var logger = new ConsoleLogger ( ) ;
373+
331374 var initResponse = await InitializeAsync ( ) ;
332375 await using var cluster = initResponse . Cluster ;
333376 await using var bucket = initResponse . Bucket ;
@@ -340,6 +383,8 @@ public async Task ClusterAnalytics()
340383 [ MethodImpl ( MethodImplOptions . NoOptimization | MethodImplOptions . NoInlining ) ]
341384 public async Task ScopeAnalytics ( )
342385 {
386+ using var logger = new ConsoleLogger ( ) ;
387+
343388 var initResponse = await InitializeAsync ( ) ;
344389 await using var cluster = initResponse . Cluster ;
345390 await using var bucket = initResponse . Bucket ;
@@ -355,6 +400,26 @@ private async Task<ICouchbaseCollection> GetCollectionAsync(IBucket bucket, stri
355400
356401 return await Task . FromResult ( collection ) ;
357402 }
403+ }
404+
405+ public class ConsoleLogger : IDisposable
406+ {
407+ private readonly string _callerMemberName ;
408+
409+ public ConsoleLogger ( [ CallerMemberName ] string callerMemberName = "" )
410+ {
411+ _callerMemberName = callerMemberName ;
358412
413+ LogToConsole ( "Starting" ) ;
414+ }
415+
416+ public void LogToConsole ( string message )
417+ {
418+ Console . WriteLine ( $ "--> { DateTime . Now : yyyy-MM-dd HH:mm:ss,fff} Couchbase3Exerciser.{ _callerMemberName } : { message } ") ;
419+ }
420+ public void Dispose ( )
421+ {
422+ LogToConsole ( "Complete" ) ;
423+ }
359424}
360425#endif
0 commit comments