-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finagle-core: Provide a mechanism for injecting a parameter in all cl…
…ients Problem Although it's possible to inject a parameter across all clients/servers with a StackTransformer, it's quite error-prone, and it means that we need to consider *when* to inject it. Solution Add a special mechanism just for injecting parameters. JIRA Issues: CSL-9959 Differential Revision: https://phabricator.twitter.biz/D574861
- Loading branch information
Showing
10 changed files
with
125 additions
and
32 deletions.
There are no files selected for viewing
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
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
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
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
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
1 change: 1 addition & 0 deletions
1
finagle-core/src/test/resources/META-INF/services/com.twitter.finagle.ClientParamsInjector
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.twitter.finagle.client.TestClientParamsInjector |
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
9 changes: 9 additions & 0 deletions
9
finagle-core/src/test/scala/com/twitter/finagle/client/TestClientParamsInjector.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.twitter.finagle.client | ||
|
||
import com.twitter.finagle.{ClientParamsInjector, Stack} | ||
import com.twitter.finagle.util.TestParam | ||
|
||
class TestClientParamsInjector extends ClientParamsInjector { | ||
def name: String = "test-injector" | ||
def apply(params: Stack.Params): Stack.Params = params + TestParam(37) | ||
} |
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
31 changes: 31 additions & 0 deletions
31
finagle-core/src/test/scala/com/twitter/finagle/util/params.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.twitter.finagle.util | ||
|
||
import com.twitter.finagle.Stack | ||
import com.twitter.util.Var | ||
|
||
case class TestParam(p1: Int) { | ||
def mk() = (this, TestParam.param) | ||
} | ||
object TestParam { | ||
implicit val param = Stack.Param(TestParam(1)) | ||
} | ||
|
||
case class TestParam2(p2: Int) { | ||
def mk() = (this, TestParam2.param) | ||
} | ||
object TestParam2 { | ||
implicit val param = Stack.Param(TestParam2(1)) | ||
} | ||
|
||
class NotCaseClassParam(val ncc: Var[Int]) { | ||
def mk() = (this, NotCaseClassParam.param) | ||
|
||
} | ||
object NotCaseClassParam { | ||
implicit val param = new Stack.Param[NotCaseClassParam] { | ||
val default = new NotCaseClassParam(Var(3)) | ||
override def show(p: NotCaseClassParam): Seq[(String, () => String)] = | ||
Seq(("ncc", () => p.ncc.sample().toString)) | ||
} | ||
} | ||
|