-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 39 additions & 1 deletion
40
testkit/src/main/scala/com/commercetools/queue/testkit/QueuePublisherSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,47 @@ | ||
package com.commercetools.queue.testkit | ||
|
||
import munit.CatsEffectSuite | ||
import fs2.Stream | ||
import cats.syntax.all._ | ||
|
||
import scala.concurrent.duration.DurationInt | ||
|
||
/** | ||
* This suite tests that the features of a [[com.commercetools.queue.QueuePublisher QueuePublisher]] are properly | ||
* implemented for a concrete client. | ||
*/ | ||
trait QueuePublisherSuite extends CatsEffectSuite {} | ||
trait QueuePublisherSuite extends CatsEffectSuite { self: QueueClientSuite => | ||
|
||
withQueue.test("sink publishes all the messages") { queueName => | ||
val client = clientFixture() | ||
for { | ||
msgs <- randomMessages(30) | ||
_ <- Stream | ||
.emits(msgs) | ||
.through(client.publish(queueName).sink(batchSize = 10)) | ||
.compile | ||
.drain | ||
messagesInQueue <- client.statistics(queueName).fetcher.use(_.fetch).map(_.messages) | ||
_ = assertEquals(messagesInQueue, msgs.size) | ||
} yield () | ||
} | ||
|
||
withQueue.test("sink publishes all the messages with a delay") { queueName => | ||
assume(delayedMessagesStatsSupported, "The test environment does not support delayed messages stats") | ||
val client = clientFixture() | ||
for { | ||
msgs <- randomMessages(30) | ||
_ <- Stream | ||
.emits(msgs) | ||
.through(client.publish(queueName).sink(batchSize = 10, delay = 1.minute.some)) | ||
.compile | ||
.drain | ||
statsFetcher = client.statistics(queueName).fetcher | ||
messagesInQueue <- statsFetcher.use(_.fetch).map(_.messages) | ||
delayedMessages <- statsFetcher.use(_.fetch).map(_.delayed) | ||
_ = assertEquals(delayedMessages, msgs.size.some, "delayed messages are not what we expect") | ||
_ = assertEquals(messagesInQueue, 0, "the queue is not empty") | ||
} yield () | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters