in finagle-benchmark/src/main/scala/com/twitter/finagle/thrift/ThriftGenBenchmark.scala [36:119]
def setup() = {
javaRequest = new TJavaRequest(
Int.MaxValue,
Long.MaxValue,
false,
"hello",
Seq.fill(collectionSize)("hello").asJava,
Map(new Integer(Int.MaxValue) -> "hello").asJava,
Seq.fill(collectionSize)(new java.lang.Long(Long.MaxValue)).toSet.asJava
)
scalaRequest = TScalaRequest(
Int.MaxValue,
Long.MaxValue,
false,
"hello",
Seq.fill(collectionSize)("hello"),
Map(Int.MaxValue -> "hello"),
Seq.fill(collectionSize)(Long.MaxValue).toSet
)
// use a mock service to get the request bytes so we don't need to
// write the request to a thrift buffer manually
val echoScalaSvc = new Service[ThriftClientRequest, Array[Byte]] {
def apply(treq: ThriftClientRequest) = {
thriftRequestBytes = treq.message
// Throw an exception since it requires us to put a properly
// serialized response. It is OK to throw an exception since
// all we want is the serialized request.
Future.exception(new Exception("boom"))
}
}
val scalaIface =
new TScalaThriftOneGenServer.FinagledClient(echoScalaSvc, new TBinaryProtocol.Factory())
// the mock service will throw an exception
try { Await.result(scalaIface.echo(scalaRequest)) }
catch { case _: Throwable => }
scalaServer = {
val impl = new TScalaThriftOneGenServer.MethodPerEndpoint {
val scalaResponse = TScalaResponse(
Int.MaxValue,
Long.MaxValue,
false,
"hello",
Seq.fill(collectionSize)("hello"),
Map(Int.MaxValue -> "hello"),
Seq.fill(collectionSize)(Long.MaxValue).toSet
)
def echo(r: TScalaRequest) = Future.value(scalaResponse)
}
new TScalaThriftOneGenServer.FinagledService(impl, new TBinaryProtocol.Factory())
}
val thriftResponseBytes = Await.result(scalaServer(thriftRequestBytes))
scalaClient = new TScalaThriftOneGenServer.FinagledClient(
new Service[ThriftClientRequest, Array[Byte]] {
def apply(treq: ThriftClientRequest) = {
Future.value(thriftResponseBytes)
}
},
new TBinaryProtocol.Factory())
javaServer = {
val impl = new TJavaThriftOneGenServer.ServiceIface {
val javaResponse = new TJavaResponse(
Int.MaxValue,
Long.MaxValue,
false,
"hello",
Seq.fill(collectionSize)("hello").asJava,
Map(new Integer(Int.MaxValue) -> "hello").asJava,
Seq.fill(collectionSize)(new java.lang.Long(Long.MaxValue)).toSet.asJava
)
def echo(r: TJavaRequest) = Future.value(javaResponse)
}
new TJavaThriftOneGenServer.Service(impl, new TBinaryProtocol.Factory())
}
javaClient = new TJavaThriftOneGenServer.ServiceToClient(
new Service[ThriftClientRequest, Array[Byte]] {
def apply(req: ThriftClientRequest) = Future.value(thriftResponseBytes)
},
new TBinaryProtocol.Factory())
}