Update integration tests.
1. Use okhttp client transport for okhttp tests.
2. Utilize GrpcClient to construct channel according to the transport type.
3. Remove the unused middle layer abstract tests after above changes.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=72732333
diff --git a/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransport.java b/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransport.java
index b4e9f68..6acddf8 100644
--- a/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransport.java
+++ b/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransport.java
@@ -40,8 +40,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.Executor;
import javax.annotation.concurrent.GuardedBy;
@@ -83,7 +82,7 @@
private int nextStreamId;
private final Map<Integer, OkHttpClientStream> streams =
Collections.synchronizedMap(new HashMap<Integer, OkHttpClientStream>());
- private final ExecutorService executor = Executors.newCachedThreadPool();
+ private final Executor executor;
private int unacknowledgedBytesRead;
private ClientFrameHandler clientFrameHandler;
// The status used to finish all active streams when the transport is closed.
@@ -92,9 +91,10 @@
@GuardedBy("lock")
private Status goAwayStatus;
- public OkHttpClientTransport(String host, int port) {
+ OkHttpClientTransport(String host, int port, Executor executor) {
this.host = Preconditions.checkNotNull(host);
this.port = port;
+ this.executor = Preconditions.checkNotNull(executor);
// Client initiated streams are odd, server initiated ones are even. Server should not need to
// use it. We start clients at 3 to avoid conflicting with HTTP negotiation.
nextStreamId = 3;
@@ -104,12 +104,14 @@
* Create a transport connected to a fake peer for test.
*/
@VisibleForTesting
- OkHttpClientTransport(FrameReader frameReader, AsyncFrameWriter frameWriter, int nextStreamId) {
+ OkHttpClientTransport(Executor executor, FrameReader frameReader, AsyncFrameWriter frameWriter,
+ int nextStreamId) {
host = null;
port = -1;
+ this.executor = Preconditions.checkNotNull(executor);
+ this.frameReader = Preconditions.checkNotNull(frameReader);
+ this.frameWriter = Preconditions.checkNotNull(frameWriter);
this.nextStreamId = nextStreamId;
- this.frameReader = frameReader;
- this.frameWriter = frameWriter;
}
@Override
@@ -227,7 +229,6 @@
} catch (IOException e) {
throw new RuntimeException(e);
}
- executor.shutdown();
notifyStopped();
}
}
diff --git a/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportFactory.java b/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportFactory.java
index 93db9ac..adf7ba2 100644
--- a/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportFactory.java
+++ b/core/src/main/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportFactory.java
@@ -3,21 +3,25 @@
import com.google.net.stubby.newtransport.ClientTransport;
import com.google.net.stubby.newtransport.ClientTransportFactory;
+import java.util.concurrent.ExecutorService;
+
/**
* Factory that manufactures instances of {@link OkHttpClientTransport}.
*/
public class OkHttpClientTransportFactory implements ClientTransportFactory {
private final String host;
private final int port;
+ private final ExecutorService executor;
- public OkHttpClientTransportFactory(String host, int port) {
+ public OkHttpClientTransportFactory(String host, int port, ExecutorService executor) {
this.host = host;
this.port = port;
+ this.executor = executor;
}
@Override
public ClientTransport newClientTransport() {
- return new OkHttpClientTransport(host, port);
+ return new OkHttpClientTransport(host, port, executor);
}
}
diff --git a/core/src/test/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportTest.java b/core/src/test/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportTest.java
index 7c3d7fd..e0465ff 100644
--- a/core/src/test/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportTest.java
+++ b/core/src/test/java/com/google/net/stubby/newtransport/okhttp/OkHttpClientTransportTest.java
@@ -49,6 +49,8 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
@@ -72,13 +74,15 @@
private MockFrameReader frameReader;
private Map<Integer, OkHttpClientStream> streams;
private ClientFrameHandler frameHandler;
+ private ExecutorService executor;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
streams = new HashMap<Integer, OkHttpClientStream>();
frameReader = new MockFrameReader();
- clientTransport = new OkHttpClientTransport(frameReader, frameWriter, 3);
+ executor = Executors.newCachedThreadPool();
+ clientTransport = new OkHttpClientTransport(executor, frameReader, frameWriter, 3);
clientTransport.startAsync();
frameHandler = clientTransport.getHandler();
streams = clientTransport.getStreams();
@@ -90,6 +94,7 @@
clientTransport.stopAsync();
assertTrue(frameReader.closed);
verify(frameWriter).close();
+ executor.shutdown();
}
/**
@@ -370,7 +375,7 @@
int startId = Integer.MAX_VALUE - 2;
AsyncFrameWriter writer = mock(AsyncFrameWriter.class);
OkHttpClientTransport transport =
- new OkHttpClientTransport(frameReader, writer, startId);
+ new OkHttpClientTransport(executor, frameReader, writer, startId);
transport.startAsync();
streams = transport.getStreams();