Skip to content

Commit

Permalink
finagle-{thrift,mux,thriftmux}: minimal cross-build 213
Browse files Browse the repository at this point in the history
Problem

No 2.13 cross-building for finagle-thrift, finagle-mux and finagle-thrift-mux

Solution

Cross-build.

Signed-off-by: David Rusek <drusek@twitter.com>

Differential Revision: https://phabricator.twitter.biz/D373165
  • Loading branch information
martijnhoekstra authored and jenkins committed Sep 26, 2019
1 parent 2fc241d commit 47ee31f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Unreleased
New Features
~~~~~~~~~~~~

* finagle-{mux,thrift,thrift-mux}: Enables cross-build for 2.13.0. ``PHAB_ID=D373165``

* finagle-tunable: Enables cross-build for 2.13.0. ``PHAB_ID=D373170``

* finagle-grpc-context: Enables cross-build for 2.13.0. ``PHAB_ID=D373168``
Expand Down
9 changes: 6 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ lazy val finagleThrift = Project(
id = "finagle-thrift",
base = file("finagle-thrift")
).settings(
sharedSettings
sharedSettings,
withTwoThirteen
).settings(
name := "finagle-thrift",
libraryDependencies ++= scroogeLibs
Expand Down Expand Up @@ -674,7 +675,8 @@ lazy val finagleMux = Project(
id = "finagle-mux",
base = file("finagle-mux")
).settings(
sharedSettings
sharedSettings,
withTwoThirteen
).settings(
name := "finagle-mux",
libraryDependencies ++= Seq(
Expand All @@ -691,7 +693,8 @@ lazy val finagleThriftMux = Project(
id = "finagle-thriftmux",
base = file("finagle-thriftmux")
).settings(
sharedSettings
sharedSettings,
withTwoThirteen
).settings(
name := "finagle-thriftmux",
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.twitter.finagle.mux

import com.twitter.io.{Buf, ByteReader, ByteWriter}
import scala.collection.mutable.ArrayBuffer
import scala.collection.compat.immutable.ArraySeq

/**
* Encoder and decoder for mux contexts
Expand Down Expand Up @@ -41,7 +42,7 @@ private[mux] object ContextCodec {
// We don't know the precise size and we don't try to guess.
val acc = new ArrayBuffer[(Buf, Buf)]()
decodeToBuffer(br, Int.MaxValue, acc)
acc
ArraySeq.unsafeWrapArray(acc.toArray)
}

/**
Expand All @@ -53,7 +54,7 @@ private[mux] object ContextCodec {
def decode(br: ByteReader, count: Int): Seq[(Buf, Buf)] = {
val acc = new ArrayBuffer[(Buf, Buf)](count)
decodeToBuffer(br, count, acc)
acc
ArraySeq.unsafeWrapArray(acc.toArray)
}

private def decodeToBuffer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.twitter.finagle.{Dentry, Dtab, Failure, NameTree, Path}
import com.twitter.io.{Buf, BufByteWriter, ByteReader}
import com.twitter.util.{Duration, Future, Time}
import java.nio.charset.{StandardCharsets => Charsets}
import scala.collection.mutable.ArrayBuffer
import scala.collection.compat.immutable.ArraySeq

/**
* Indicates that encoding or decoding of a Mux message failed.
Expand Down Expand Up @@ -140,13 +140,13 @@ private[finagle] object Message {

def decode(br: ByteReader): (Short, Seq[(Buf, Buf)]) = {
val version = br.readShortBE()
val headers = new ArrayBuffer[(Buf, Buf)]
val headers = ArraySeq.newBuilder[(Buf, Buf)]
while (br.remaining > 0) {
val k = br.readBytes(br.readIntBE())
val v = br.readBytes(br.readIntBE())
headers += (k -> v)
}
(version.toShort, headers)
(version.toShort, headers.result())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ abstract class AbstractEndToEndTest
for (n <- 0 until 2) {
val rsp = Await.result(client(Request(Path.empty, Nil, Buf.Empty)), 30.seconds)
val Buf.Utf8(str) = rsp.body
assert(str == "Dtab(2)\n\t/foo => /bar\n\t/web => /$/inet/twitter.com/80\n")
assert(
str.replace("\r", "") == "Dtab(2)\n\t/foo => /bar\n\t/web => /$/inet/twitter.com/80\n")
}
}
Await.result(server.close(), 5.seconds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.twitter.finagle.param.{
import com.twitter.finagle.server.{Listener, StackServer, StdStackServer}
import com.twitter.finagle.service.{ResponseClassifier, RetryBudget}
import com.twitter.finagle.stats.{ExceptionStatsHandler, StatsReceiver}
import com.twitter.finagle.thrift.{ClientId => _, _}
import com.twitter.finagle.thrift.{ClientId => FinagleClientId, _}
import com.twitter.finagle.thrift.service.ThriftResponseClassifier
import com.twitter.finagle.thrift.transport.ThriftClientPreparer
import com.twitter.finagle.thrift.transport.netty4.Netty4Transport
Expand Down Expand Up @@ -137,7 +137,7 @@ object Thrift

val maxThriftBufferSize: Int = 16 * 1024

case class ClientId(clientId: Option[thrift.ClientId])
case class ClientId(clientId: Option[FinagleClientId])
implicit object ClientId extends Stack.Param[ClientId] {
val default = ClientId(None)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ object Thrift
def withProtocolFactory(protocolFactory: TProtocolFactory): Client =
configured(param.ProtocolFactory(protocolFactory))

def withClientId(clientId: thrift.ClientId): Client =
def withClientId(clientId: FinagleClientId): Client =
configured(Thrift.param.ClientId(Some(clientId)))

/**
Expand Down Expand Up @@ -303,7 +303,7 @@ object Thrift
def withPerEndpointStats: Client =
configured(param.PerEndpointStats(true))

def clientId: Option[thrift.ClientId] = params[Thrift.param.ClientId].clientId
def clientId: Option[FinagleClientId] = params[Thrift.param.ClientId].clientId

private[this] def withDeserializingClassifier: Client = {
// Note: what type of deserializer used is important if none is specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.twitter.finagle.stats.{
NullStatsReceiver,
StatsReceiver
}
import com.twitter.finagle.thrift.{ClientId => FinagleClientId}
import com.twitter.finagle.thrift.service.ThriftResponseClassifier
import com.twitter.finagle.thrift.thriftscala._
import com.twitter.finagle.tracing.{Annotation, Record, Trace}
Expand Down Expand Up @@ -82,7 +83,7 @@ class EndToEndTest extends FunSuite with ThriftTest with BeforeAndAfter {
def servers(serverParam: RichServerParam): Seq[(String, Closable, Int)] = {
val iface = new BServiceImpl {
override def show_me_your_dtab(): Future[String] = {
ClientId.current.map(_.name) match {
FinagleClientId.current.map(_.name) match {
case Some(name) => Future.value(name)
case _ => Future.exception(missingClientIdEx)
}
Expand All @@ -109,7 +110,7 @@ class EndToEndTest extends FunSuite with ThriftTest with BeforeAndAfter {

def clients(
pf: TProtocolFactory,
clientId: Option[ClientId],
clientId: Option[FinagleClientId],
port: Int
): Seq[(String, B.ServiceIface, Closable)] = {
val dest = s"localhost:$port"
Expand Down Expand Up @@ -137,7 +138,7 @@ class EndToEndTest extends FunSuite with ThriftTest with BeforeAndAfter {
// While we're supporting both old & new APIs, test the cross-product
test("Mix of client and server creation styles") {
for {
clientId <- Seq(Some(ClientId("anClient")), None)
clientId <- Seq(Some(FinagleClientId("anClient")), None)
pf <- Seq(Protocols.binaryFactory(), new TCompactProtocol.Factory())
(serverWhich, serverClosable, port) <- servers(RichServerParam(pf))
} {
Expand Down Expand Up @@ -1196,7 +1197,7 @@ class EndToEndTest extends FunSuite with ThriftTest with BeforeAndAfter {
val pf = Protocols.binaryFactory()
val iface = new BServiceImpl {
override def someway(): Future[Void] = {
ClientId.current.map(_.name) match {
FinagleClientId.current.map(_.name) match {
case Some(name) => Future.exception(presentClientIdEx)
case _ => Future.Void
}
Expand All @@ -1210,7 +1211,7 @@ class EndToEndTest extends FunSuite with ThriftTest with BeforeAndAfter {
val client = Thrift.client
.configured(Stats(sr))
.withProtocolFactory(pf)
.withClientId(ClientId("aClient"))
.withClientId(FinagleClientId("aClient"))
.withNoAttemptTTwitterUpgrade
.build[B.ServiceIface](
Name.bound(Address(server.boundAddress.asInstanceOf[InetSocketAddress])),
Expand Down

0 comments on commit 47ee31f

Please sign in to comment.