1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.http.impl.client.integration;
28
29 import org.apache.http.HttpHost;
30 import org.apache.http.client.methods.CloseableHttpResponse;
31 import org.apache.http.client.methods.HttpGet;
32 import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
33 import org.apache.http.localserver.LocalServerTestBase;
34 import org.apache.http.util.EntityUtils;
35 import org.junit.Assert;
36 import org.junit.Test;
37
38 public class TestBasicConnectionManager extends LocalServerTestBase {
39
40 @Test
41 public void testBasics() throws Exception {
42 this.clientBuilder.setConnectionManager(new BasicHttpClientConnectionManager());
43
44 final HttpHost target = start();
45 final HttpGet get = new HttpGet("/random/1024");
46 final CloseableHttpResponse response = this.httpclient.execute(target, get);
47 try {
48 Assert.assertEquals(200, response.getStatusLine().getStatusCode());
49 EntityUtils.consume(response.getEntity());
50 } finally {
51 response.close();
52 }
53 }
54
55 @Test(expected=IllegalStateException.class)
56 public void testConnectionStillInUse() throws Exception {
57 this.clientBuilder.setConnectionManager(new BasicHttpClientConnectionManager());
58
59 final HttpHost target = start();
60 final HttpGet get1 = new HttpGet("/random/1024");
61 this.httpclient.execute(target, get1);
62 final HttpGet get2 = new HttpGet("/random/1024");
63 this.httpclient.execute(target, get2);
64 }
65
66 }