Skip to content

Commit 8b58fe1

Browse files
author
Stephane Landelle
committed
Move tests to Netty specific class, Grizzly don't care about ConnectionPool
1 parent 754bdbf commit 8b58fe1

File tree

3 files changed

+106
-182
lines changed

3 files changed

+106
-182
lines changed

src/test/java/com/ning/http/client/async/ConnectionPoolTest.java

Lines changed: 14 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@
1515
*/
1616
package com.ning.http.client.async;
1717

18-
import com.ning.http.client.AsyncCompletionHandler;
19-
import com.ning.http.client.AsyncCompletionHandlerBase;
20-
import com.ning.http.client.AsyncHttpClient;
21-
import com.ning.http.client.AsyncHttpClientConfig;
22-
import com.ning.http.client.ConnectionsPool;
23-
import com.ning.http.client.Response;
24-
import org.jboss.netty.channel.Channel;
25-
import org.slf4j.Logger;
26-
import org.slf4j.LoggerFactory;
27-
import org.testng.Assert;
28-
import org.testng.annotations.Test;
18+
import static org.testng.Assert.assertEquals;
19+
import static org.testng.Assert.assertNotNull;
20+
import static org.testng.Assert.assertNull;
21+
import static org.testng.Assert.fail;
2922

3023
import java.io.IOException;
3124
import java.util.Map;
@@ -35,10 +28,16 @@
3528
import java.util.concurrent.TimeUnit;
3629
import java.util.concurrent.atomic.AtomicInteger;
3730

38-
import static org.testng.Assert.assertEquals;
39-
import static org.testng.Assert.assertNotNull;
40-
import static org.testng.Assert.assertNull;
41-
import static org.testng.Assert.fail;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
33+
import org.testng.Assert;
34+
import org.testng.annotations.Test;
35+
36+
import com.ning.http.client.AsyncCompletionHandler;
37+
import com.ning.http.client.AsyncCompletionHandlerBase;
38+
import com.ning.http.client.AsyncHttpClient;
39+
import com.ning.http.client.AsyncHttpClientConfig;
40+
import com.ning.http.client.Response;
4241

4342
public abstract class ConnectionPoolTest extends AbstractBasicTest {
4443
protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class);
@@ -133,89 +132,6 @@ public Response onCompleted(Response response) throws Exception {
133132
}
134133
}
135134

136-
@Test(groups = { "standalone", "default_provider" })
137-
public void testInvalidConnectionsPool() {
138-
139-
ConnectionsPool<String, Channel> cp = new ConnectionsPool<String, Channel>() {
140-
141-
public boolean offer(String key, Channel connection) {
142-
return false;
143-
}
144-
145-
public Channel poll(String connection) {
146-
return null;
147-
}
148-
149-
public boolean removeAll(Channel connection) {
150-
return false;
151-
}
152-
153-
public boolean canCacheConnection() {
154-
return false;
155-
}
156-
157-
public void destroy() {
158-
159-
}
160-
};
161-
162-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
163-
try {
164-
Exception exception = null;
165-
try {
166-
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
167-
} catch (Exception ex) {
168-
ex.printStackTrace();
169-
exception = ex;
170-
}
171-
assertNotNull(exception);
172-
assertEquals(exception.getMessage(), "Too many connections -1");
173-
} finally {
174-
client.close();
175-
}
176-
}
177-
178-
@Test(groups = { "standalone", "default_provider" })
179-
public void testValidConnectionsPool() {
180-
181-
ConnectionsPool<String, Channel> cp = new ConnectionsPool<String, Channel>() {
182-
183-
public boolean offer(String key, Channel connection) {
184-
return true;
185-
}
186-
187-
public Channel poll(String connection) {
188-
return null;
189-
}
190-
191-
public boolean removeAll(Channel connection) {
192-
return false;
193-
}
194-
195-
public boolean canCacheConnection() {
196-
return true;
197-
}
198-
199-
public void destroy() {
200-
201-
}
202-
};
203-
204-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
205-
try {
206-
Exception exception = null;
207-
try {
208-
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
209-
} catch (Exception ex) {
210-
ex.printStackTrace();
211-
exception = ex;
212-
}
213-
assertNull(exception);
214-
} finally {
215-
client.close();
216-
}
217-
}
218-
219135
@Test(groups = { "standalone", "default_provider" })
220136
public void multipleMaxConnectionOpenTest() throws Throwable {
221137
AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setConnectionTimeoutInMs(5000).setMaximumConnectionsTotal(1).build();

src/test/java/com/ning/http/client/async/grizzly/GrizzlyConnectionPoolTest.java

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@
1515

1616
import static org.testng.Assert.assertEquals;
1717
import static org.testng.Assert.assertNotNull;
18-
import static org.testng.Assert.assertNull;
1918
import static org.testng.Assert.fail;
2019

2120
import java.util.concurrent.TimeUnit;
2221

23-
import org.glassfish.grizzly.Connection;
2422
import org.testng.annotations.Test;
2523

2624
import com.ning.http.client.AsyncHttpClient;
2725
import com.ning.http.client.AsyncHttpClientConfig;
28-
import com.ning.http.client.ConnectionsPool;
2926
import com.ning.http.client.Response;
3027
import com.ning.http.client.async.ConnectionPoolTest;
3128
import com.ning.http.client.async.ProviderUtil;
@@ -66,87 +63,6 @@ public void testMaxTotalConnectionsException() {
6663
}
6764
}
6865

