Skip to content

Commit

Permalink
More renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
nr-ahemsath committed Oct 21, 2024
1 parent 6e6d5a8 commit d4a9144
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@

namespace AwsSdkTestApp.AwsSdkExercisers
{
public class AwsSdkExerciser : IDisposable
public class AwsSdkSQSExerciser : IDisposable
{
public AwsSdkExerciser(AwsSdkTestType testType)
{
switch (testType)
{
case AwsSdkTestType.SQS:
_amazonSqsClient = GetSqsClient();
break;
default:
throw new ArgumentException("Invalid test type");
}
}
#region SQS

private readonly AmazonSQSClient _amazonSqsClient;
private string _sqsQueueUrl = null;

public AwsSdkSQSExerciser()
{
_amazonSqsClient = GetSqsClient();
}


private AmazonSQSClient GetSqsClient()
{
// configure the client to use LocalStack
Expand Down Expand Up @@ -190,8 +183,6 @@ public void SQS_SetQueueUrl(string messageQueueUrl)
_sqsQueueUrl = messageQueueUrl;
}

#endregion

public void Dispose()
{
_amazonSqsClient?.Dispose();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace AwsSdkTestApp.Controllers
{
[ApiController]
[Route("[controller]")]
public class AwsSdkController : ControllerBase
public class AwsSdkSQSController : ControllerBase
{
private readonly ILogger<AwsSdkController> _logger;
private readonly ILogger<AwsSdkSQSController> _logger;
private readonly ISQSRequestQueue _requestQueue;
private readonly ISQSResponseQueue _responseQueue;

public AwsSdkController(ILogger<AwsSdkController> logger, ISQSRequestQueue requestQueue, ISQSResponseQueue responseQueue)
public AwsSdkSQSController(ILogger<AwsSdkSQSController> logger, ISQSRequestQueue requestQueue, ISQSResponseQueue responseQueue)
{
_logger = logger;
_requestQueue = requestQueue;
Expand All @@ -36,20 +36,20 @@ public async Task SQS_SendReceivePurgeAsync([Required]string queueName)
{
_logger.LogInformation("Starting SQS_SendReceivePurge for {Queue}", queueName);

using var awsSdkExerciser = new AwsSdkExercisers.AwsSdkExerciser(AwsSdkTestType.SQS);
using var awsSdkSQSExerciser = new AwsSdkSQSExerciser();

await awsSdkExerciser.SQS_InitializeAsync(queueName);
await awsSdkSQSExerciser.SQS_InitializeAsync(queueName);

await awsSdkExerciser.SQS_SendMessageAsync("Hello World!");
await awsSdkExerciser.SQS_ReceiveMessageAsync();
await awsSdkSQSExerciser.SQS_SendMessageAsync("Hello World!");
await awsSdkSQSExerciser.SQS_ReceiveMessageAsync();

var messages = new[] { "Hello", "World" };
await awsSdkExerciser.SQS_SendMessageBatchAsync(messages);
await awsSdkExerciser.SQS_ReceiveMessageAsync(messages.Length);
await awsSdkSQSExerciser.SQS_SendMessageBatchAsync(messages);
await awsSdkSQSExerciser.SQS_ReceiveMessageAsync(messages.Length);

await awsSdkExerciser.SQS_PurgeQueueAsync();
await awsSdkSQSExerciser.SQS_PurgeQueueAsync();

await awsSdkExerciser.SQS_TeardownAsync();
await awsSdkSQSExerciser.SQS_TeardownAsync();

_logger.LogInformation("Finished SQS_SendReceivePurge for {Queue}", queueName);
}
Expand All @@ -64,8 +64,8 @@ public async Task SQS_SendReceivePurgeAsync([Required]string queueName)
public async Task<string> SQS_InitializeQueueAsync([Required]string queueName)
{
_logger.LogInformation("Initializing queue {Queue}", queueName);
using var awsSdkExerciser = new AwsSdkExercisers.AwsSdkExerciser(AwsSdkTestType.SQS);
var queueUrl = await awsSdkExerciser.SQS_InitializeAsync(queueName);
using var awsSdkSQSExerciser = new AwsSdkSQSExerciser();
var queueUrl = await awsSdkSQSExerciser.SQS_InitializeAsync(queueName);
_logger.LogInformation("Queue {Queue} initialized with URL {QueueUrl}", queueName, queueUrl);
return queueUrl;
}
Expand All @@ -75,10 +75,10 @@ public async Task<string> SQS_InitializeQueueAsync([Required]string queueName)
public async Task SQS_SendMessageToQueueAsync([Required]string message, [Required]string messageQueueUrl)
{
_logger.LogInformation("Sending message {Message} to {Queue}", message, messageQueueUrl);
using var awsSdkExerciser = new AwsSdkExercisers.AwsSdkExerciser(AwsSdkTestType.SQS);
awsSdkExerciser.SQS_SetQueueUrl(messageQueueUrl);
using var awsSdkSQSExerciser = new AwsSdkSQSExerciser();
awsSdkSQSExerciser.SQS_SetQueueUrl(messageQueueUrl);

await awsSdkExerciser.SQS_SendMessageAsync(message);
await awsSdkSQSExerciser.SQS_SendMessageAsync(message);
_logger.LogInformation("Message {Message} sent to {Queue}", message, messageQueueUrl);
}

Expand All @@ -99,10 +99,10 @@ public async Task<IEnumerable<Message>> SQS_ReceiveMessageFromQueueAsync([Requir
public async Task SQS_DeleteQueueAsync([Required]string messageQueueUrl)
{
_logger.LogInformation("Deleting queue {Queue}", messageQueueUrl);
using var awsSdkExerciser = new AwsSdkExercisers.AwsSdkExerciser(AwsSdkTestType.SQS);
awsSdkExerciser.SQS_SetQueueUrl(messageQueueUrl);
using var awsSdkSQSExerciser = new AwsSdkSQSExerciser();
awsSdkSQSExerciser.SQS_SetQueueUrl(messageQueueUrl);

await awsSdkExerciser.SQS_TeardownAsync();
await awsSdkSQSExerciser.SQS_TeardownAsync();
_logger.LogInformation("Queue {Queue} deleted", messageQueueUrl);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
private async Task<IEnumerable<Message>> ProcessRequestAsync(string queueUrl)
{
_logger.LogInformation("Received a request to receive a message from {Queue}", queueUrl);
using var awsSdkExerciser = new AwsSdkExercisers.AwsSdkExerciser(AwsSdkTestType.SQS);
awsSdkExerciser.SQS_SetQueueUrl(queueUrl);
using var awsSdkSQSExerciser = new AwsSdkSQSExerciser();
awsSdkSQSExerciser.SQS_SetQueueUrl(queueUrl);
_logger.LogInformation("Receiving a message from {Queue}", queueUrl);
var messages = await awsSdkExerciser.SQS_ReceiveMessageAsync();
var messages = await awsSdkSQSExerciser.SQS_ReceiveMessageAsync();
_logger.LogInformation("Received a message from {Queue}; queuing a response", queueUrl);
await _responseQueue.QueueResponseAsync(messages);
_logger.LogInformation("Finished processing request for {Queue}", queueUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,40 @@ public class AwsSdkContainerSQSTestFixture : AwsSdkContainerTestFixtureBase
private const ContainerApplication.Architecture Architecture = ContainerApplication.Architecture.X64;
private const string DistroTag = "jammy";

public AwsSdkContainerSQSTestFixture() : base(DistroTag, Architecture, Dockerfile) { }
private readonly string BaseUrl;

public void ExerciseSQS_SendReceivePurge(string queueName)
public AwsSdkContainerSQSTestFixture() : base(DistroTag, Architecture, Dockerfile)
{
var address = $"http://localhost:{Port}/awssdk";
BaseUrl = $"http://localhost:{Port}/awssdksqs";
}

public void ExerciseSQS_SendReceivePurge(string queueName)
{
// The exerciser will return a 500 error if the `RequestMessage.MessageAttributeNames` collection is modified by our instrumentation.
// See https://github.com/newrelic/newrelic-dotnet-agent/pull/2646
GetAndAssertStatusCode($"{address}/SQS_SendReceivePurge?queueName={queueName}", System.Net.HttpStatusCode.OK);
GetAndAssertStatusCode($"{BaseUrl}/SQS_SendReceivePurge?queueName={queueName}", System.Net.HttpStatusCode.OK);
}

public string ExerciseSQS_SendAndReceiveInSeparateTransactions(string queueName)
{
var address = $"http://localhost:{Port}/awssdk";

var queueUrl = GetString($"{address}/SQS_InitializeQueue?queueName={queueName}");
var queueUrl = GetString($"{BaseUrl}/SQS_InitializeQueue?queueName={queueName}");

GetAndAssertStatusCode($"{address}/SQS_SendMessageToQueue?message=Hello&messageQueueUrl={queueUrl}", System.Net.HttpStatusCode.OK);
GetAndAssertStatusCode($"{BaseUrl}/SQS_SendMessageToQueue?message=Hello&messageQueueUrl={queueUrl}", System.Net.HttpStatusCode.OK);

var messagesJson = GetString($"{address}/SQS_ReceiveMessageFromQueue?messageQueueUrl={queueUrl}");
var messagesJson = GetString($"{BaseUrl}/SQS_ReceiveMessageFromQueue?messageQueueUrl={queueUrl}");

GetAndAssertStatusCode($"{address}/SQS_DeleteQueue?messageQueueUrl={queueUrl}", System.Net.HttpStatusCode.OK);
GetAndAssertStatusCode($"{BaseUrl}/SQS_DeleteQueue?messageQueueUrl={queueUrl}", System.Net.HttpStatusCode.OK);

return messagesJson;
}

public string ExerciseSQS_ReceiveEmptyMessage(string queueName)
{
var address = $"http://localhost:{Port}/awssdk";

var queueUrl = GetString($"{address}/SQS_InitializeQueue?queueName={queueName}");
var queueUrl = GetString($"{BaseUrl}/SQS_InitializeQueue?queueName={queueName}");

var messagesJson = GetString($"{address}/SQS_ReceiveMessageFromQueue?messageQueueUrl={queueUrl}");
var messagesJson = GetString($"{BaseUrl}/SQS_ReceiveMessageFromQueue?messageQueueUrl={queueUrl}");

GetAndAssertStatusCode($"{address}/SQS_DeleteQueue?messageQueueUrl={queueUrl}", System.Net.HttpStatusCode.OK);
GetAndAssertStatusCode($"{BaseUrl}/SQS_DeleteQueue?messageQueueUrl={queueUrl}", System.Net.HttpStatusCode.OK);

return messagesJson;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public abstract class AwsSdkSQSTestBase : NewRelicIntegrationTest<AwsSdkContaine
private readonly string _testQueueName1 = $"TestQueue1-{Guid.NewGuid()}";
private readonly string _testQueueName2 = $"TestQueue2-{Guid.NewGuid()}";
private readonly string _testQueueName3 = $"TestQueue3-{Guid.NewGuid()}";
private readonly string _metricScope1 = "WebTransaction/MVC/AwsSdk/SQS_SendReceivePurge/{queueName}";
private readonly string _metricScope2 = "WebTransaction/MVC/AwsSdk/SQS_SendMessageToQueue/{message}/{messageQueueUrl}";
private readonly string _metricScope1 = "WebTransaction/MVC/AwsSdkSQS/SQS_SendReceivePurge/{queueName}";
private readonly string _metricScope2 = "WebTransaction/MVC/AwsSdkSQS/SQS_SendMessageToQueue/{message}/{messageQueueUrl}";
private bool _initCollections;

protected AwsSdkSQSTestBase(AwsSdkContainerSQSTestFixture fixture, ITestOutputHelper output, bool initCollections) : base(fixture)
Expand Down

0 comments on commit d4a9144

Please sign in to comment.