From 2a93c4765745676c670936852be4bcd03e81e0b5 Mon Sep 17 00:00:00 2001 From: ejona Date: Fri, 7 Nov 2014 10:02:20 -0800 Subject: [PATCH] Remove GrpcServer to allow more tests to move to third_party. GrpcServer had the same restriction that GrpcClient did: it had a single enum of all transports that prevents using it in third_party. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=79428440 --- .../integration/AbstractTransportTest.java | 23 ++++++++++++ .../testing/integration/Http2NettyTest.java | 35 ++++++++++++++++++ .../testing/integration/Http2OkHttpTest.java | 36 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2NettyTest.java create mode 100644 integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2OkHttpTest.java diff --git a/integration-testing/src/main/java/com/google/net/stubby/testing/integration/AbstractTransportTest.java b/integration-testing/src/main/java/com/google/net/stubby/testing/integration/AbstractTransportTest.java index 2acd28d050..5e6019151f 100644 --- a/integration-testing/src/main/java/com/google/net/stubby/testing/integration/AbstractTransportTest.java +++ b/integration-testing/src/main/java/com/google/net/stubby/testing/integration/AbstractTransportTest.java @@ -10,14 +10,18 @@ import com.google.common.base.Throwables; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import com.google.common.util.concurrent.Uninterruptibles; +import com.google.net.stubby.AbstractServerBuilder; import com.google.net.stubby.Call; import com.google.net.stubby.ChannelImpl; import com.google.net.stubby.Metadata; +import com.google.net.stubby.ServerImpl; +import com.google.net.stubby.ServerInterceptors; import com.google.net.stubby.Status; import com.google.net.stubby.proto.ProtoUtils; import com.google.net.stubby.stub.MetadataUtils; import com.google.net.stubby.stub.StreamObserver; import com.google.net.stubby.stub.StreamRecorder; +import com.google.net.stubby.testing.TestUtils; import com.google.net.stubby.testing.integration.Messages.Payload; import com.google.net.stubby.testing.integration.Messages.PayloadType; import com.google.net.stubby.testing.integration.Messages.ResponseParameters; @@ -43,6 +47,8 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Random; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -54,6 +60,23 @@ public abstract class AbstractTransportTest { public static final Metadata.Key METADATA_KEY = ProtoUtils.keyForProto(Messages.SimpleContext.getDefaultInstance()); + private static ScheduledExecutorService testServiceExecutor; + private static ServerImpl server; + + protected static void startStaticServer(AbstractServerBuilder builder) { + testServiceExecutor = Executors.newScheduledThreadPool(2); + + server = builder + .addService(ServerInterceptors.intercept( + TestServiceGrpc.bindService(new TestServiceImpl(testServiceExecutor)), + TestUtils.echoRequestHeadersInterceptor(Util.METADATA_KEY))) + .buildAndWaitForRunning(); + } + + protected static void stopStaticServer() { + server.stopAsync(); + testServiceExecutor.shutdown(); + } protected ChannelImpl channel; protected TestServiceGrpc.TestServiceBlockingStub blockingStub; diff --git a/integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2NettyTest.java b/integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2NettyTest.java new file mode 100644 index 0000000000..62c2360986 --- /dev/null +++ b/integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2NettyTest.java @@ -0,0 +1,35 @@ +package com.google.net.stubby.testing.integration; + +import com.google.net.stubby.ChannelImpl; +import com.google.net.stubby.transport.netty.NegotiationType; +import com.google.net.stubby.transport.netty.NettyChannelBuilder; +import com.google.net.stubby.transport.netty.NettyServerBuilder; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Integration tests for GRPC over HTTP2 using the Netty framework. + */ +@RunWith(JUnit4.class) +public class Http2NettyTest extends AbstractTransportTest { + private static int serverPort = Util.pickUnusedPort(); + + @BeforeClass + public static void startServer() { + startStaticServer(NettyServerBuilder.forPort(serverPort)); + } + + @AfterClass + public static void stopServer() { + stopStaticServer(); + } + + @Override + protected ChannelImpl createChannel() { + return NettyChannelBuilder.forAddress("127.0.0.1", serverPort) + .negotiationType(NegotiationType.PLAINTEXT).build(); + } +} diff --git a/integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2OkHttpTest.java b/integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2OkHttpTest.java new file mode 100644 index 0000000000..c0230d9324 --- /dev/null +++ b/integration-testing/src/test/java/com/google/net/stubby/testing/integration/Http2OkHttpTest.java @@ -0,0 +1,36 @@ +package com.google.net.stubby.testing.integration; + +import com.google.net.stubby.ChannelImpl; +import com.google.net.stubby.transport.AbstractStream; +import com.google.net.stubby.transport.netty.NettyServerBuilder; +import com.google.net.stubby.transport.okhttp.OkHttpChannelBuilder; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Integration tests for GRPC over Http2 using the OkHttp framework. + */ +@RunWith(JUnit4.class) +public class Http2OkHttpTest extends AbstractTransportTest { + private static int serverPort = Util.pickUnusedPort(); + + @BeforeClass + public static void startServer() throws Exception { + AbstractStream.GRPC_V2_PROTOCOL = true; + startStaticServer(NettyServerBuilder.forPort(serverPort)); + } + + @AfterClass + public static void stopServer() throws Exception { + stopStaticServer(); + AbstractStream.GRPC_V2_PROTOCOL = false; + } + + @Override + protected ChannelImpl createChannel() { + return OkHttpChannelBuilder.forAddress("127.0.0.1", serverPort).build(); + } +}