Skip to content

Commit

Permalink
APID-252: add index on messageId to messages collection in Mongo (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
worthydolt authored Aug 11, 2021
1 parent b1c843c commit 0e78fe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class OutboundMessageRepository @Inject()(mongoComponent: MongoComponent, appCon
domainFormat = outboundSoapMessageFormatter,
indexes = Seq(IndexModel(ascending("globalId"),
IndexOptions().name("globalIdIndex").background(true).unique(true)),
IndexModel(ascending("messageId"),
IndexOptions().name("messageIdIndex").background(true).unique(false)),
IndexModel(ascending("createDateTime"),
IndexOptions().name("ttlIndex").background(true)
.expireAfter(appConfig.retryMessagesTtl.toSeconds, TimeUnit.SECONDS))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ class OutboundMessageRepositoryISpec extends AnyWordSpec with PlayMongoRepositor
globalIdIndex.get("background").get shouldBe BsonBoolean(true)
}

"create index on message ID" in {
await(serviceRepo.persist(sentMessage))

val Some(globalIdIndex) = await(serviceRepo.collection.listIndexes().toFuture()).find(i => i.get("name").get.asString().getValue == "messageIdIndex")
globalIdIndex.get("unique") shouldBe None
globalIdIndex.get("background").get shouldBe BsonBoolean(true)
}

"fail when a message with the same ID already exists" in {
await(serviceRepo.persist(retryingMessage))

Expand Down

0 comments on commit 0e78fe3

Please sign in to comment.