-
Notifications
You must be signed in to change notification settings - Fork 40
/
ExchangeSubscriberBlackboxSpec.scala
44 lines (31 loc) · 1.75 KB
/
ExchangeSubscriberBlackboxSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package io.scalac.amqp.impl
import scala.concurrent.duration._
import akka.actor.ActorSystem
import akka.stream.ActorFlowMaterializer
import akka.stream.scaladsl.{Source, Sink}
import io.scalac.amqp.{Message, Connection, Routed}
import org.reactivestreams.tck.{TestEnvironment, SubscriberBlackboxVerification}
import org.scalatest.testng.TestNGSuiteLike
import org.testng.annotations.AfterSuite
class ExchangeSubscriberBlackboxSpec(defaultTimeout: FiniteDuration) extends SubscriberBlackboxVerification[Routed](
new TestEnvironment(defaultTimeout.toMillis)) with TestNGSuiteLike {
def this() = this(300.millis)
val connection = Connection()
implicit val system = ActorSystem()
implicit val mat = ActorFlowMaterializer()
@AfterSuite def cleanup() = system.shutdown()
override def createSubscriber() = connection.publish("nowhere")
val message = Routed(routingKey = "foo", message = Message())
def createHelperSource(elements: Long): Source[Routed, Unit] = elements match {
/** if `elements` is 0 the `Publisher` should signal `onComplete` immediately. */
case 0 ⇒ Source.empty
/** if `elements` is [[Long.MaxValue]] the produced stream must be infinite. */
case Long.MaxValue ⇒ Source(() ⇒ Iterator.continually(message))
/** It must create a `Publisher` for a stream with exactly the given number of elements. */
case n if n <= Int.MaxValue ⇒ Source(List.fill(n.toInt)(message))
/** I assume that the number of elements is always less or equal to [[Int.MaxValue]] */
case n ⇒ sys.error("n > Int.MaxValue")
}
override def createHelperPublisher(elements: Long) = createHelperSource(elements).runWith(Sink.publisher)
override def createElement(element: Int) = message
}