Instantly share code, notes, and snippets.

Embed
What would you like to do?
Always sees only a single transport being created, is there a better way to check (programmaticaly) how many connections were created?
it should "call createTransport only once when sharing sessions" in {
val counter = new AtomicInteger
val spied =
(x: Stack.Params) => {
counter.incrementAndGet()
Http.client.params[HttpImpl].transporter(x)
}
val myClient =
Http.client
.configured(Http.client.params[HttpImpl].copy(transporter = spied))
.withStack(
Http.client.stack
.replace(DefaultPool.Role, module[Request, Response])
.remove(DefaultPool.Role.bufferingPool)
.remove(DefaultPool.Role.cachingPool)
.remove(DefaultPool.Role.watermarkPool)
.remove(StackClient.Role.pool)
)
val service =
Service.const(Future.value(Response()))
val server =
com.twitter.finagle.Http.server.serve(":*", service)
val connection =
myClient.newService(FinagleUtil.socketsToName(server.boundAddress), "single-transport-created")
Await.ready(connection(Request()))
Await.ready(connection(Request()))
counter.get() shouldBe 2
Await.all(server.close(), connection.close())
}
def module[Req, Rep]: Stackable[ServiceFactory[Req, Rep]] =
new Stack.Module[ServiceFactory[Req, Rep]] {
override def make(params: Stack.Params, next: Stack[ServiceFactory[Req, Rep]]): Stack[ServiceFactory[Req, Rep]] = next
override def role: Stack.Role = DefaultPool.Role
override def description: String = "NoOpFactory"
override def parameters: Seq[Stack.Param[_]] = Seq()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment