Skip to content

Commit f2ec5ce

Browse files
authored
Merge pull request #86 from dr3s/85-create-attr
Issue 85: only compare attributes if they are sent on request
2 parents f22b7bd + 5cb5815 commit f2ec5ce

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
22

33
addSbtPlugin("com.gu" % "sbt-teamcity-test-reporting-plugin" % "1.5")
44

5+
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.0.1")
6+
57
scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation")

rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class AmazonJavaSdkTestSuite extends FunSuite with Matchers with BeforeAndAfter
154154
// Then
155155
queueVisibilityTimeout(queueUrl) should be (10)
156156
}
157-
157+
158158
test("should send and receive a simple message") {
159159
doTestSendAndReceiveMessage("Message 1")
160160
}
@@ -795,6 +795,18 @@ class AmazonJavaSdkTestSuite extends FunSuite with Matchers with BeforeAndAfter
795795

796796
result.isLeft should be (true)
797797
}
798+
799+
test("should not return an error if creating an existing queue with a non default visibility timeout") {
800+
// Given
801+
val queueUrl = client.createQueue(new CreateQueueRequest("testQueue1")
802+
.withAttributes(Map(defaultVisibilityTimeoutAttribute -> "42"))).getQueueUrl
803+
804+
// When
805+
val queueUrl2 = client.createQueue(new CreateQueueRequest("testQueue1")).getQueueUrl
806+
807+
808+
queueUrl should equal(queueUrl2)
809+
}
798810

799811
test("should purge the queue") {
800812
// Given

rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/CreateQueueDirectives.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ trait CreateQueueDirectives { this: ElasticMQDirectives with QueueURLModule with
1919
queueNameFromParams(p) { queueName =>
2020
val attributes = attributeNameAndValuesReader.read(p)
2121

22-
val secondsVisibilityTimeout = attributes.parseOptionalLong(VisibilityTimeoutParameter)
23-
.getOrElse(DefaultVisibilityTimeout)
22+
val secondsVisibilityTimeoutOpt = attributes.parseOptionalLong(VisibilityTimeoutParameter)
23+
val secondsVisibilityTimeout = secondsVisibilityTimeoutOpt.getOrElse(DefaultVisibilityTimeout)
2424

25-
val secondsDelay = attributes.parseOptionalLong(DelaySecondsAttribute)
26-
.getOrElse(DefaultDelay)
25+
val secondsDelayOpt = attributes.parseOptionalLong(DelaySecondsAttribute)
26+
val secondsDelay = secondsDelayOpt.getOrElse(DefaultDelay)
2727

2828
val secondsReceiveMessageWaitTimeOpt = attributes.parseOptionalLong(ReceiveMessageWaitTimeSecondsAttribute)
2929
val secondsReceiveMessageWaitTime = secondsReceiveMessageWaitTimeOpt
@@ -44,9 +44,12 @@ trait CreateQueueDirectives { this: ElasticMQDirectives with QueueURLModule with
4444

4545
val queueData = await(lookupOrCreateQueue(newQueueData))
4646

47-
if ((queueData.delay.getStandardSeconds != secondsDelay) ||
48-
(queueData.receiveMessageWait.getStandardSeconds != secondsReceiveMessageWaitTime) ||
49-
(queueData.defaultVisibilityTimeout.seconds != secondsVisibilityTimeout)) {
47+
// if the request set the attributes compare them against the queue
48+
if ((!secondsDelayOpt.isEmpty && queueData.delay.getStandardSeconds != secondsDelay) ||
49+
(!secondsReceiveMessageWaitTimeOpt.isEmpty
50+
&& queueData.receiveMessageWait.getStandardSeconds != secondsReceiveMessageWaitTime) ||
51+
(!secondsVisibilityTimeoutOpt.isEmpty
52+
&& queueData.defaultVisibilityTimeout.seconds != secondsVisibilityTimeout)) {
5053
// Special case: the queue existed, but has different attributes
5154
throw new SQSException("AWS.SimpleQueueService.QueueNameExists")
5255
}

0 commit comments

Comments
 (0)