69-
@Override
70-
public void testValidConnectionsPool() {
71-
ConnectionsPool<String, Connection> cp = new ConnectionsPool<String, Connection>() {
72-
73-
public boolean offer(String key, Connection connection) {
74-
return true;
75-
}
76-
77-
public Connection poll(String connection) {
78-
return null;
79-
}
80-
81-
public boolean removeAll(Connection connection) {
82-
return false;
83-
}
84-
85-
public boolean canCacheConnection() {
86-
return true;
87-
}
88-
89-
public void destroy() {
90-
91-
}
92-
};
93-
94-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
95-
try {
96-
Exception exception = null;
97-
try {
98-
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
99-
} catch (Exception ex) {
100-
ex.printStackTrace();
101-
exception = ex;
102-
}
103-
assertNull(exception);
104-
} finally {
105-
client.close();
106-
}
107-
}
108-
109-
@Test(groups = { "standalone", "default_provider" })
110-
public void testInvalidConnectionsPool() {
111-
112-
ConnectionsPool<String, Connection> cp = new ConnectionsPool<String, Connection>() {
113-
114-
public boolean offer(String key, Connection connection) {
115-
return false;
116-
}
117-
118-
public Connection poll(String connection) {
119-
return null;
120-
}
121-
122-
public boolean removeAll(Connection connection) {
123-
return false;
124-
}
125-
126-
public boolean canCacheConnection() {
127-
return false;
128-
}
129-
130-
public void destroy() {
131-
132-
}
133-
};
134-
135-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
136-
try {
137-
Exception exception = null;
138-
try {
139-
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
140-
} catch (Exception ex) {
141-
ex.printStackTrace();
142-
exception = ex;
143-
}
144-
assertNotNull(exception);
145-
} finally {
146-
client.close();
147-
}
148-
}
149-
15066
@Override
15167
@Test
15268
public void multipleMaxConnectionOpenTest() throws Throwable {

src/test/java/com/ning/http/client/async/netty/NettyConnectionPoolTest.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@
1212
*/
1313
package com.ning.http.client.async.netty;
1414

15+
import static org.testng.Assert.assertEquals;
16+
import static org.testng.Assert.assertNotNull;
17+
import static org.testng.Assert.assertNull;
18+
19+
import java.util.concurrent.TimeUnit;
20+
21+
import org.jboss.netty.channel.Channel;
22+
import org.testng.annotations.Test;
23+
1524
import com.ning.http.client.AsyncHttpClient;
1625
import com.ning.http.client.AsyncHttpClientConfig;
26+
import com.ning.http.client.ConnectionsPool;
1727
import com.ning.http.client.async.ConnectionPoolTest;
1828
import com.ning.http.client.async.ProviderUtil;
1929

@@ -24,4 +34,86 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) {
2434
return ProviderUtil.nettyProvider(config);
2535
}
2636

37+
@Test(groups = { "standalone", "default_provider" })
38+
public void testInvalidConnectionsPool() {
39+
40+
ConnectionsPool<String, Channel> cp = new ConnectionsPool<String, Channel>() {
41+
42+
public boolean offer(String key, Channel connection) {
43+
return false;
44+
}
45+
46+
public Channel poll(String connection) {
47+
return null;
48+
}
49+
50+
public boolean removeAll(Channel connection) {
51+
return false;
52+
}
53+
54+
public boolean canCacheConnection() {
55+
return false;
56+
}
57+
58+
public void destroy() {
59+
60+
}
61+
};
62+
63+
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
64+
try {
65+
Exception exception = null;
66+
try {
67+
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
68+
} catch (Exception ex) {
69+
ex.printStackTrace();
70+
exception = ex;
71+
}
72+
assertNotNull(exception);
73+
assertEquals(exception.getMessage(), "Too many connections -1");
74+
} finally {
75+
client.close();
76+
}
77+
}
78+
79+
@Test(groups = { "standalone", "default_provider" })
80+
public void testValidConnectionsPool() {
81+
82+
ConnectionsPool<String, Channel> cp = new ConnectionsPool<String, Channel>() {
83+
84+
public boolean offer(String key, Channel connection) {
85+
return true;
86+
}
87+
88+
public Channel poll(String connection) {
89+
return null;
90+
}
91+
92+
public boolean removeAll(Channel connection) {
93+
return false;
94+
}
95+
96+
public boolean canCacheConnection() {
97+
return true;
98+
}
99+
100+
public void destroy() {
101+
102+
}
103+
};
104+
105+
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build());
106+
try {
107+
Exception exception = null;
108+
try {
109+
client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS);
110+
} catch (Exception ex) {
111+
ex.printStackTrace();
112+
exception = ex;
113+
}
114+
assertNull(exception);
115+
} finally {
116+
client.close();
117+
}
118+
}
27119
}

0 commit comments

Comments
 (0)