Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QueueDoesNotExist error in json protocol #905

Merged
merged 6 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("The specified queue does not exist.")
}

test(s"should tag, untag and list queue tags ${version.name}", Only213) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 {

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(AwsSdkGetQueueUrlRequest.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(AwsSdkGetQueueUrlRequest.builder().queueName("testQueue1").build()).queueUrl()
}

// Then
thrown.awsErrorDetails().errorCode() shouldBe "QueueDoesNotExist"
thrown.awsErrorDetails().errorMessage() shouldBe "The specified queue does not exist."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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.regions.Region
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")))
.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()
}

after {
clientV2.close()
relaxedClientV2.close()

Try(strictServer.stopAndWait())
Try(relaxedServer.stopAndWait())

logger.info(s"\n---\nTest done: $currentTestName\n---\n")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
}
Loading