2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import java.io.BufferedReader;
20 import java.io.InputStreamReader;
21 import tests.support.Support_TestWebServer;
23 public class URLConnectionTest extends junit.framework.TestCase {
25 private Support_TestWebServer mServer;
28 public void setUp() throws Exception {
30 mServer = new Support_TestWebServer();
31 mPort = mServer.initServer(0, false);
35 public void tearDown() throws Exception {
40 private String readFirstLine() throws Exception {
41 URLConnection connection = new URL("http://localhost:" + mPort + "/test1").openConnection();
42 BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
43 String result = in.readLine();
48 // Check that if we don't read to the end of a response, the next request on the
49 // recycled connection doesn't get the unread tail of the first request's response.
50 // http://code.google.com/p/android/issues/detail?id=2939
51 public void test_2939() throws Exception {
52 mServer.setChunked(true);
53 mServer.setMaxChunkSize(8);
54 assertTrue(readFirstLine().equals("<html>"));
55 assertTrue(readFirstLine().equals("<html>"));
56 assertEquals(1, mServer.getNumAcceptedConnections());
59 public void testConnectionsArePooled() throws Exception {
63 assertEquals(1, mServer.getNumAcceptedConnections());