mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-28 17:24:27 -05:00
Drop job step and Create\Update alert handlers (#636)
* Add Delete Job Step implementation * Update create\update agent alert handlers to use execution handler * Cleanup create/update/delete operator request handlers
This commit is contained in:
@@ -3,21 +3,11 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.XEvent;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Profiler;
|
||||
using Microsoft.SqlTools.ServiceLayer.Profiler.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Moq;
|
||||
@@ -53,43 +43,44 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
/// <summary>
|
||||
/// Verify the default "create agent alert" request handler with valid parameters
|
||||
/// </summary>
|
||||
// TODO: Fix flaky test. See https://github.com/Microsoft/sqltoolsservice/issues/630
|
||||
// [Fact]
|
||||
[Fact]
|
||||
public async Task TestHandleCreateAgentAlertsRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
// setup
|
||||
var createContext = new Mock<RequestContext<CreateAgentAlertResult>>();
|
||||
var deleteContext = new Mock<RequestContext<ResultStatus>>();
|
||||
|
||||
var requestParams = new CreateAgentAlertParams
|
||||
var service = new AgentService();
|
||||
var alert = new AgentAlertInfo()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Alert = new AgentAlertInfo()
|
||||
{
|
||||
JobName = "Test Job Name"
|
||||
}
|
||||
JobName = "test_update_job",
|
||||
AlertType = AlertType.SqlServerEvent,
|
||||
Severity = 1
|
||||
};
|
||||
|
||||
var requestContext = new Mock<RequestContext<CreateAgentAlertResult>>();
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
await service.HandleDeleteAgentAlertRequest(new DeleteAgentAlertParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Alert = alert
|
||||
}, deleteContext.Object);
|
||||
|
||||
AgentService service = new AgentService();
|
||||
await service.HandleCreateAgentAlertRequest(requestParams, requestContext.Object);
|
||||
// test
|
||||
await service.HandleCreateAgentAlertRequest(new CreateAgentAlertParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Alert = alert
|
||||
}, createContext.Object);
|
||||
createContext.VerifyAll();
|
||||
|
||||
// var agentAlerts = await AgentTestUtils.GetAgentAlerts(connectionResult.ConnectionInfo.OwnerUri);
|
||||
// if (agentAlerts != null && agentAlerts.Length > 0)
|
||||
// {
|
||||
// foreach (var agentAlert in agentAlerts)
|
||||
// {
|
||||
// if (agentAlert.JobName.Equals(alert.JobName))
|
||||
// {
|
||||
// await service.HandleDeleteAgentAlertRequest(new DeleteAgentAlertParams()
|
||||
// {
|
||||
// OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
// Alert = alert
|
||||
// }, deleteContext.Object);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// cleanup
|
||||
await service.HandleDeleteAgentAlertRequest(new DeleteAgentAlertParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Alert = alert
|
||||
}, deleteContext.Object);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +92,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// setup
|
||||
var createContext = new Mock<RequestContext<CreateAgentAlertResult>>();
|
||||
var updateContext = new Mock<RequestContext<UpdateAgentAlertResult>>();
|
||||
var deleteContext = new Mock<RequestContext<ResultStatus>>();
|
||||
@@ -126,21 +118,21 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
Alert = alert
|
||||
}, createContext.Object);
|
||||
|
||||
// test
|
||||
alert.Severity = 2;
|
||||
await service.HandleUpdateAgentAlertRequest(new UpdateAgentAlertParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Alert = alert
|
||||
}, updateContext.Object);
|
||||
updateContext.VerifyAll();
|
||||
|
||||
// cleanup
|
||||
await service.HandleDeleteAgentAlertRequest(new DeleteAgentAlertParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Alert = alert
|
||||
}, deleteContext.Object);
|
||||
|
||||
createContext.VerifyAll();
|
||||
updateContext.VerifyAll();
|
||||
deleteContext.VerifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +64,33 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
await AgentTestUtils.UpdateAgentJobStep(service, connectionResult, stepInfo);
|
||||
|
||||
// cleanup
|
||||
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
|
||||
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TestHandleDeleteAgentJobRequest
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestHandleDeleteAgentJobStepRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// setup
|
||||
var service = new AgentService();
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var job = AgentTestUtils.GetTestJobInfo();
|
||||
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
|
||||
await AgentTestUtils.CreateAgentJob(service, connectionResult, job);
|
||||
var stepInfo = AgentTestUtils.GetTestJobStepInfo(connectionResult, job);
|
||||
await AgentTestUtils.CreateAgentJobStep(service, connectionResult, stepInfo);
|
||||
|
||||
// test
|
||||
await AgentTestUtils.DeleteAgentJobStep(service, connectionResult, stepInfo);
|
||||
|
||||
// cleanup
|
||||
await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,34 +16,69 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
public class AgentOperatorTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Verify the default "create agent alert" request handler with valid parameters
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestHandleCreateAgentOperatorRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// setup
|
||||
var service = new AgentService();
|
||||
var operatorInfo = AgentTestUtils.GetTestOperatorInfo();
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);
|
||||
|
||||
// test
|
||||
await AgentTestUtils.CreateAgentOperator(service, connectionResult, operatorInfo);
|
||||
|
||||
// cleanup
|
||||
await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the default "update agent alert" request handler with valid parameters
|
||||
/// TestHandleUpdateAgentOperatorRequest
|
||||
/// </summary>
|
||||
//[Fact]
|
||||
[Fact]
|
||||
public async Task TestHandleUpdateAgentOperatorRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var createContext = new Mock<RequestContext<CreateAgentOperatorResult>>();
|
||||
|
||||
// setup
|
||||
var service = new AgentService();
|
||||
var operatorInfo = new AgentOperatorInfo()
|
||||
{
|
||||
Id = 10,
|
||||
Name = "Joe DBA",
|
||||
EmailAddress = "test@aol.com"
|
||||
};
|
||||
|
||||
var operatorInfo = AgentTestUtils.GetTestOperatorInfo();
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);
|
||||
await AgentTestUtils.CreateAgentOperator(service, connectionResult, operatorInfo);
|
||||
|
||||
await service.HandleCreateAgentOperatorRequest(new CreateAgentOperatorParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Operator = operatorInfo
|
||||
}, createContext.Object);
|
||||
// test
|
||||
operatorInfo.EmailAddress = "updated@email.com";
|
||||
await AgentTestUtils.UpdateAgentOperator(service, connectionResult, operatorInfo);
|
||||
|
||||
createContext.VerifyAll();
|
||||
// cleanup
|
||||
await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TestHandleDeleteAgentOperatorRequest
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestHandleDeleteAgentOperatorRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// setup
|
||||
var service = new AgentService();
|
||||
var operatorInfo = AgentTestUtils.GetTestOperatorInfo();
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);
|
||||
await AgentTestUtils.CreateAgentOperator(service, connectionResult, operatorInfo);
|
||||
|
||||
// test
|
||||
await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,16 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
};
|
||||
}
|
||||
|
||||
internal static AgentOperatorInfo GetTestOperatorInfo()
|
||||
{
|
||||
return new AgentOperatorInfo()
|
||||
{
|
||||
Id = 10,
|
||||
Name = "Joe DBA",
|
||||
EmailAddress = "test@aol.com"
|
||||
};
|
||||
}
|
||||
|
||||
internal static async Task CreateAgentJob(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
@@ -135,6 +145,62 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task DeleteAgentJobStep(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
AgentJobStepInfo stepInfo)
|
||||
{
|
||||
var context = new Mock<RequestContext<ResultStatus>>();
|
||||
await service.HandleDeleteAgentJobStepRequest(new DeleteAgentJobStepParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Step = stepInfo
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task CreateAgentOperator(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
AgentOperatorInfo operatorInfo)
|
||||
{
|
||||
var context = new Mock<RequestContext<AgentOperatorResult>>();
|
||||
await service.HandleCreateAgentOperatorRequest(new CreateAgentOperatorParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Operator = operatorInfo
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task UpdateAgentOperator(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
AgentOperatorInfo operatorInfo)
|
||||
{
|
||||
var context = new Mock<RequestContext<AgentOperatorResult>>();
|
||||
await service.HandleUpdateAgentOperatorRequest(new UpdateAgentOperatorParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Operator = operatorInfo
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task DeleteAgentOperator(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
AgentOperatorInfo operatorInfo)
|
||||
{
|
||||
var context = new Mock<RequestContext<ResultStatus>>();
|
||||
await service.HandleDeleteAgentOperatorRequest(new DeleteAgentOperatorParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Operator = operatorInfo
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task<AgentAlertInfo[]> GetAgentAlerts(string connectionUri)
|
||||
{
|
||||
var requestParams = new AgentAlertsParams()
|
||||
|
||||
Reference in New Issue
Block a user