From 8c92995216cab33138b802493b05c7fa0a33328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ossowski?= Date: Wed, 15 Nov 2023 10:21:11 +0100 Subject: [PATCH 1/6] fix QueueDoesNotExist error in json protocol --- build.sbt | 3 +- .../rest/sqs/AmazonJavaSdkV2TestSuite.scala | 33 ++++++++++ ...qsClientServerWithSdkV2Communication.scala | 66 +++++++++++++++++++ .../org/elasticmq/rest/sqs/SQSException.scala | 2 +- 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala create mode 100644 rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala diff --git a/build.sbt b/build.sbt index 691c588b..38e6880b 100644 --- a/build.sbt +++ b/build.sbt @@ -37,6 +37,7 @@ val scalatest = "org.scalatest" %% "scalatest" % "3.2.17" val awaitility = "org.awaitility" % "awaitility-scala" % "4.2.0" val amazonJavaSdkSqs = "com.amazonaws" % "aws-java-sdk-sqs" % "1.12.472" exclude ("commons-logging", "commons-logging") +val amazonJavaV2SdkSqs = "software.amazon.awssdk" % "sqs" % "2.21.22" val pekkoVersion = "1.0.1" val pekkoHttpVersion = "1.0.0" @@ -191,7 +192,7 @@ lazy val restSqsTestingAmazonJavaSdk: Project = .settings( Seq( name := "elasticmq-rest-sqs-testing-amazon-java-sdk", - libraryDependencies ++= Seq(amazonJavaSdkSqs, awsSpringMessaging, jclOverSlf4j, springWeb) ++ common, + libraryDependencies ++= Seq(amazonJavaSdkSqs, amazonJavaV2SdkSqs, awsSpringMessaging, jclOverSlf4j, springWeb) ++ common, publish / skip := true ) ) diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala new file mode 100644 index 00000000..b0ccef0c --- /dev/null +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala @@ -0,0 +1,33 @@ +package org.elasticmq.rest.sqs + +import org.scalatest.matchers.should.Matchers +import software.amazon.awssdk.services.sqs.model._ + +class AmazonJavaSdkV2TestSuite extends SqsClientServerWithSdkV2Communication with Matchers { + + test("should create a queue") { + clientV2.createQueue(CreateQueueRequest.builder.queueName("testQueue1").build()) + } + + test("should get queue url") { + // Given + clientV2.createQueue(CreateQueueRequest.builder.queueName("testQueue1").build()) + + // When + val queueUrl = clientV2.getQueueUrl(GetQueueUrlRequest.builder.queueName("testQueue1").build()).queueUrl() + + // Then + queueUrl shouldEqual "http://localhost:9321/123456789012/testQueue1" + } + + test("should fail to get queue url if queue doesn't exist") { + // When + val thrown = intercept[QueueDoesNotExistException] { + clientV2.getQueueUrl(GetQueueUrlRequest.builder.queueName("testQueue1").build()).queueUrl() + } + + // Then + thrown.awsErrorDetails().errorCode() shouldBe "QueueDoesNotExist" + thrown.awsErrorDetails().errorMessage() shouldBe "The specified queue does not exist." + } +} diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala new file mode 100644 index 00000000..0aa2ff97 --- /dev/null +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala @@ -0,0 +1,66 @@ +package org.elasticmq.rest.sqs + +import org.elasticmq.util.Logging +import org.elasticmq.{NodeAddress, RelaxedSQSLimits} +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.{Args, BeforeAndAfter, Status} +import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider} +import software.amazon.awssdk.services.sqs.{SqsClient, SqsClientBuilder} + +import java.net.URI +import scala.util.Try + +trait SqsClientServerWithSdkV2Communication extends AnyFunSuite with BeforeAndAfter with Logging { + + var clientV2: SqsClient = _ // strict server + var relaxedClientV2: SqsClient = _ + + var currentTestName: String = _ + + var strictServer: SQSRestServer = _ + var relaxedServer: SQSRestServer = _ + val awsAccountId = "123456789012" + val awsRegion = "elasticmq" + + val ServiceEndpoint = "http://localhost:9321" + + before { + logger.info(s"\n---\nRunning test: $currentTestName\n---\n") + + strictServer = SQSRestServerBuilder + .withPort(9321) + .withServerAddress(NodeAddress(port = 9321)) + .withAWSAccountId(awsAccountId) + .withAWSRegion(awsRegion) + .start() + + relaxedServer = SQSRestServerBuilder + .withPort(9322) + .withServerAddress(NodeAddress(port = 9322)) + .withSQSLimits(RelaxedSQSLimits) + .start() + + strictServer.waitUntilStarted() + relaxedServer.waitUntilStarted() + + clientV2 = SqsClient.builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))) + .endpointOverride(new URI("http://localhost:9321")) + .build() + + relaxedClientV2 = SqsClient.builder() + .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))) + .endpointOverride(new URI("http://localhost:9322")) + .build() + } + + after { + clientV2.close() + relaxedClientV2.close() + + Try(strictServer.stopAndWait()) + Try(relaxedServer.stopAndWait()) + + logger.info(s"\n---\nTest done: $currentTestName\n---\n") + } +} diff --git a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/SQSException.scala b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/SQSException.scala index cd4c49bc..b904aa13 100644 --- a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/SQSException.scala +++ b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/SQSException.scala @@ -71,5 +71,5 @@ object SQSException { /** Indicates a queue does not exist */ def nonExistentQueue: SQSException = - new SQSException("AWS.SimpleQueueService.NonExistentQueue") + new SQSException("AWS.SimpleQueueService.NonExistentQueue", errorType = "com.amazonaws.sqs#QueueDoesNotExist", errorMessage = Some("The specified queue does not exist.")) } From 14c50eee7d5ae73d0a1f31b074dd2aeb26213c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ossowski?= Date: Wed, 15 Nov 2023 10:35:44 +0100 Subject: [PATCH 2/6] add missing default region --- .../rest/sqs/SqsClientServerWithSdkV2Communication.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala index 0aa2ff97..433e8393 100644 --- a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqsClientServerWithSdkV2Communication.scala @@ -5,6 +5,7 @@ import org.elasticmq.{NodeAddress, RelaxedSQSLimits} import org.scalatest.funsuite.AnyFunSuite import org.scalatest.{Args, BeforeAndAfter, Status} import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider} +import software.amazon.awssdk.regions.Region import software.amazon.awssdk.services.sqs.{SqsClient, SqsClientBuilder} import java.net.URI @@ -45,11 +46,13 @@ trait SqsClientServerWithSdkV2Communication extends AnyFunSuite with BeforeAndAf clientV2 = SqsClient.builder() .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))) + .region(Region.EU_CENTRAL_1) .endpointOverride(new URI("http://localhost:9321")) .build() relaxedClientV2 = SqsClient.builder() .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))) + .region(Region.EU_CENTRAL_1) .endpointOverride(new URI("http://localhost:9322")) .build() } From ca8eb380cb4c43b3ccdbf7e5ef6ebca3fea30018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ossowski?= Date: Wed, 15 Nov 2023 10:40:13 +0100 Subject: [PATCH 3/6] fix 2.12 build --- .../org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala index b0ccef0c..ec655ce6 100644 --- a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala @@ -6,15 +6,15 @@ import software.amazon.awssdk.services.sqs.model._ class AmazonJavaSdkV2TestSuite extends SqsClientServerWithSdkV2Communication with Matchers { test("should create a queue") { - clientV2.createQueue(CreateQueueRequest.builder.queueName("testQueue1").build()) + clientV2.createQueue(CreateQueueRequest.builder().queueName("testQueue1").build()) } test("should get queue url") { // Given - clientV2.createQueue(CreateQueueRequest.builder.queueName("testQueue1").build()) + clientV2.createQueue(CreateQueueRequest.builder().queueName("testQueue1").build()) // When - val queueUrl = clientV2.getQueueUrl(GetQueueUrlRequest.builder.queueName("testQueue1").build()).queueUrl() + val queueUrl = clientV2.getQueueUrl(GetQueueUrlRequest.builder().queueName("testQueue1").build()).queueUrl() // Then queueUrl shouldEqual "http://localhost:9321/123456789012/testQueue1" @@ -23,7 +23,7 @@ class AmazonJavaSdkV2TestSuite extends SqsClientServerWithSdkV2Communication wit test("should fail to get queue url if queue doesn't exist") { // When val thrown = intercept[QueueDoesNotExistException] { - clientV2.getQueueUrl(GetQueueUrlRequest.builder.queueName("testQueue1").build()).queueUrl() + clientV2.getQueueUrl(GetQueueUrlRequest.builder().queueName("testQueue1").build()).queueUrl() } // Then From 89f4767ca589d551cb1ae14df3aa07e8ac02659c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ossowski?= Date: Wed, 15 Nov 2023 10:46:30 +0100 Subject: [PATCH 4/6] fix 2.12 build --- .../org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala index ec655ce6..e2fb482c 100644 --- a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkV2TestSuite.scala @@ -2,6 +2,7 @@ package org.elasticmq.rest.sqs import org.scalatest.matchers.should.Matchers import software.amazon.awssdk.services.sqs.model._ +import software.amazon.awssdk.services.sqs.model.{GetQueueUrlRequest => AwsSdkGetQueueUrlRequest} class AmazonJavaSdkV2TestSuite extends SqsClientServerWithSdkV2Communication with Matchers { @@ -14,7 +15,7 @@ class AmazonJavaSdkV2TestSuite extends SqsClientServerWithSdkV2Communication wit clientV2.createQueue(CreateQueueRequest.builder().queueName("testQueue1").build()) // When - val queueUrl = clientV2.getQueueUrl(GetQueueUrlRequest.builder().queueName("testQueue1").build()).queueUrl() + val queueUrl = clientV2.getQueueUrl(AwsSdkGetQueueUrlRequest.builder().queueName("testQueue1").build()).queueUrl() // Then queueUrl shouldEqual "http://localhost:9321/123456789012/testQueue1" @@ -23,7 +24,7 @@ class AmazonJavaSdkV2TestSuite extends SqsClientServerWithSdkV2Communication wit test("should fail to get queue url if queue doesn't exist") { // When val thrown = intercept[QueueDoesNotExistException] { - clientV2.getQueueUrl(GetQueueUrlRequest.builder().queueName("testQueue1").build()).queueUrl() + clientV2.getQueueUrl(AwsSdkGetQueueUrlRequest.builder().queueName("testQueue1").build()).queueUrl() } // Then From d8267987c7e33157285b1991f5ca4554b11fd574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ossowski?= Date: Wed, 15 Nov 2023 10:57:57 +0100 Subject: [PATCH 5/6] fix cli test --- .../test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala index aae13b05..848bc604 100644 --- a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala @@ -264,7 +264,7 @@ class AmazonCliTestSuite // then outLines.mkString("\n") shouldBe empty - errLines.mkString("\n") should include("AWS.SimpleQueueService.NonExistentQueue; see the SQS docs.") + errLines.mkString("\n") should include("An error occurred (QueueDoesNotExist) when calling the SendMessage operation: The specified queue does not exist.") } test(s"should tag, untag and list queue tags ${version.name}", Only213) { From 162f969f335e5a5b8dfa6c6eb2017396a3cf89a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ossowski?= Date: Wed, 15 Nov 2023 12:51:18 +0100 Subject: [PATCH 6/6] fix cli test --- .../test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala index 848bc604..116b3986 100644 --- a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonCliTestSuite.scala @@ -264,7 +264,7 @@ class AmazonCliTestSuite // then outLines.mkString("\n") shouldBe empty - errLines.mkString("\n") should include("An error occurred (QueueDoesNotExist) when calling the SendMessage operation: The specified queue does not exist.") + errLines.mkString("\n") should include("The specified queue does not exist.") } test(s"should tag, untag and list queue tags ${version.name}", Only213) {