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
namespace com.github.reikje | |
service MicroService { | |
string request() | |
} |
using Scrooge or the scrooge-sbt-plugin, this is a ScalaTest that does exactly that.
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
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) | |
} |