From 5cb5815b95cc696157827ab1aec9d264a240cf37 Mon Sep 17 00:00:00 2001 From: Andres March Date: Tue, 29 Nov 2016 09:59:14 -0500 Subject: [PATCH] Issue 85: only compare attributes if they are sent on request --- project/plugins.sbt | 2 ++ .../rest/sqs/AmazonJavaSdkTestSuite.scala | 14 +++++++++++++- .../rest/sqs/CreateQueueDirectives.scala | 17 ++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 4a7e0c9c5..1c8b9bcb2 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,4 +2,6 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2") addSbtPlugin("com.gu" % "sbt-teamcity-test-reporting-plugin" % "1.5") +addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.0.1") + scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation") diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala index 743a2f3a9..b94dc09c2 100644 --- a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala +++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala @@ -154,7 +154,7 @@ class AmazonJavaSdkTestSuite extends FunSuite with Matchers with BeforeAndAfter // Then queueVisibilityTimeout(queueUrl) should be (10) } - + test("should send and receive a simple message") { doTestSendAndReceiveMessage("Message 1") } @@ -795,6 +795,18 @@ class AmazonJavaSdkTestSuite extends FunSuite with Matchers with BeforeAndAfter result.isLeft should be (true) } + + test("should not return an error if creating an existing queue with a non default visibility timeout") { + // Given + val queueUrl = client.createQueue(new CreateQueueRequest("testQueue1") + .withAttributes(Map(defaultVisibilityTimeoutAttribute -> "42"))).getQueueUrl + + // When + val queueUrl2 = client.createQueue(new CreateQueueRequest("testQueue1")).getQueueUrl + + + queueUrl should equal(queueUrl2) + } test("should purge the queue") { // Given diff --git a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/CreateQueueDirectives.scala b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/CreateQueueDirectives.scala index db992a6fe..5a83dcf58 100644 --- a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/CreateQueueDirectives.scala +++ b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/CreateQueueDirectives.scala @@ -19,11 +19,11 @@ trait CreateQueueDirectives { this: ElasticMQDirectives with QueueURLModule with queueNameFromParams(p) { queueName => val attributes = attributeNameAndValuesReader.read(p) - val secondsVisibilityTimeout = attributes.parseOptionalLong(VisibilityTimeoutParameter) - .getOrElse(DefaultVisibilityTimeout) + val secondsVisibilityTimeoutOpt = attributes.parseOptionalLong(VisibilityTimeoutParameter) + val secondsVisibilityTimeout = secondsVisibilityTimeoutOpt.getOrElse(DefaultVisibilityTimeout) - val secondsDelay = attributes.parseOptionalLong(DelaySecondsAttribute) - .getOrElse(DefaultDelay) + val secondsDelayOpt = attributes.parseOptionalLong(DelaySecondsAttribute) + val secondsDelay = secondsDelayOpt.getOrElse(DefaultDelay) val secondsReceiveMessageWaitTimeOpt = attributes.parseOptionalLong(ReceiveMessageWaitTimeSecondsAttribute) val secondsReceiveMessageWaitTime = secondsReceiveMessageWaitTimeOpt @@ -44,9 +44,12 @@ trait CreateQueueDirectives { this: ElasticMQDirectives with QueueURLModule with val queueData = await(lookupOrCreateQueue(newQueueData)) - if ((queueData.delay.getStandardSeconds != secondsDelay) || - (queueData.receiveMessageWait.getStandardSeconds != secondsReceiveMessageWaitTime) || - (queueData.defaultVisibilityTimeout.seconds != secondsVisibilityTimeout)) { + // if the request set the attributes compare them against the queue + if ((!secondsDelayOpt.isEmpty && queueData.delay.getStandardSeconds != secondsDelay) || + (!secondsReceiveMessageWaitTimeOpt.isEmpty + && queueData.receiveMessageWait.getStandardSeconds != secondsReceiveMessageWaitTime) || + (!secondsVisibilityTimeoutOpt.isEmpty + && queueData.defaultVisibilityTimeout.seconds != secondsVisibilityTimeout)) { // Special case: the queue existed, but has different attributes throw new SQSException("AWS.SimpleQueueService.QueueNameExists") }