Пример #1
0
 private async Task <IDocumentQueryExecutionContext> CreateDocumentQueryExecutionContextAsync(bool isContinuationExpected, CancellationToken cancellationToken)
 {
     return(await DocumentQueryExecutionContextFactory.CreateDocumentQueryExecutionContextAsync(
                this.client,
                this.resourceTypeEnum,
                this.resourceType,
                this.expression,
                this.feedOptions,
                this.documentsFeedOrDatabaseLink,
                isContinuationExpected,
                cancellationToken,
                this.CorrelatedActivityId));
 }
Пример #2
0
        public async Task ItemEpkQuerySingleKeyRangeValidation()
        {
            IList <ToDoActivity> deleteList = new List <ToDoActivity>();
            CosmosContainer      container  = null;

            try
            {
                // Create a container large enough to have at least 2 partitions
                CosmosContainerResponse containerResponse = await this.database.Containers.CreateContainerAsync(
                    id : Guid.NewGuid().ToString(),
                    partitionKeyPath : "/pk",
                    throughput : 15000);

                container = containerResponse;

                // Get all the partition key ranges to verify there is more than one partition
                IRoutingMapProvider routingMapProvider = await this.cosmosClient.DocumentClient.GetPartitionKeyRangeCacheAsync();

                IReadOnlyList <PartitionKeyRange> ranges = await routingMapProvider.TryGetOverlappingRangesAsync(
                    containerResponse.Resource.ResourceId,
                    new Documents.Routing.Range <string>("00", "FF", isMaxInclusive: true, isMinInclusive: true));

                // If this fails the RUs of the container needs to be increased to ensure at least 2 partitions.
                Assert.IsTrue(ranges.Count > 1, " RUs of the container needs to be increased to ensure at least 2 partitions.");

                FeedOptions options = new FeedOptions()
                {
                    Properties = new Dictionary <string, object>()
                    {
                        { "x-ms-effective-partition-key-string", "AA" }
                    }
                };

                // Create a bad expression. It will not be called. Expression is not allowed to be null.
                IQueryable <int> queryable  = new List <int>().AsQueryable();
                Expression       expression = queryable.Expression;

                DocumentQueryExecutionContextBase.InitParams inputParams = new DocumentQueryExecutionContextBase.InitParams(
                    new DocumentQueryClient(this.cosmosClient.DocumentClient),
                    ResourceType.Document,
                    typeof(object),
                    expression,
                    options,
                    ((CosmosContainerCore)container).LinkUri.OriginalString,
                    false,
                    Guid.NewGuid());

                DefaultDocumentQueryExecutionContext defaultDocumentQueryExecutionContext = new DefaultDocumentQueryExecutionContext(inputParams, true);

                // There should only be one range since the EPK option is set.
                List <PartitionKeyRange> partitionKeyRanges = await DocumentQueryExecutionContextFactory.GetTargetPartitionKeyRanges(
                    queryExecutionContext : defaultDocumentQueryExecutionContext,
                    partitionedQueryExecutionInfo : null,
                    collection : containerResponse,
                    feedOptions : options);

                Assert.IsTrue(partitionKeyRanges.Count == 1, "Only 1 partition key range should be selected since the EPK option is set.");
            }
            finally
            {
                if (container != null)
                {
                    await container.DeleteAsync();
                }
            }
        }