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
This commit is contained in:
ejona 2014-11-07 10:02:20 -08:00 committed by Eric Anderson
parent 1553aabb2f
commit 2a93c47657
3 changed files with 94 additions and 0 deletions

View File

@ -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<Messages.SimpleContext> 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;

View File

@ -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();
}
}

View File

@ -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();
}
}