Skip to content

Instantly share code, notes, and snippets.

@reikje
Created February 14, 2017 12:11
Show Gist options
  • Save reikje/898d3050cd960b2e7d47be3e02d187cd to your computer and use it in GitHub Desktop.
Save reikje/898d3050cd960b2e7d47be3e02d187cd to your computer and use it in GitHub Desktop.
package com.github.reikje
import java.net.{InetAddress, InetSocketAddress}
import com.twitter.finagle.{Address, Name, ThriftMux, param}
import com.twitter.util.{Await, Future}
import org.scalatest.{Matchers, WordSpec}
class RoundtripSpec extends WordSpec with Matchers {
"Microservice" should {
"respond to requests" in {
val service = new MicroServiceImpl("foo")
val server = ThriftMux.server
.configured(param.Label("zuul-thrift"))
.serveIface(new InetSocketAddress(InetAddress.getLoopbackAddress, 0), service)
val client = ThriftMux.client.newIface[MicroService.FutureIface](
Name.bound(Address(server.boundAddress.asInstanceOf[InetSocketAddress])), "microservice-client"
)
val response = Await.result(client.request())
response shouldBe "foo"
}
}
}
class MicroServiceImpl(response: String) extends MicroService.FutureIface {
override def request(): Future[String] = Future.value(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment