Inter-Service API for executing queries (#223)

Adding new methods for executing queries from other services (such as the upcoming edit data service). The code is written to avoid duplicating logic by using lambdas to perform custom logic.
Additionally, the service host protocol has been slightly modified to split the IMessageSender into IEventSender and IRequestSender. This allows us to use either a ServiceHost or any RequestContext<T> to send events. It becomes very convenient to use another service's request context to send the events for query execution.

**Breaking Change**: This removes the messages property for query dispose results and instead elects to use error for any errors encountered during query disposal. A result is only used when something is successful.

* Splitting IMessageSender into IEventSender and IRequestSender

* Adding inter-service method for executing queries

* Adding inter-service method for disposing of a query

* Adding null checking for the success/error handlers
This commit is contained in:
Benjamin Russell
2017-02-02 17:05:10 -08:00
committed by GitHub
parent 8c6014b81c
commit 54c43f950f
9 changed files with 238 additions and 93 deletions

View File

@@ -48,11 +48,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
// ... And then I dispose of the query
var disposeParams = new QueryDisposeParams {OwnerUri = Common.OwnerUri};
var disposeRequest = new EventFlowValidator<QueryDisposeResult>()
.AddResultValidation(r =>
{
// Then: Messages should be null
Assert.Null(r.Messages);
}).Complete();
.AddStandardQueryDisposeValidator()
.Complete();
await queryService.HandleDisposeRequest(disposeParams, disposeRequest.Object);
// Then:
@@ -71,13 +68,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
var disposeParams = new QueryDisposeParams {OwnerUri = Common.OwnerUri};
var disposeRequest = new EventFlowValidator<QueryDisposeResult>()
.AddResultValidation(r =>
{
// Then: Messages should not be null
Assert.NotNull(r.Messages);
Assert.NotEmpty(r.Messages);
}).Complete();
.AddErrorValidation<string>(Assert.NotEmpty)
.Complete();
await queryService.HandleDisposeRequest(disposeParams, disposeRequest.Object);
// Then: I should have received an error
disposeRequest.Validate();
}
@@ -107,4 +102,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
Assert.Empty(queryService.ActiveQueries);
}
}
public static class QueryDisposeEventFlowValidatorExtensions
{
public static EventFlowValidator<QueryDisposeResult> AddStandardQueryDisposeValidator(
this EventFlowValidator<QueryDisposeResult> evf)
{
// We just need to make sure that the result is not null
evf.AddResultValidation(Assert.NotNull);
return evf;
}
}
}