private async Task TestTryExecuteQueryHelper( Container container, IReadOnlyList <CosmosObject> documents) { ContainerInternal conatinerCore = (ContainerInlineCore)container; foreach (int maxDegreeOfParallelism in new int[] { 1, 100 }) { foreach (int maxItemCount in new int[] { 10, 100 }) { foreach ((string query, QueryFeatures queryFeatures, bool canSupportExpected) in new Tuple <string, QueryFeatures, bool>[] { new Tuple <string, QueryFeatures, bool>("SELECT * FROM c", QueryFeatures.None, true), new Tuple <string, QueryFeatures, bool>("SELECT * FROM c ORDER BY c._ts", QueryFeatures.None, false), new Tuple <string, QueryFeatures, bool>("SELECT * FROM c ORDER BY c._ts", QueryFeatures.OrderBy, true), }) { string continuationToken = null; do { ContainerInternal.TryExecuteQueryResult tryExecuteQueryResult = await conatinerCore.TryExecuteQueryAsync( supportedQueryFeatures : queryFeatures, queryDefinition : new QueryDefinition(query), requestOptions : new QueryRequestOptions() { MaxConcurrency = maxDegreeOfParallelism, MaxItemCount = maxItemCount, }, feedRangeInternal : null, continuationToken : continuationToken); if (canSupportExpected) { Assert.IsTrue(tryExecuteQueryResult is ContainerInternal.QueryPlanIsSupportedResult); } else { Assert.IsTrue(tryExecuteQueryResult is ContainerInternal.QueryPlanNotSupportedResult); } if (canSupportExpected) { ContainerInternal.QueryPlanIsSupportedResult queryPlanIsSupportedResult = (ContainerInternal.QueryPlanIsSupportedResult)tryExecuteQueryResult; ResponseMessage cosmosQueryResponse = await queryPlanIsSupportedResult.QueryIterator.ReadNextAsync(); continuationToken = cosmosQueryResponse.ContinuationToken; } } while (continuationToken != null); } } } { // Test the syntax error case ContainerInternal.TryExecuteQueryResult tryExecuteQueryResult = await conatinerCore.TryExecuteQueryAsync( supportedQueryFeatures : QueryFeatures.None, queryDefinition : new QueryDefinition("This is not a valid query."), requestOptions : new QueryRequestOptions() { MaxConcurrency = 1, MaxItemCount = 1, }, feedRangeInternal : null, continuationToken : null); Assert.IsTrue(tryExecuteQueryResult is ContainerInternal.FailedToGetQueryPlanResult); } { // Test that the force passthrough mechanism works ContainerInternal.TryExecuteQueryResult tryExecuteQueryResult = await conatinerCore.TryExecuteQueryAsync( supportedQueryFeatures : QueryFeatures.None, // Not supporting any features queryDefinition : new QueryDefinition("SELECT VALUE [{\"item\": {\"sum\": SUM(c.blah), \"count\": COUNT(c.blah)}}] FROM c"), // Query has aggregates requestOptions : new QueryRequestOptions() { MaxConcurrency = 1, MaxItemCount = 1, }, feedRangeInternal : new FeedRangePartitionKeyRange("0"), // filtering on a PkRangeId. continuationToken : null); Assert.IsTrue(tryExecuteQueryResult is ContainerInternal.QueryPlanIsSupportedResult); ContainerInternal.QueryPlanIsSupportedResult queryPlanIsSupportedResult = (ContainerInternal.QueryPlanIsSupportedResult)tryExecuteQueryResult; ResponseMessage response = await queryPlanIsSupportedResult.QueryIterator.ReadNextAsync(); Assert.IsTrue(response.IsSuccessStatusCode, response.ErrorMessage); } }
private async Task TestTryExecuteQueryHelper( Container container, IReadOnlyList <CosmosObject> documents) { ContainerInternal conatinerCore = (ContainerInlineCore)container; foreach (int maxDegreeOfParallelism in new int[] { 1, 100 }) { foreach (int maxItemCount in new int[] { 10, 100 }) { foreach ((string query, QueryFeatures queryFeatures, bool canSupportExpected) in new Tuple <string, QueryFeatures, bool>[] { new Tuple <string, QueryFeatures, bool>("SELECT * FROM c", QueryFeatures.None, true), new Tuple <string, QueryFeatures, bool>("SELECT * FROM c ORDER BY c._ts", QueryFeatures.None, false), new Tuple <string, QueryFeatures, bool>("SELECT * FROM c ORDER BY c._ts", QueryFeatures.OrderBy, true), }) { string continuationToken = null; do { ((Exception exception, PartitionedQueryExecutionInfo partitionedQueryExecutionInfo), (bool canSupportActual, FeedIterator queryIterator)) = await conatinerCore.TryExecuteQueryAsync( supportedQueryFeatures : queryFeatures, queryDefinition : new QueryDefinition(query), requestOptions : new QueryRequestOptions() { MaxConcurrency = maxDegreeOfParallelism, MaxItemCount = maxItemCount, }, feedRangeInternal : null, continuationToken : continuationToken); Assert.AreEqual(canSupportExpected, canSupportActual); if (canSupportExpected) { ResponseMessage cosmosQueryResponse = await queryIterator.ReadNextAsync(); continuationToken = cosmosQueryResponse.ContinuationToken; } Assert.IsNotNull(partitionedQueryExecutionInfo); } while (continuationToken != null); } } } { // Test the syntax error case ((Exception exception, PartitionedQueryExecutionInfo partitionedQueryExecutionInfo), (bool canSupportActual, FeedIterator queryIterator)) = await conatinerCore.TryExecuteQueryAsync( supportedQueryFeatures : QueryFeatures.None, queryDefinition : new QueryDefinition("This is not a valid query."), requestOptions : new QueryRequestOptions() { MaxConcurrency = 1, MaxItemCount = 1, }, feedRangeInternal : null, continuationToken : null); Assert.IsNotNull(exception); } }