Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

protobuf: updates from George V.

Signed-off-by: marius a. eriksen <marius@twitter.com>
  • Loading branch information...
commit c39bb8c075a00c3c76b70a853d26458fdec82e12 1 parent 59476f9
George Vacariuc authored mariusae committed
View
33 finagle-protobuf/pom.xml
@@ -0,0 +1,33 @@
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.twitter</groupId>
+ <artifactId>finagle-protobuf</artifactId>
+ <packaging>jar</packaging>
+ <version>3.0.1-SNAPSHOT</version>
+ <distributionManagement>
+ <repository>
+ <id>artifactory-release</id>
+ <name>Artifactory Releases</name>
+ <url>http://build:8081/nexus/content/repositories/platform-services</url>
+ </repository>
+ <snapshotRepository>
+ <id>artifactory-snapshot</id>
+ <name>Artifactory Snapshots</name>
+ <url>http://build:8081/nexus/content/repositories/platform-services-snapshot</url>
+ </snapshotRepository>
+ </distributionManagement>
+ <dependencies>
+ <dependency>
+ <groupId>com.twitter</groupId>
+ <artifactId>finagle-core</artifactId>
+ <version>3.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>2.4.1</version>
+ </dependency>
+ </dependencies>
+</project>
View
3  finagle-protobuf/src/main/scala/com/twitter/finagle/protobuf/rpc/RpcFactory.scala
@@ -16,4 +16,7 @@ trait RpcFactory {
def createStub[T <: Service](cb: ClientBuilder[(String, Message), (String, Message), Any, Any, Any], service: { def newStub(c: RpcChannel): T }, executorService: ExecutorService): T
def createController(): RpcController
+
+ def release(stub: { def getChannel(): RpcChannel })
+
}
View
2  finagle-protobuf/src/main/scala/com/twitter/finagle/protobuf/rpc/channel/ProtobufEncoder.scala
@@ -39,8 +39,6 @@ class CustomProtobufEncoder(val repo: MethodLookup) extends OneToOneEncoder {
val msgLenBuf = ChannelBuffers.buffer(4)
msgLenBuf.writeInt(message.length)
- ctx.getPipeline().remove(this)
-
ChannelBuffers.wrappedBuffer(methodNameBuf, msgLenBuf,
ChannelBuffers.wrappedBuffer(message))
}
View
7 finagle-protobuf/src/main/scala/com/twitter/finagle/protobuf/rpc/impl/RpcChannelImpl.scala
@@ -36,8 +36,11 @@ class RpcChannelImpl(cb: ClientBuilder[(String, Message), (String, Message), Any
} onFailure { e =>
log.warn("Failed. ", e)
controller.asInstanceOf[RpcControllerWithOnFailureCallback].setFailed(e)
- } ensure {
- client.release()
}
}
+
+ def release() {
+ client.release()
+ }
+
}
View
4 finagle-protobuf/src/main/scala/com/twitter/finagle/protobuf/rpc/impl/RpcFactoryImpl.scala
@@ -25,4 +25,8 @@ class RpcFactoryImpl extends RpcFactory {
}
def createController(): RpcController = { new RpcControllerWithOnFailureCallback() }
+
+ def release(stub: { def getChannel(): RpcChannel }) {
+ stub.getChannel().asInstanceOf[RpcChannelImpl].release()
+ }
}
View
247 finagle-protobuf/src/test/java/com/twitter/finagle/protobuf/rpc/RpcIntegrationTest.java
@@ -1,247 +0,0 @@
-package com.twitter.finagle.protobuf.rpc;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.TimeoutException;
-
-import org.junit.Test;
-
-import com.google.common.base.Throwables;
-import com.google.protobuf.RpcCallback;
-import com.google.protobuf.RpcController;
-import com.twitter.finagle.protobuf.rpc.RpcControllerWithOnFailureCallback;
-import com.twitter.finagle.protobuf.rpc.RpcFactory;
-import com.twitter.finagle.protobuf.rpc.RpcServer;
-import com.twitter.finagle.protobuf.rpc.impl.RpcFactoryImpl;
-import com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherRequest;
-import com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherResponse;
-import com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastRequest;
-import com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastResponse;
-import com.twitter.finagle.protobuf.rpc.SampleServiceProtos.WeatherService;
-import com.twitter.finagle.builder.ClientBuilder;
-import com.twitter.finagle.builder.ServerBuilder;
-import com.twitter.util.Duration;
-
-public class RpcIntegrationTest {
-
- private static final int MILLIS_PER_SEC = 1000;
-
- private static final int CLIENT_TIMEOUT_SECONDS = 1;
-
- private static final int RPC_OVERHEAD_MILLIS = 300;
-
- private int port = 8080;
-
- private ExecutorService executorService = Executors.newFixedThreadPool(2);
-
- private RpcFactory factory = new RpcFactoryImpl();
-
- private ServerBuilder serverBuilder = ServerBuilder.get()
- .maxConcurrentRequests(10);
-
- private ClientBuilder clientBuilder = ClientBuilder
- .get()
- .hosts(String.format("localhost:%s", port))
- .hostConnectionLimit(1)
- .retries(2)
- .requestTimeout(
- Duration.apply(CLIENT_TIMEOUT_SECONDS, TimeUnit.SECONDS));
-
- @Test
- public void testSuccessfulRequest() throws InterruptedException {
-
- SampleWeatherServiceImpl service = new SampleWeatherServiceImpl(80,
- null);
- RpcServer server = factory.createServer(serverBuilder, port, service,
- executorService);
- WeatherService stub = factory.<WeatherService> createStub(
- clientBuilder, WeatherService.newStub(null), executorService);
-
- RpcControllerWithOnFailureCallback controller = (RpcControllerWithOnFailureCallback) factory
- .createController();
-
- final CountDownLatch l = new CountDownLatch(1);
- final AtomicInteger result = new AtomicInteger();
- GetWeatherForecastRequest request = GetWeatherForecastRequest
- .newBuilder().setZip("80301").build();
- stub.getWeatherForecast(
- controller.onFailure(new RpcCallback<Throwable>() {
-
- @Override
- public void run(Throwable e) {
- }
- }), request, new RpcCallback<GetWeatherForecastResponse>() {
-
- @Override
- public void run(GetWeatherForecastResponse resp) {
- result.set(resp.getTemp());
- l.countDown();
- }
- });
-
- l.await(CLIENT_TIMEOUT_SECONDS + 2, TimeUnit.SECONDS);
- server.close(new Duration(TimeUnit.SECONDS.toNanos(1)));
-
- assertEquals(service.getTemperature(), result.get());
- }
-
- @Test
- public void testMethodWithResponseTimeout() throws InterruptedException {
-
- SampleWeatherServiceImpl service = new SampleWeatherServiceImpl(80,
- new Callable<Void>() {
-
- @Override
- public Void call() throws Exception {
- // force timeout
- Thread.sleep((CLIENT_TIMEOUT_SECONDS * 10) * 1000);
- return null;
- }
- });
- RpcServer server = factory.createServer(serverBuilder, port, service,
- executorService);
- WeatherService stub = factory.<WeatherService> createStub(
- clientBuilder, WeatherService.newStub(null), executorService);
- RpcControllerWithOnFailureCallback controller = (RpcControllerWithOnFailureCallback) factory
- .createController();
-
- final AtomicBoolean processed = new AtomicBoolean(false);
-
- final CountDownLatch l = new CountDownLatch(1);
- GetHistoricWeatherRequest request = GetHistoricWeatherRequest
- .newBuilder().setZip("80301").build();
- long callStartTime = System.currentTimeMillis();
- stub.getHistoricWeather(
- controller.onFailure(new RpcCallback<Throwable>() {
-
- @Override
- public void run(Throwable e) {
- if (e instanceof TimeoutException) {
- processed.set(true);
- l.countDown();
- }
- }
- }), request, new RpcCallback<GetHistoricWeatherResponse>() {
-
- @Override
- public void run(GetHistoricWeatherResponse resp) {
- }
- });
-
- l.await(CLIENT_TIMEOUT_SECONDS + 2, TimeUnit.SECONDS);
- long methodCallDuration = (System.currentTimeMillis() - callStartTime);
- assertTrue(
- "Method call duration ~= client timeout " + methodCallDuration,
- Math.abs(methodCallDuration - CLIENT_TIMEOUT_SECONDS
- * MILLIS_PER_SEC) < RPC_OVERHEAD_MILLIS);
-
- try {
- assertTrue("Expected timeout.", processed.get());
- } finally {
- server.close(new Duration(TimeUnit.SECONDS.toNanos(1)));
- }
- }
-
- @Test
- public void testMethodWithException() throws InterruptedException {
-
- SampleWeatherServiceImpl service = new SampleWeatherServiceImpl(80,
- new Callable<Void>() {
-
- @Override
- public Void call() throws Exception {
- throw new RuntimeException(
- "Cannot connect to the database...");
- }
- });
- RpcServer server = factory.createServer(serverBuilder, port, service,
- executorService);
- WeatherService stub = factory.<WeatherService> createStub(
- clientBuilder, WeatherService.newStub(null), executorService);
- RpcControllerWithOnFailureCallback controller = (RpcControllerWithOnFailureCallback) factory
- .createController();
-
- final AtomicBoolean processed = new AtomicBoolean(false);
-
- final CountDownLatch l = new CountDownLatch(1);
-
- GetHistoricWeatherRequest request = GetHistoricWeatherRequest
- .newBuilder().setZip("80301").build();
- long callStartTime = System.currentTimeMillis();
- stub.getHistoricWeather(
- controller.onFailure(new RpcCallback<Throwable>() {
-
- @Override
- public void run(Throwable e) {
- if (e instanceof RuntimeException) {
- processed.set(true);
- l.countDown();
- }
- }
- }), request, new RpcCallback<GetHistoricWeatherResponse>() {
-
- @Override
- public void run(GetHistoricWeatherResponse resp) {
- }
- });
-
- l.await(CLIENT_TIMEOUT_SECONDS + 2, TimeUnit.SECONDS);
- long methodCallDuration = (System.currentTimeMillis() - callStartTime);
- assertTrue("The exception occured BEFORE the client timeout "
- + methodCallDuration,
- methodCallDuration < CLIENT_TIMEOUT_SECONDS * MILLIS_PER_SEC);
-
- try {
- assertTrue("Expected failure.", processed.get());
- } finally {
- server.close(new Duration(TimeUnit.SECONDS.toNanos(1)));
- }
- }
-
- public class SampleWeatherServiceImpl extends WeatherService {
-
- private final int temperature;
- private final Callable<?> getHistoricWeather;
-
- public SampleWeatherServiceImpl(int temperature,
- Callable<?> getHistoricWeather) {
- super();
- this.temperature = temperature;
- this.getHistoricWeather = getHistoricWeather;
- }
-
- public int getTemperature() {
- return temperature;
- }
-
- @Override
- public void getWeatherForecast(RpcController controller,
- GetWeatherForecastRequest request,
- RpcCallback<GetWeatherForecastResponse> done) {
- done.run(GetWeatherForecastResponse.newBuilder()
- .setTemp(temperature).build());
- }
-
- @Override
- public void getHistoricWeather(RpcController controller,
- GetHistoricWeatherRequest request,
- RpcCallback<GetHistoricWeatherResponse> done) {
- if (this.getHistoricWeather != null) {
- try {
- this.getHistoricWeather.call();
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
- }
-
- }
-}
View
71 finagle-protobuf/src/test/java/com/twitter/finagle/protobuf/rpc/SimpleMethodLookupTest.java
@@ -1,71 +0,0 @@
-package com.twitter.finagle.protobuf.rpc;
-
-import static org.junit.Assert.*;
-
-import java.util.List;
-
-import org.junit.Test;
-
-import com.google.common.collect.Lists;
-import com.twitter.finagle.protobuf.rpc.channel.SimpleMethodLookup;
-
-public class SimpleMethodLookupTest {
-
- @Test
- public void testConstruct() {
- List<String> l = Lists.newArrayList("eat", "drink");
- new SimpleMethodLookup(l) {
-
- @Override
- public int createEncoding(String s) {
- return eatAndEssenCollidingHash(s);
- }
- };
-
- // force a collision
- l.add("essen");
- try {
- new SimpleMethodLookup(l) {
-
- @Override
- public int createEncoding(String s) {
- return eatAndEssenCollidingHash(s);
- }
- };
- fail("Should fail due to collision.");
- } catch (Exception e) {
- }
-
- }
-
- protected int eatAndEssenCollidingHash(String s) {
- if ("eat".equals(s) || "essen".equals(s)) {
- return 1;
- }
- return s.hashCode();
- }
-
- @Test(expected = NoSuchMethodException.class)
- public void testMissingMethod() {
- List<String> l = Lists.newArrayList("doThis");
- SimpleMethodLookup repo = new SimpleMethodLookup(l);
- repo.encode("doesNotExist");
- }
-
- @Test(expected = NoSuchMethodException.class)
- public void testMissingLookupCode() {
- List<String> l = Lists.newArrayList();
- SimpleMethodLookup repo = new SimpleMethodLookup(l);
- repo.lookup(0);
- }
-
- @Test
- public void testHappyPath() {
- List<String> l = Lists.newArrayList("doThis", "doThat");
- SimpleMethodLookup repo = new SimpleMethodLookup(l);
-
- int code = repo.encode("doThis");
- assertEquals("doThis", repo.lookup(code));
- }
-
-}
View
119 finagle-protobuf/src/test/scala/com/twitter/finagle/protobuf/rpc/LoadSpec.scala
@@ -0,0 +1,119 @@
+package com.twitter.finagle.protobuf.rpc
+
+import org.specs.SpecificationWithJUnit
+import org.specs.mock.Mockito
+
+import org.junit.Assert._
+
+import com.google.protobuf._
+import com.google.common.base._
+
+import com.twitter.util._
+import com.twitter.finagle.protobuf.rpc._
+import com.twitter.finagle.protobuf.rpc.impl._
+
+import com.twitter.finagle.protobuf.rpc.SampleServiceProtos._
+import com.twitter.finagle.builder._
+
+import java.util.concurrent._
+import java.util.concurrent.atomic._
+
+object RpcProtobufSpec extends SpecificationWithJUnit {
+
+ def CLIENT_TIMEOUT_SECONDS = 1
+
+ def THREAD_COUNT = 40
+
+ def REQ_PER_THREAD = 100
+
+ def port = 8080
+
+ def executorService = Executors.newFixedThreadPool(4)
+
+ def factory = new RpcFactoryImpl()
+
+ def serverBuilder = ServerBuilder.get().maxConcurrentRequests(10)
+
+ def clientBuilder = ClientBuilder
+ .get()
+ .hosts(String.format("localhost:%s", port.toString()))
+ .hostConnectionLimit(1)
+ .retries(2)
+ .requestTimeout(Duration(CLIENT_TIMEOUT_SECONDS, TimeUnit.SECONDS))
+
+ "A client" should {
+
+ val totalRequests = new AtomicInteger()
+
+ val service = new SampleWeatherServiceImpl(80, null)
+ val server = factory.createServer(serverBuilder.asInstanceOf[ServerBuilder[(String, com.google.protobuf.Message),(String, com.google.protobuf.Message),Any,Any,Any]], port, service, executorService)
+ val stub = factory.createStub(clientBuilder.asInstanceOf[ClientBuilder[(String, com.google.protobuf.Message),(String, com.google.protobuf.Message),Any,Any,Any]], WeatherService.newStub(null).asInstanceOf[{ def newStub(c: RpcChannel): WeatherService }], executorService)
+
+ val finishBarrier = new CyclicBarrier(THREAD_COUNT + 1)
+ val startBarrier = new CyclicBarrier(THREAD_COUNT)
+
+ for (i <- 0 until THREAD_COUNT) {
+ new Thread(new Runnable() {
+ def run() {
+ startBarrier.await();
+ try {
+ for (k <- 0 until REQ_PER_THREAD) {
+ makeRequest(service, stub, totalRequests)
+ }
+ }
+ finally {
+ finishBarrier.await(60l, TimeUnit.SECONDS)
+ }
+ }
+ }).start()
+ }
+ finishBarrier.await(60l, TimeUnit.SECONDS)
+ server.close(Duration(1, TimeUnit.SECONDS))
+
+ "receive THREAD_COUNT * REQ_PER_THREAD responses." in {
+ THREAD_COUNT * REQ_PER_THREAD mustEqual totalRequests.get()
+ }
+
+ }
+
+
+ def makeRequest(service: SampleWeatherServiceImpl, stub: WeatherService, totalRequests: AtomicInteger) {
+ val controller = factory.createController().asInstanceOf[RpcControllerWithOnFailureCallback]
+
+ val l = new java.util.concurrent.CountDownLatch(1);
+ val request = GetWeatherForecastRequest.newBuilder().setZip("80301").build()
+ stub.getWeatherForecast(controller.onFailure(new RpcCallback[Throwable]() {
+
+ def run(e: Throwable) {
+ l.countDown()
+ }
+ }), request, new RpcCallback[GetWeatherForecastResponse]() {
+
+ def run(resp: GetWeatherForecastResponse) {
+ totalRequests.incrementAndGet()
+ l.countDown()
+ }
+ });
+
+ l.await(CLIENT_TIMEOUT_SECONDS + 2, TimeUnit.SECONDS)
+ }
+}
+
+
+class SampleWeatherServiceImpl(val temperature: Int, val getHistoricWeather: Callable[Any]) extends WeatherService {
+
+ def getTemperature() = temperature
+
+ def getWeatherForecast(controller: RpcController, request: GetWeatherForecastRequest, done:
+ RpcCallback[GetWeatherForecastResponse]) {
+ done.run(GetWeatherForecastResponse.newBuilder().setTemp(temperature).build())
+ }
+
+ def getHistoricWeather(controller: RpcController, request: GetHistoricWeatherRequest,
+ done: RpcCallback[GetHistoricWeatherResponse]) {
+ if (getHistoricWeather != null) {
+ getHistoricWeather.call()
+ }
+ }
+
+}
View
102 ...ter/finagle/protobuf/rpc/SampleServiceProtos.java → ...ter/finagle/protobuf/rpc/SampleServiceProtos.java
@@ -35,12 +35,12 @@ public GetWeatherForecastRequest getDefaultInstanceForType() {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_fieldAccessorTable;
}
private int bitField0_;
@@ -204,12 +204,12 @@ protected Builder newBuilderForType(
implements com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastRequestOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_fieldAccessorTable;
}
// Construct using com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastRequest.newBuilder()
@@ -414,12 +414,12 @@ public GetWeatherForecastResponse getDefaultInstanceForType() {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_fieldAccessorTable;
}
private int bitField0_;
@@ -601,12 +601,12 @@ protected Builder newBuilderForType(
implements com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastResponseOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_fieldAccessorTable;
}
// Construct using com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastResponse.newBuilder()
@@ -842,12 +842,12 @@ public GetHistoricWeatherRequest getDefaultInstanceForType() {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_fieldAccessorTable;
}
private int bitField0_;
@@ -1011,12 +1011,12 @@ protected Builder newBuilderForType(
implements com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherRequestOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_fieldAccessorTable;
}
// Construct using com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherRequest.newBuilder()
@@ -1221,12 +1221,12 @@ public GetHistoricWeatherResponse getDefaultInstanceForType() {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_fieldAccessorTable;
}
private int bitField0_;
@@ -1408,12 +1408,12 @@ protected Builder newBuilderForType(
implements com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherResponseOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_descriptor;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
- return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_fieldAccessorTable;
+ return com.twitter.finagle.protobuf.rpc.SampleServiceProtos.internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_fieldAccessorTable;
}
// Construct using com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherResponse.newBuilder()
@@ -1909,25 +1909,25 @@ private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {
}
private static com.google.protobuf.Descriptors.Descriptor
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_descriptor;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_descriptor;
private static
com.google.protobuf.GeneratedMessage.FieldAccessorTable
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_fieldAccessorTable;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_fieldAccessorTable;
private static com.google.protobuf.Descriptors.Descriptor
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_descriptor;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_descriptor;
private static
com.google.protobuf.GeneratedMessage.FieldAccessorTable
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_fieldAccessorTable;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_fieldAccessorTable;
private static com.google.protobuf.Descriptors.Descriptor
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_descriptor;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_descriptor;
private static
com.google.protobuf.GeneratedMessage.FieldAccessorTable
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_fieldAccessorTable;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_fieldAccessorTable;
private static com.google.protobuf.Descriptors.Descriptor
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_descriptor;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_descriptor;
private static
com.google.protobuf.GeneratedMessage.FieldAccessorTable
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_fieldAccessorTable;
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
@@ -1937,56 +1937,56 @@ private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {
descriptor;
static {
java.lang.String[] descriptorData = {
- "\n\033sample-service-protos.proto\022$com.tendr" +
- "il.platform.services.sample\"(\n\031GetWeathe" +
- "rForecastRequest\022\013\n\003zip\030\001 \001(\t\"7\n\032GetWeat" +
- "herForecastResponse\022\013\n\003zip\030\001 \001(\t\022\014\n\004temp" +
- "\030\002 \001(\r\"(\n\031GetHistoricWeatherRequest\022\013\n\003z" +
- "ip\030\001 \001(\t\"7\n\032GetHistoricWeatherResponse\022\013" +
- "\n\003zip\030\001 \001(\t\022\014\n\004temp\030\002 \001(\r2\304\002\n\016WeatherSer" +
- "vice\022\227\001\n\022GetWeatherForecast\022?.com.tendri" +
- "l.platform.services.sample.GetWeatherFor" +
- "ecastRequest\032@.com.twitter.platform.serv",
- "ices.sample.GetWeatherForecastResponse\022\227" +
- "\001\n\022GetHistoricWeather\022?.com.twitter.plat" +
- "form.services.sample.GetHistoricWeatherR" +
- "equest\032@.com.twitter.platform.services.s" +
- "ample.GetHistoricWeatherResponseB\003\210\001\001"
+ "\n\033sample-service-protos.proto\022 com.twitt" +
+ "er.finagle.protobuf.rpc\"(\n\031GetWeatherFor" +
+ "ecastRequest\022\013\n\003zip\030\001 \001(\t\"7\n\032GetWeatherF" +
+ "orecastResponse\022\013\n\003zip\030\001 \001(\t\022\014\n\004temp\030\002 \001" +
+ "(\r\"(\n\031GetHistoricWeatherRequest\022\013\n\003zip\030\001" +
+ " \001(\t\"7\n\032GetHistoricWeatherResponse\022\013\n\003zi" +
+ "p\030\001 \001(\t\022\014\n\004temp\030\002 \001(\r2\264\002\n\016WeatherService" +
+ "\022\217\001\n\022GetWeatherForecast\022;.com.twitter.fi" +
+ "nagle.protobuf.rpc.GetWeatherForecastReq" +
+ "uest\032<.com.twitter.finagle.protobuf.rpc.",
+ "GetWeatherForecastResponse\022\217\001\n\022GetHistor" +
+ "icWeather\022;.com.twitter.finagle.protobuf" +
+ ".rpc.GetHistoricWeatherRequest\032<.com.twi" +
+ "tter.finagle.protobuf.rpc.GetHistoricWea" +
+ "therResponseB\003\210\001\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
public com.google.protobuf.ExtensionRegistry assignDescriptors(
com.google.protobuf.Descriptors.FileDescriptor root) {
descriptor = root;
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_descriptor =
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_descriptor =
getDescriptor().getMessageTypes().get(0);
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_fieldAccessorTable = new
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastRequest_descriptor,
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastRequest_descriptor,
new java.lang.String[] { "Zip", },
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastRequest.class,
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastRequest.Builder.class);
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_descriptor =
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_descriptor =
getDescriptor().getMessageTypes().get(1);
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_fieldAccessorTable = new
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
- internal_static_com_twitter_platform_services_sample_GetWeatherForecastResponse_descriptor,
+ internal_static_com_twitter_finagle_protobuf_rpc_GetWeatherForecastResponse_descriptor,
new java.lang.String[] { "Zip", "Temp", },
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastResponse.class,
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetWeatherForecastResponse.Builder.class);
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_descriptor =
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_descriptor =
getDescriptor().getMessageTypes().get(2);
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_fieldAccessorTable = new
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherRequest_descriptor,
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherRequest_descriptor,
new java.lang.String[] { "Zip", },
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherRequest.class,
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherRequest.Builder.class);
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_descriptor =
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_descriptor =
getDescriptor().getMessageTypes().get(3);
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_fieldAccessorTable = new
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
- internal_static_com_twitter_platform_services_sample_GetHistoricWeatherResponse_descriptor,
+ internal_static_com_twitter_finagle_protobuf_rpc_GetHistoricWeatherResponse_descriptor,
new java.lang.String[] { "Zip", "Temp", },
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherResponse.class,
com.twitter.finagle.protobuf.rpc.SampleServiceProtos.GetHistoricWeatherResponse.Builder.class);
View
67 finagle-protobuf/src/test/scala/com/twitter/finagle/protobuf/rpc/SimpleMethodLookupSpec.scala
@@ -0,0 +1,67 @@
+package com.twitter.finagle.protobuf.rpc
+
+import org.specs.SpecificationWithJUnit
+import org.specs.mock.Mockito
+
+import org.junit.Assert._
+
+import java.util.List
+
+import org.junit.Test
+
+import com.google.common.collect.Lists
+import com.twitter.finagle.protobuf.rpc.channel.SimpleMethodLookup
+
+object SimpleMethodLookupSpec extends SpecificationWithJUnit {
+
+ "A method lookup" should {
+
+ "find no collisions for eat, drink" in {
+ val l = Lists.newArrayList("eat", "drink")
+ var collision = false
+ try {
+ new SimpleMethodLookup(l) {
+ override def createEncoding(s: String) : Int = {
+ eatAndEssenCollidingHash(s);
+ }
+ }
+ } catch {
+ case e: IllegalArgumentException => collision = true
+ }
+ collision must beFalse
+ }
+
+ "find collisions for eat, essen, drink" in {
+ val l = Lists.newArrayList("eat", "essen", "drink")
+ var collision = false
+ try {
+ new SimpleMethodLookup(l) {
+
+ override def createEncoding(s: String) : Int = {
+ eatAndEssenCollidingHash(s)
+ }
+ }
+ } catch {
+ case e: IllegalArgumentException => collision = true
+ }
+ collision must beTrue
+ }
+
+ "find a valid method" in {
+ val l = Lists.newArrayList("doThis", "doThat")
+ val repo = new SimpleMethodLookup(l)
+ val code = repo.encode("doThis")
+ repo.lookup(code) mustEqual "doThis"
+ }
+
+ }
+
+ def eatAndEssenCollidingHash(s: String) : Int = {
+ if ("eat".equals(s) || "essen".equals(s)) {
+ return 1
+ }
+ return s.hashCode()
+ }
+
+ }
+
Please sign in to comment.
Something went wrong with that request. Please try again.