Exemple #1
0
        /// <summary>
        /// Handles a request to get an execution plan
        /// </summary>
        internal async Task HandleExecutionPlanRequest(QueryExecutionPlanParams planParams,
                                                       RequestContext <QueryExecutionPlanResult> requestContext)
        {
            try
            {
                // Attempt to load the query
                Query query;
                if (!ActiveQueries.TryGetValue(planParams.OwnerUri, out query))
                {
                    await requestContext.SendError(SR.QueryServiceRequestsNoQuery);

                    return;
                }

                // Retrieve the requested execution plan and return it
                var result = new QueryExecutionPlanResult
                {
                    ExecutionPlan = await query.GetExecutionPlan(planParams.BatchIndex, planParams.ResultSetIndex)
                };
                await requestContext.SendResult(result);
            }
            catch (Exception e)
            {
                // This was unexpected, so send back as error
                await requestContext.SendError(e.Message);
            }
        }
        public async Task ExecutionPlanServiceOutOfRangeSubsetTest()
        {
            // If:
            // ... I have a query that doesn't have any result sets
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams
            {
                QuerySelection       = null,
                OwnerUri             = Constants.OwnerUri,
                ExecutionPlanOptions = new ExecutionPlanOptions
                {
                    IncludeActualExecutionPlanXml    = false,
                    IncludeEstimatedExecutionPlanXml = true
                }
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);
            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            // ... And I then ask for an execution plan from a result set
            var executionPlanParams = new QueryExecutionPlanParams {
                OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0
            };
            var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>()
                                       .AddStandardErrorValidation()
                                       .Complete();
            await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);

            executionPlanRequest.Validate();
        }
        public async Task ExecutionPlanServiceValidTest()
        {
            // If:
            // ... I have a query that has results in the form of an execution plan
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams
            {
                QuerySelection       = null,
                OwnerUri             = Constants.OwnerUri,
                ExecutionPlanOptions = new ExecutionPlanOptions
                {
                    IncludeActualExecutionPlanXml    = false,
                    IncludeEstimatedExecutionPlanXml = true
                }
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);
            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            // ... And I then ask for a valid execution plan
            var executionPlanParams = new QueryExecutionPlanParams {
                OwnerUri = Constants.OwnerUri, BatchIndex = 0, ResultSetIndex = 0
            };
            var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>()
                                       .AddResultValidation(r =>
            {
                // Then: Messages should be null and execution plan should not be null
                Assert.NotNull(r.ExecutionPlan);
            }).Complete();
            await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);

            executionPlanRequest.Validate();
        }
        public async Task ExecutionPlanServiceUnexecutedQueryTest()
        {
            // If:
            // ... I have a query that hasn't finished executing (doesn't matter what)
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams
            {
                QuerySelection       = null,
                OwnerUri             = Constants.OwnerUri,
                ExecutionPlanOptions = new ExecutionPlanOptions
                {
                    IncludeActualExecutionPlanXml    = false,
                    IncludeEstimatedExecutionPlanXml = true
                }
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);
            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;

            // ... And I then ask for a valid execution plan from it
            var executionPlanParams = new QueryExecutionPlanParams {
                OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0
            };
            var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>()
                                       .AddStandardErrorValidation()
                                       .Complete();
            await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);

            executionPlanRequest.Validate();
        }
        public async Task ExecutionPlanServiceMissingQueryTest()
        {
            // If:
            // ... I ask for an execution plan for a file that hasn't executed a query
            var workspaceService    = Common.GetPrimedWorkspaceService(Common.StandardQuery);
            var queryService        = Common.GetPrimedExecutionService(null, true, false, workspaceService);
            var executionPlanParams = new QueryExecutionPlanParams {
                OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0
            };
            var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>()
                                       .AddErrorValidation <string>(Assert.NotNull).Complete();
            await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);

            executionPlanRequest.Validate();
        }