Repository: softwaremill/elasticmq (scala)

Issue:
Disable to restore persisted FIFO queue config
Hi

When using `queues-storage` config and creating FIFO queue, the queue is correctly created.
But when restarted, persisted queues does not be restored.

---

started with config
``` elasticmq.conf
include classpath("application.conf")

queues-storage {
  enabled = true
  path = "/data/queues.conf"
}
```
and created FIFO queue
```
aws sqs create-queue --queue-name dummy.fifo --attributes ReceiveMessageWaitTimeSeconds=20,FifoQueue=true --endpoint-url http://localhost:9324
```
then, file `/data/queues.conf` is created
```
queues {
 dummy.fifo {contentBasedDeduplication=false,copyTo="",defaultVisibilityTimeout=30000,delay=0,fifo=true,moveTo="",receiveMessageWait=0,tags{}}
}
```

In this config file, name includes `.fifo` suffix.
TypeSafe Config may read incorrectly as follows.
```
queues {
 dummy {
  fifo {contentBasedDeduplication=false,copyTo="",defaultVisibilityTimeout=30000,delay=0,fifo=true,moveTo="",receiveMessageWait=0,tags{}}
 }
}
```

Pull request description:
fix #697

Patch:
diff --git a/persistence/persistence-file/src/main/scala/org/elasticmq/persistence/file/QueuePersister.scala b/persistence/persistence-file/src/main/scala/org/elasticmq/persistence/file/QueuePersister.scala
index f72e6f855..717513a2c 100644
--- a/persistence/persistence-file/src/main/scala/org/elasticmq/persistence/file/QueuePersister.scala
+++ b/persistence/persistence-file/src/main/scala/org/elasticmq/persistence/file/QueuePersister.scala
@@ -25,12 +25,21 @@ object QueuePersister {
 
   def prepareQueuesConfig(queues: List[QueueData]): String = {
     val queuesMetadata: String = queues
-      .map(queue => (queue.name, toQueueConfig(queue)))
+      .map(queue => (toPersistQueueName(queue.name), toQueueConfig(queue)))
       .map(serializeQueueMetadata)
       .mkString("")
     s"queues {\n$queuesMetadata}"
   }
 
+  private val fifoQueueNamePattern = "^(.*)\\.fifo$".r
+
+  private def toPersistQueueName(queueName: String): String = {
+    queueName match {
+      case fifoQueueNamePattern(prefix) => prefix
+      case name                         => name
+    }
+  }
+
   private def serializeQueueMetadata(queueNameToMetadata: (String, QueueMetadata)): String = {
     val options = ConfigRenderOptions.defaults().setOriginComments(false).setJson(false).setFormatted(false)
     val str = ConfigWriter[QueueMetadata].to(queueNameToMetadata._2).render(options)


Test patch:
diff --git a/persistence/persistence-file/src/test/scala/org/elasticmq/persistence/file/QueuePersisterTest.scala b/persistence/persistence-file/src/test/scala/org/elasticmq/persistence/file/QueuePersisterTest.scala
new file mode 100644
index 000000000..affa1a2ef
--- /dev/null
+++ b/persistence/persistence-file/src/test/scala/org/elasticmq/persistence/file/QueuePersisterTest.scala
@@ -0,0 +1,48 @@
+package org.elasticmq.persistence.file
+import org.elasticmq.{MillisVisibilityTimeout, QueueData}
+import org.joda.time.{DateTime, Duration}
+import org.scalatest.funsuite.AnyFunSuite
+import org.scalatest.matchers.should.Matchers
+
+class QueuePersisterTest extends AnyFunSuite with Matchers {
+  test("standard queue is converted to config") {
+
+    val queues = List(
+      QueueData(
+        name = "queue1",
+        defaultVisibilityTimeout = MillisVisibilityTimeout(10),
+        delay = Duration.ZERO,
+        receiveMessageWait = Duration.standardSeconds(10),
+        created = new DateTime(),
+        lastModified = new DateTime()
+      )
+    )
+    val actual = QueuePersister.prepareQueuesConfig(queues)
+
+    actual shouldBe
+      """queues {
+        | queue1 {contentBasedDeduplication=false,copyTo="",defaultVisibilityTimeout=10,delay=0,fifo=false,moveTo="",receiveMessageWait=10,tags{}}
+        |}""".stripMargin
+  }
+
+  test("fifo queue is converted to config") {
+    val queues = List(
+      QueueData(
+        name = "queue2.fifo",
+        defaultVisibilityTimeout = MillisVisibilityTimeout(10),
+        delay = Duration.ZERO,
+        receiveMessageWait = Duration.standardSeconds(10),
+        created = new DateTime(),
+        lastModified = new DateTime(),
+        isFifo = true
+      )
+    )
+    val actual = QueuePersister.prepareQueuesConfig(queues)
+
+    actual shouldBe
+      """queues {
+        | queue2 {contentBasedDeduplication=false,copyTo="",defaultVisibilityTimeout=10,delay=0,fifo=true,moveTo="",receiveMessageWait=10,tags{}}
+        |}""".stripMargin
+  }
+
+}