public async Task Teardown() { foreach (var key in _documentsToDelete) { await _collection.RemoveAsync(key); } await _cluster.DisposeAsync(); }
public async ValueTask DisposeAsync() { if (!_disposed) { _disposed = true; await(_cluster?.DisposeAsync() ?? default).ConfigureAwait(false); _cluster = null; } }
public async Task Teardown() { DocumentsToRemove.ForEach(async key => { try { await Collection.RemoveAsync(key); } catch { // if there's an exception throw because that key doesn't exist // that's fine, but there many be others in DocumentsToRemove // so that's why this exception is being swallowed } }); await TestCluster.DisposeAsync(); }
public async Task Teardown() { await Cluster.DisposeAsync(); }
public async ValueTask DisposeAsync() { await Bucket.DisposeAsync().ConfigureAwait(false); await Cluster.DisposeAsync().ConfigureAwait(false); }
static async Task Main(string[] args) { // SETUP: connect to Couchbase _cluster = await Cluster.ConnectAsync( "couchbase://localhost", "Administrator", "password"); _bucket = await _cluster.BucketAsync("matt"); _scope = await _bucket.ScopeAsync("myScope"); _coll = await _scope.CollectionAsync("myCollection"); // SETUP: create a 'conference' document and a 'conference activities' document await SetupInitialDocuments(); // STEP 1: create transactions object var transactions = Transactions.Create(_cluster, TransactionConfigBuilder.Create() .DurabilityLevel(DurabilityLevel.MajorityAndPersistToActive) // since I have 1 node, replication must be 0, or this will throw exception .Build()); Console.WriteLine("Press ENTER to continue"); Console.ReadLine(); // STEP 2: transaction operations await transactions.RunAsync(async (ctx) => { var now = DateTime.Now; // FIRST: get the two document I want to change var confDoc = await ctx.GetAsync(_coll, "dataLove2021"); var actsDoc = await ctx.GetAsync(_coll, "dataLove2021::activities"); var conf = confDoc.ContentAs <Conference>(); var acts = actsDoc.ContentAs <ConferenceActivities>(); // SECOND: add an event to the "activities" document acts.Events.Add(new ConferenceEvent { Type = "CFP", DtActivity = now, Desc = "Submitted to the CFP" }); // acts.Events.Add(new ConferenceEvent // { // Type = "PRESENTATION", // DtActivity = now, // Desc = "Delivered ACID presentation" // }); // acts.Events.Add(new ConferenceEvent // { // Type = "SPATIAL", // DtActivity = now, // Desc = "Answered questions in Spatial Chat" // }); // THIRD: change the "conference" document conf.Followups = (conf.Followups ?? 0) + 1; conf.LastActivity = now; // FOURTH: write the changes await ctx.ReplaceAsync(confDoc, conf); // OPTIONAL STEP: fail right in the middle of the transaction making two writes // var fail = true; // if(fail) throw new Exception("Something went wrong!"); await ctx.ReplaceAsync(actsDoc, acts); // FIFTH: commit (implied) }); await _cluster.DisposeAsync(); }
private async Task DisconnectAsync() { await Bucket.DisposeAsync().ConfigureAwait(false); await Cluster.DisposeAsync().ConfigureAwait(false); }