public async Task BatchItemTimeToLiveAsync()
        {
            // Verify with schematized containers where we are allowed to send TTL as a header
            const bool isSchematized = true;
            const bool isStream      = true;
            Container  container     = BatchTestBase.SchematizedContainer;

            await this.CreateSchematizedTestDocsAsync(container);

            {
                TestDoc testDocToCreate        = BatchTestBase.PopulateTestDoc(this.PartitionKey1);
                TestDoc anotherTestDocToCreate = BatchTestBase.PopulateTestDoc(this.PartitionKey1);

                TestDoc testDocToReplace = this.GetTestDocCopy(this.TestDocPk1ExistingA);
                testDocToReplace.Cost++;

                const int ttlInSeconds = 3;
                const int infiniteTtl  = -1;

                TestDoc testDocToUpsert = await BatchTestBase.CreateSchematizedTestDocAsync(container, this.PartitionKey1, ttlInSeconds : ttlInSeconds);

                testDocToUpsert.Cost++;

                BatchCore batch = (BatchCore)(new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
                                              .CreateItemStream(
                                                  BatchTestBase.TestDocToStream(testDocToCreate, isSchematized),
                                                  BatchTestBase.GetBatchItemRequestOptions(testDocToCreate, isSchematized, ttlInSeconds: ttlInSeconds))
                                              .CreateItemStream(
                                                  BatchTestBase.TestDocToStream(anotherTestDocToCreate, isSchematized),
                                                  BatchTestBase.GetBatchItemRequestOptions(anotherTestDocToCreate, isSchematized))
                                              .ReplaceItemStream(
                                                  BatchTestBase.GetId(testDocToReplace, isSchematized),
                                                  BatchTestBase.TestDocToStream(testDocToReplace, isSchematized),
                                                  BatchTestBase.GetBatchItemRequestOptions(testDocToReplace, isSchematized, ttlInSeconds: ttlInSeconds))
                                              .UpsertItemStream(
                                                  BatchTestBase.TestDocToStream(testDocToUpsert, isSchematized),
                                                  BatchTestBase.GetBatchItemRequestOptions(testDocToUpsert, isSchematized, ttlInSeconds: infiniteTtl)));

                TransactionalBatchResponse batchResponse = await batch.ExecuteAsync(BatchTestBase.GetUpdatedBatchRequestOptions(isSchematized: true));

                BatchSinglePartitionKeyTests.VerifyBatchProcessed(batchResponse, numberOfOperations: 4);

                Assert.AreEqual(HttpStatusCode.Created, batchResponse[0].StatusCode);
                Assert.AreEqual(HttpStatusCode.Created, batchResponse[1].StatusCode);
                Assert.AreEqual(HttpStatusCode.OK, batchResponse[2].StatusCode);
                Assert.AreEqual(HttpStatusCode.OK, batchResponse[3].StatusCode);

                // wait for TTL to expire
                await Task.Delay(TimeSpan.FromSeconds(ttlInSeconds + 1));

                await BatchTestBase.VerifyNotFoundAsync(container, testDocToCreate, isSchematized);

                await BatchTestBase.VerifyByReadAsync(container, anotherTestDocToCreate, isStream, isSchematized);

                await BatchTestBase.VerifyNotFoundAsync(container, testDocToReplace, isSchematized);

                await BatchTestBase.VerifyByReadAsync(container, testDocToUpsert, isStream, isSchematized);
            }
        }
예제 #2
0
        protected virtual async Task CreateSchematizedTestDocsAsync(Container container)
        {
            this.TestDocPk1ExistingA = await BatchTestBase.CreateSchematizedTestDocAsync(container, this.PartitionKey1);

            this.TestDocPk1ExistingB = await BatchTestBase.CreateSchematizedTestDocAsync(container, this.PartitionKey1);

            this.TestDocPk1ExistingC = await BatchTestBase.CreateSchematizedTestDocAsync(container, this.PartitionKey1);

            this.TestDocPk1ExistingD = await BatchTestBase.CreateSchematizedTestDocAsync(container, this.PartitionKey1);
        }