diff options
author | Brian Carlstrom <bdc@google.com> | 2013-04-03 15:16:10 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-05-09 09:33:09 -0700 |
commit | 5fb0d4224639f941d585ac760e9c4575a5bba945 (patch) | |
tree | 71643bf3f6b06ebb0b319f601f7b93048d5634b0 /benchmarks/src | |
parent | 41875e781d3262853d02b3a2a611f302fc6d9998 (diff) | |
download | libcore-5fb0d4224639f941d585ac760e9c4575a5bba945.zip libcore-5fb0d4224639f941d585ac760e9c4575a5bba945.tar.gz libcore-5fb0d4224639f941d585ac760e9c4575a5bba945.tar.bz2 |
Move URLConnectionBenchmark to latest mockwebserver API
(cherry picked from commit 50b871d4eb3b42a8209bb4a6d54cb649f56e873f)
Change-Id: I67e7ae5de6fc3b568c34bf56706dd5146d9f2b18
Diffstat (limited to 'benchmarks/src')
-rw-r--r-- | benchmarks/src/benchmarks/regression/URLConnectionBenchmark.java | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/benchmarks/src/benchmarks/regression/URLConnectionBenchmark.java b/benchmarks/src/benchmarks/regression/URLConnectionBenchmark.java index 36c5666..a4817b5 100644 --- a/benchmarks/src/benchmarks/regression/URLConnectionBenchmark.java +++ b/benchmarks/src/benchmarks/regression/URLConnectionBenchmark.java @@ -18,8 +18,10 @@ package benchmarks.regression; import com.google.caliper.Param; import com.google.caliper.SimpleBenchmark; +import com.google.mockwebserver.Dispatcher; import com.google.mockwebserver.MockResponse; import com.google.mockwebserver.MockWebServer; +import com.google.mockwebserver.RecordedRequest; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; @@ -38,6 +40,16 @@ public final class URLConnectionBenchmark extends SimpleBenchmark { private MockWebServer server; private URL url; + private static class SingleResponseDispatcher extends Dispatcher { + private MockResponse response; + SingleResponseDispatcher(MockResponse response) { + this.response = response; + } + @Override public MockResponse dispatch(RecordedRequest request) { + return response; + } + }; + protected void setUp() throws Exception { readBuffer = new byte[readBufferSize]; server = new MockWebServer(); @@ -45,10 +57,9 @@ public final class URLConnectionBenchmark extends SimpleBenchmark { MockResponse response = new MockResponse(); responseHeaders.apply(response); transferEncoding.setBody(response, bodySize, chunkSize); - server.enqueue(response); // keep serving the same response for all iterations - server.setSingleResponse(true); + server.setDispatcher(new SingleResponseDispatcher(response)); server.play(); url = server.getUrl("/"); @@ -56,14 +67,6 @@ public final class URLConnectionBenchmark extends SimpleBenchmark { } protected void tearDown() throws Exception { - /* - * Entice the server to shut itself down gracefully. The shutdown method - * doesn't work on Dalvik because socket.close() doesn't release blocked - * threads. Instead, read the last continuously-served request, and then - * cause the server to close the otherwise-reusable HTTP connection. - */ - server.setSingleResponse(false); - get(); server.shutdown(); } |