Пример #1
0
        public async Task Upsert_With_PreserveTtl(bool preserveTtl)
        {
            var docId      = "UpsertTests.Upsert_With_PreserveTtl";
            var collection = await _fixture.GetDefaultCollectionAsync();

            await using var docDisposer = DisposeCleaner.RemoveDocument(collection, docId, _outputHelper);
            await collection.InsertAsync(docId, new { Bar = "Foo" },
                                         options => { options.Expiry(TimeSpan.FromMinutes(1)); });

            var result =
                await collection.UpsertAsync(docId, new { Foo = "Bar" }, new UpsertOptions().PreserveTtl(preserveTtl));

            Assert.True(result.Cas > 0);
        }
Пример #2
0
        public async Task MutateInTests_With_PreserveTtl(bool preserveTtl)
        {
            var docId      = "MutateInTests.MutateIn_With_PreserveTtl";
            var collection = await _fixture.GetDefaultCollectionAsync();

            await using var docDisposer = DisposeCleaner.RemoveDocument(collection, docId, _outputHelper);
            await collection.InsertAsync(docId, new { Bar = "Foo" }, options => options.Expiry(TimeSpan.FromMinutes(1)));

            var result =
                await collection.MutateInAsync(docId, builder => builder.Insert("Foo", "Bar", true),
                                               options => { options.PreserveTtl(preserveTtl); });

            Assert.True(result.Cas > 0);
        }
Пример #3
0
        public async Task Test_Collections_DataverseCollectionQuery()
        {
            var cluster = await _fixture.GetCluster().ConfigureAwait(false);

            var bucket = await _fixture.Cluster.BucketAsync("default").ConfigureAwait(false);

            var dataverseName     = bucket.Name + "." + ScopeName;
            var collectionManager = (CollectionManager)bucket.Collections;
            var analytics         = cluster.AnalyticsIndexes;

            try
            {
                await using var dataverseDisposer = DisposeCleaner.DropDataverseOnDispose(analytics, dataverseName, _output);
                await collectionManager.CreateScopeAsync(ScopeName).ConfigureAwait(false);

                await using var scopeDispose = DisposeCleaner.DropScopeOnDispose(collectionManager, ScopeName, _output);
                var collectionSpec = new CollectionSpec(ScopeName, CollectionName);

                await Task.Delay(TimeSpan.FromSeconds(1));

                await collectionManager.CreateCollectionAsync(collectionSpec).ConfigureAwait(false);

                await Task.Delay(TimeSpan.FromSeconds(1));

                var collectionExistsResult =
                    await collectionManager.CollectionExistsAsync(collectionSpec).ConfigureAwait(false);

                Assert.True(collectionExistsResult);

                await bucket.Scope(ScopeName).Collection(CollectionName).UpsertAsync("KEY1", new { bar = "foo" });

                await analytics.CreateDataverseAsync(dataverseName).ConfigureAwait(false);

                await Task.Delay(TimeSpan.FromSeconds(5));

                var statement = $"CREATE ANALYTICS COLLECTION {FilteredCollection} ON {bucket.Name}.{ScopeName}.{CollectionName}";
                await cluster.AnalyticsQueryAsync <TestRequest>(statement).ConfigureAwait(false);

                await using var analyticsCollectionDisposer = new DisposeCleanerAsync(() =>
                                                                                      cluster.AnalyticsQueryAsync <dynamic>($"DROP ANALYTICS COLLECTION {FilteredCollection}"),
                                                                                      _output
                                                                                      );

                await Task.Delay(TimeSpan.FromSeconds(5));

                var selectStatement  = $"SELECT * FROM `{FilteredCollection}`";
                var analyticsResult2 = await cluster.AnalyticsQueryAsync <TestRequest>(selectStatement).ConfigureAwait(false);

                var result = await analyticsResult2.ToListAsync().ConfigureAwait(false);

                Assert.True(result.Any());
            }
            catch (Exception e)
            {
                _output.WriteLine("oops{0}", e);
            }
            finally
            {
                // give some time befor the cleanups happen.
                await Task.Delay(TimeSpan.FromSeconds(1));
            }
        }