diff --git a/benchmarks/src/main/java/com/squareup/okhttp/benchmarks/Benchmark.java b/benchmarks/src/main/java/com/squareup/okhttp/benchmarks/Benchmark.java index 8a5505158d54..7f0073cc7da5 100644 --- a/benchmarks/src/main/java/com/squareup/okhttp/benchmarks/Benchmark.java +++ b/benchmarks/src/main/java/com/squareup/okhttp/benchmarks/Benchmark.java @@ -173,7 +173,7 @@ private MockWebServer startServer() throws IOException { } }); - server.play(); + server.start(); return server; } diff --git a/mockwebserver/README.md b/mockwebserver/README.md index 9596ec163998..c72966826ce0 100644 --- a/mockwebserver/README.md +++ b/mockwebserver/README.md @@ -39,7 +39,7 @@ public void test() throws Exception { server.enqueue(new MockResponse().setBody("yo dog")); // Start the server. - server.play(); + server.start(); // Ask the server for its URL. You'll need this to make HTTP requests. URL baseUrl = server.getUrl("/v1/chat/"); diff --git a/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java b/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java index 06ef70ee99ad..6041089a2899 100644 --- a/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java +++ b/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/MockWebServer.java @@ -127,17 +127,19 @@ public void setServerSocketFactory(ServerSocketFactory serverSocketFactory) { } public int getPort() { - if (port == -1) throw new IllegalStateException("Call play() before getPort()"); + if (port == -1) throw new IllegalStateException("Call start() before getPort()"); return port; } public String getHostName() { - if (inetAddress == null) throw new IllegalStateException("Call play() before getHostName()"); + if (inetAddress == null) throw new IllegalStateException("Call start() before getHostName()"); return inetAddress.getHostName(); } public Proxy toProxyAddress() { - if (inetAddress == null) throw new IllegalStateException("Call play() before toProxyAddress()"); + if (inetAddress == null) { + throw new IllegalStateException("Call start() before toProxyAddress()"); + } return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(inetAddress, getPort())); } @@ -258,20 +260,30 @@ public void enqueue(MockResponse response) { ((QueueDispatcher) dispatcher).enqueueResponse(response.clone()); } - /** Equivalent to {@code play(0)}. */ + /** @deprecated Use {@link #start()}. */ public void play() throws IOException { - play(0); + start(); + } + + /** @deprecated Use {@link #start(int)}. */ + public void play(int port) throws IOException { + start(port); + } + + /** Equivalent to {@code start(0)}. */ + public void start() throws IOException { + start(0); } /** - * Starts the server, serves all enqueued requests, and shuts the server down. + * Starts the server. * * @param port the port to listen to, or 0 for any available port. Automated * tests should always use port 0 to avoid flakiness when a specific port * is unavailable. */ - public void play(int port) throws IOException { - if (executor != null) throw new IllegalStateException("play() already called"); + public void start(int port) throws IOException { + if (executor != null) throw new IllegalStateException("start() already called"); executor = Executors.newCachedThreadPool(Util.threadFactory("MockWebServer", false)); inetAddress = InetAddress.getByName(null); serverSocket = serverSocketFactory.createServerSocket(); diff --git a/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/rule/MockWebServerRule.java b/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/rule/MockWebServerRule.java index e7200e266532..01df8e219ada 100644 --- a/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/rule/MockWebServerRule.java +++ b/mockwebserver/src/main/java/com/squareup/okhttp/mockwebserver/rule/MockWebServerRule.java @@ -40,7 +40,7 @@ public class MockWebServerRule extends ExternalResource { if (started) return; started = true; try { - server.play(); + server.start(); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/mockwebserver/src/test/java/com/squareup/okhttp/mockwebserver/CustomDispatcherTest.java b/mockwebserver/src/test/java/com/squareup/okhttp/mockwebserver/CustomDispatcherTest.java index efd34742c527..1c8c8206c96d 100644 --- a/mockwebserver/src/test/java/com/squareup/okhttp/mockwebserver/CustomDispatcherTest.java +++ b/mockwebserver/src/test/java/com/squareup/okhttp/mockwebserver/CustomDispatcherTest.java @@ -35,7 +35,7 @@ public class CustomDispatcherTest { } @Test public void simpleDispatch() throws Exception { - mockWebServer.play(); + mockWebServer.start(); final List requestsMade = new ArrayList<>(); final Dispatcher dispatcher = new Dispatcher() { @Override @@ -56,7 +56,7 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio @Test public void outOfOrderResponses() throws Exception { AtomicInteger firstResponseCode = new AtomicInteger(); AtomicInteger secondResponseCode = new AtomicInteger(); - mockWebServer.play(); + mockWebServer.start(); final String secondRequest = "/bar"; final String firstRequest = "/foo"; final CountDownLatch latch = new CountDownLatch(1); diff --git a/okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java b/okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java index 9e816d369812..ca47c0131aab 100644 --- a/okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java +++ b/okhttp-apache/src/test/java/com/squareup/okhttp/apache/OkApacheClientTest.java @@ -35,7 +35,7 @@ public class OkApacheClientTest { @Before public void setUp() throws IOException { client = new OkApacheClient(); server = new MockWebServer(); - server.play(); + server.start(); } @After public void tearDown() throws IOException { diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/CacheTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/CacheTest.java index b76b9a2be417..94df054c50d7 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/CacheTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/CacheTest.java @@ -164,7 +164,7 @@ private void assertCached(boolean shouldPut, int responseCode) throws Exception mockResponse.addHeader("WWW-Authenticate: Basic realm=\"protected area\""); } server.enqueue(mockResponse); - server.play(); + server.start(); Request request = new Request.Builder() .url(server.getUrl("/")) diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java index 0bdc9f58a43a..ebeb698ae3fc 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java @@ -80,14 +80,14 @@ private void setUp(int poolSize) throws Exception { List connectionSpecs = Util.immutableList( ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT); - httpServer.play(); + httpServer.start(); httpAddress = new Address(httpServer.getHostName(), httpServer.getPort(), socketFactory, null, null, null, AuthenticatorAdapter.INSTANCE, null, Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionSpecs, proxySelector); httpSocketAddress = new InetSocketAddress(InetAddress.getByName(httpServer.getHostName()), httpServer.getPort()); - spdyServer.play(); + spdyServer.start(); spdyAddress = new Address(spdyServer.getHostName(), spdyServer.getPort(), socketFactory, sslContext.getSocketFactory(), new RecordingHostnameVerifier(), CertificatePinner.DEFAULT, AuthenticatorAdapter.INSTANCE, null, Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), @@ -558,7 +558,7 @@ private void assertPooled(ConnectionPool pool, Connection... connections) throws private static class FakeExecutor implements Executor { private Runnable runnable; - + @Override public void execute(Runnable runnable) { // This is a bonus assertion for the invariant: At no time should two runnables be scheduled. diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/SocksProxyTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/SocksProxyTest.java index 234e449d8586..9b10213c27e4 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/SocksProxyTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/SocksProxyTest.java @@ -35,7 +35,7 @@ public final class SocksProxyTest { private final MockWebServer server = new MockWebServer(); @Before public void setUp() throws Exception { - server.play(); + server.start(); socksProxy.play(); } diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/CookiesTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/CookiesTest.java index a738cde08243..f9648d7d62a1 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/CookiesTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/CookiesTest.java @@ -63,7 +63,7 @@ public void testNetscapeResponse() throws Exception { CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER); CookieHandler.setDefault(cookieManager); MockWebServer server = new MockWebServer(); - server.play(); + server.start(); server.enqueue(new MockResponse().addHeader("Set-Cookie: a=android; " + "expires=Fri, 31-Dec-9999 23:59:59 GMT; " @@ -91,7 +91,7 @@ public void testNetscapeResponse() throws Exception { CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER); CookieHandler.setDefault(cookieManager); MockWebServer server = new MockWebServer(); - server.play(); + server.start(); server.enqueue(new MockResponse().addHeader("Set-Cookie: a=android; " + "Comment=this cookie is delicious; " @@ -121,7 +121,7 @@ public void testNetscapeResponse() throws Exception { CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER); CookieHandler.setDefault(cookieManager); MockWebServer server = new MockWebServer(); - server.play(); + server.start(); server.enqueue(new MockResponse().addHeader("Set-Cookie2: a=android; " + "Comment=this cookie is delicious; " @@ -155,7 +155,7 @@ public void testNetscapeResponse() throws Exception { CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER); CookieHandler.setDefault(cookieManager); MockWebServer server = new MockWebServer(); - server.play(); + server.start(); server.enqueue(new MockResponse().addHeader("Set-Cookie2: a=\"android\"; " + "Comment=\"this cookie is delicious\"; " @@ -188,7 +188,7 @@ public void testNetscapeResponse() throws Exception { @Test public void testSendingCookiesFromStore() throws Exception { MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse()); - server.play(); + server.start(); CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER); HttpCookie cookieA = new HttpCookie("a", "android"); @@ -213,13 +213,13 @@ public void testNetscapeResponse() throws Exception { @Test public void testRedirectsDoNotIncludeTooManyCookies() throws Exception { MockWebServer redirectTarget = new MockWebServer(); redirectTarget.enqueue(new MockResponse().setBody("A")); - redirectTarget.play(); + redirectTarget.start(); MockWebServer redirectSource = new MockWebServer(); redirectSource.enqueue(new MockResponse() .setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP) .addHeader("Location: " + redirectTarget.getUrl("/"))); - redirectSource.play(); + redirectSource.start(); CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER); HttpCookie cookie = new HttpCookie("c", "cookie"); @@ -267,7 +267,7 @@ public Map> get(URI uri, }); MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse()); - server.play(); + server.start(); HttpURLConnection connection = new OkUrlFactory(client).open(server.getUrl("/")); assertEquals(Collections.>emptyMap(), @@ -316,7 +316,7 @@ public Map> get(URI uri, }); MockWebServer server = new MockWebServer(); server. enqueue(new MockResponse()); - server.play(); + server.start(); get(server, "/"); diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/DisconnectTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/DisconnectTest.java index ff86560d90db..7a70d03e3406 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/DisconnectTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/DisconnectTest.java @@ -73,7 +73,7 @@ protected void configureSocket(Socket socket) throws IOException { server.enqueue(new MockResponse() .throttleBody(64 * 1024, 125, TimeUnit.MILLISECONDS)); // 500 Kbps - server.play(); + server.start(); HttpURLConnection connection = new OkUrlFactory(client).open(server.getUrl("/")); disconnectLater(connection, 500); @@ -100,7 +100,7 @@ protected void configureSocket(Socket socket) throws IOException { server.enqueue(new MockResponse() .setBody(new Buffer().write(new byte[responseBodySize])) .throttleBody(64 * 1024, 125, TimeUnit.MILLISECONDS)); // 500 Kbps - server.play(); + server.start(); HttpURLConnection connection = new OkUrlFactory(client).open(server.getUrl("/")); disconnectLater(connection, 500); diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java index 505796d57fc3..63f55e1f18a6 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/ThreadInterruptTest.java @@ -75,7 +75,7 @@ protected void configureSocket(Socket socket) throws IOException { server.enqueue(new MockResponse() .throttleBody(64 * 1024, 125, TimeUnit.MILLISECONDS)); // 500 Kbps - server.play(); + server.start(); interruptLater(500); @@ -102,7 +102,7 @@ protected void configureSocket(Socket socket) throws IOException { server.enqueue(new MockResponse() .setBody(new Buffer().write(new byte[responseBodySize])) .throttleBody(64 * 1024, 125, TimeUnit.MILLISECONDS)); // 500 Kbps - server.play(); + server.start(); interruptLater(500); diff --git a/okhttp-urlconnection/src/test/java/com/squareup/okhttp/UrlConnectionCacheTest.java b/okhttp-urlconnection/src/test/java/com/squareup/okhttp/UrlConnectionCacheTest.java index 277e4eca1d8d..513cd9d49e4e 100644 --- a/okhttp-urlconnection/src/test/java/com/squareup/okhttp/UrlConnectionCacheTest.java +++ b/okhttp-urlconnection/src/test/java/com/squareup/okhttp/UrlConnectionCacheTest.java @@ -173,7 +173,7 @@ private void assertCached(boolean shouldPut, int responseCode) throws Exception response.addHeader("WWW-Authenticate: Basic realm=\"protected area\""); } server.enqueue(response); - server.play(); + server.start(); URL url = server.getUrl("/"); HttpURLConnection conn = client.open(url); diff --git a/okhttp-urlconnection/src/test/java/com/squareup/okhttp/internal/huc/CacheAdapterTest.java b/okhttp-urlconnection/src/test/java/com/squareup/okhttp/internal/huc/CacheAdapterTest.java index 270fb837ee74..3b3a4b54d43b 100644 --- a/okhttp-urlconnection/src/test/java/com/squareup/okhttp/internal/huc/CacheAdapterTest.java +++ b/okhttp-urlconnection/src/test/java/com/squareup/okhttp/internal/huc/CacheAdapterTest.java @@ -254,14 +254,14 @@ private void executePost(HttpURLConnection connection) throws IOException { private URL configureServer(MockResponse mockResponse) throws Exception { server.enqueue(mockResponse); - server.play(); + server.start(); return server.getUrl("/"); } private URL configureHttpsServer(MockResponse mockResponse) throws Exception { server.useHttps(sslContext.getSocketFactory(), false /* tunnelProxy */); server.enqueue(mockResponse); - server.play(); + server.start(); return server.getUrl("/"); } } diff --git a/samples/static-server/src/main/java/com/squareup/okhttp/sample/SampleServer.java b/samples/static-server/src/main/java/com/squareup/okhttp/sample/SampleServer.java index c7a479ec18ac..a2fd19d42443 100644 --- a/samples/static-server/src/main/java/com/squareup/okhttp/sample/SampleServer.java +++ b/samples/static-server/src/main/java/com/squareup/okhttp/sample/SampleServer.java @@ -34,7 +34,7 @@ public void run() throws IOException { MockWebServer server = new MockWebServer(); server.useHttps(sslContext.getSocketFactory(), false); server.setDispatcher(this); - server.play(port); + server.start(port); } @Override public MockResponse dispatch(RecordedRequest request) {