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 bug in dequeuing according to a MaxNumberOfMessages parameter #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/main/scala/io/findify/sqsmock/model/QueueCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class QueueCache(params:Queue) {
msg
}
def dequeue(count:Int):List[ReceivedMessage] = {
(0 to count).flatMap(_ => dequeue).toList
(0 until count).flatMap(_ => dequeue).toList
}
def delete(handle:String) = received.get(handle) match {
case Some(lease) =>
Expand Down
12 changes: 12 additions & 0 deletions src/test/scala/io/findify/sqsmock/SendReceiveTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.findify.sqsmock

import com.amazonaws.services.sqs.AmazonSQSClient
import com.amazonaws.services.sqs.model.ReceiveMessageRequest
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}

import scala.collection.JavaConversions._
Expand All @@ -25,4 +26,15 @@ class SendReceiveTest extends FlatSpec with Matchers with SQSStartStop {
val result = client.receiveMessage(queue)
assert(result.getMessages.isEmpty)
}
it should "dequeue a number of messages according to a `MaxNumberOfMessages` parameter" in {
client.sendMessage(queue, "message1")
client.sendMessage(queue, "message2")
val receiveMessageRequest = new ReceiveMessageRequest(queue).withMaxNumberOfMessages(1)
val result1 = client.receiveMessage(receiveMessageRequest)
assert(result1.getMessages.size == 1)
val result2 = client.receiveMessage(receiveMessageRequest)
assert(result2.getMessages.size == 1)
val result3 = client.receiveMessage(receiveMessageRequest)
assert(result3.getMessages.size == 0)
}
}