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.nio.conn;
28
29 import java.net.InetAddress;
30 import java.net.InetSocketAddress;
31 import java.util.Calendar;
32 import java.util.concurrent.CancellationException;
33 import java.util.concurrent.ExecutionException;
34 import java.util.concurrent.Future;
35 import java.util.concurrent.TimeUnit;
36
37 import org.apache.commons.logging.Log;
38 import org.apache.http.HttpHost;
39 import org.apache.http.concurrent.FutureCallback;
40 import org.apache.http.config.ConnectionConfig;
41 import org.apache.http.config.Registry;
42 import org.apache.http.config.RegistryBuilder;
43 import org.apache.http.conn.DnsResolver;
44 import org.apache.http.conn.SchemePortResolver;
45 import org.apache.http.conn.UnsupportedSchemeException;
46 import org.apache.http.conn.routing.HttpRoute;
47 import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.ConfigData;
48 import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.InternalAddressResolver;
49 import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.InternalConnectionFactory;
50 import org.apache.http.nio.NHttpClientConnection;
51 import org.apache.http.nio.conn.ManagedNHttpClientConnection;
52 import org.apache.http.nio.conn.NHttpConnectionFactory;
53 import org.apache.http.nio.conn.SchemeIOSessionStrategy;
54 import org.apache.http.nio.reactor.ConnectingIOReactor;
55 import org.apache.http.nio.reactor.IOSession;
56 import org.apache.http.nio.reactor.SessionRequest;
57 import org.apache.http.protocol.BasicHttpContext;
58 import org.apache.http.protocol.HttpContext;
59 import org.junit.Assert;
60 import org.junit.Before;
61 import org.junit.Test;
62 import org.mockito.ArgumentCaptor;
63 import org.mockito.Captor;
64 import org.mockito.Mock;
65 import org.mockito.Mockito;
66 import org.mockito.MockitoAnnotations;
67
68 public class TestPoolingHttpClientAsyncConnectionManager {
69
70 @Mock
71 private ConnectingIOReactor ioreactor;
72 @Mock
73 private CPool pool;
74 @Mock
75 private SchemeIOSessionStrategy noopStrategy;
76 @Mock
77 private SchemeIOSessionStrategy sslStrategy;
78 @Mock
79 private SchemePortResolver schemePortResolver;
80 @Mock
81 private DnsResolver dnsResolver;
82 @Mock
83 private FutureCallback<NHttpClientConnection> connCallback;
84 @Captor
85 private ArgumentCaptor<FutureCallback<CPoolEntry>> poolEntryCallbackCaptor;
86 @Mock
87 private ManagedNHttpClientConnection conn;
88 @Mock
89 private NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory;
90 @Mock
91 private SessionRequest sessionRequest;
92 @Mock
93 private IOSession iosession;
94
95 private Registry<SchemeIOSessionStrategy> layeringStrategyRegistry;
96 private PoolingNHttpClientConnectionManager connman;
97
98 @Before
99 public void setUp() throws Exception {
100 MockitoAnnotations.initMocks(this);
101 Mockito.when(sslStrategy.isLayeringRequired()).thenReturn(Boolean.TRUE);
102
103 layeringStrategyRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create()
104 .register("http", noopStrategy)
105 .register("https", sslStrategy)
106 .build();
107 connman = new PoolingNHttpClientConnectionManager(
108 ioreactor, pool, layeringStrategyRegistry);
109 }
110
111 @Test
112 public void testShutdown() throws Exception {
113 connman.shutdown();
114
115 Mockito.verify(pool).shutdown(2000);
116 }
117
118 @Test
119 public void testShutdownMs() throws Exception {
120 connman.shutdown(500);
121
122 Mockito.verify(pool).shutdown(500);
123 }
124
125 @Test
126 public void testRequestReleaseConnection() throws Exception {
127 final HttpHost target = new HttpHost("localhost");
128 final HttpRoute route = new HttpRoute(target);
129 final Future<NHttpClientConnection> future = connman.requestConnection(
130 route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, connCallback);
131 Assert.assertNotNull(future);
132
133 Mockito.verify(pool).lease(
134 Mockito.same(route),
135 Mockito.eq("some state"),
136 Mockito.eq(1000L),
137 Mockito.eq(2000L),
138 Mockito.eq(TimeUnit.MILLISECONDS),
139 poolEntryCallbackCaptor.capture());
140 final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue();
141 final Log log = Mockito.mock(Log.class);
142 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
143 poolentry.markRouteComplete();
144 callaback.completed(poolentry);
145
146 Assert.assertTrue(future.isDone());
147 final NHttpClientConnection managedConn = future.get();
148 Mockito.verify(connCallback).completed(Mockito.<NHttpClientConnection>any());
149
150 Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
151 connman.releaseConnection(managedConn, "new state", 5, TimeUnit.SECONDS);
152
153 Mockito.verify(pool).release(poolentry, true);
154 Assert.assertEquals("new state", poolentry.getState());
155 final Calendar cal = Calendar.getInstance();
156 cal.setTimeInMillis(poolentry.getUpdated());
157 cal.add(Calendar.SECOND, 5);
158 Assert.assertEquals(cal.getTimeInMillis(), poolentry.getExpiry());
159 }
160
161 @Test
162 public void testReleaseConnectionIncompleteRoute() throws Exception {
163 final HttpHost target = new HttpHost("localhost");
164 final HttpRoute route = new HttpRoute(target);
165 final Future<NHttpClientConnection> future = connman.requestConnection(
166 route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, connCallback);
167 Assert.assertNotNull(future);
168
169 Mockito.verify(pool).lease(
170 Mockito.same(route),
171 Mockito.eq("some state"),
172 Mockito.eq(1000L),
173 Mockito.eq(2000L),
174 Mockito.eq(TimeUnit.MILLISECONDS),
175 poolEntryCallbackCaptor.capture());
176 final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue();
177 final Log log = Mockito.mock(Log.class);
178 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
179 callaback.completed(poolentry);
180
181 Assert.assertTrue(future.isDone());
182 final NHttpClientConnection managedConn = future.get();
183 Mockito.verify(connCallback).completed(Mockito.<NHttpClientConnection>any());
184
185 Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
186 connman.releaseConnection(managedConn, "new state", 5, TimeUnit.SECONDS);
187
188 Mockito.verify(pool).release(poolentry, false);
189 }
190
191 @Test
192 public void testRequestConnectionFutureCancelled() throws Exception {
193 final HttpHost target = new HttpHost("localhost");
194 final HttpRoute route = new HttpRoute(target);
195 final Future<NHttpClientConnection> future = connman.requestConnection(
196 route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, null);
197 Assert.assertNotNull(future);
198 future.cancel(true);
199
200 Mockito.verify(pool).lease(
201 Mockito.same(route),
202 Mockito.eq("some state"),
203 Mockito.eq(1000L),
204 Mockito.eq(2000L),
205 Mockito.eq(TimeUnit.MILLISECONDS),
206 poolEntryCallbackCaptor.capture());
207 final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue();
208 final Log log = Mockito.mock(Log.class);
209 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
210 poolentry.markRouteComplete();
211 callaback.completed(poolentry);
212
213 Mockito.verify(pool).release(poolentry, true);
214 }
215
216 @Test(expected=ExecutionException.class)
217 public void testRequestConnectionFailed() throws Exception {
218 final HttpHost target = new HttpHost("localhost");
219 final HttpRoute route = new HttpRoute(target);
220 final Future<NHttpClientConnection> future = connman.requestConnection(
221 route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, null);
222 Assert.assertNotNull(future);
223
224 Mockito.verify(pool).lease(
225 Mockito.same(route),
226 Mockito.eq("some state"),
227 Mockito.eq(1000L),
228 Mockito.eq(2000L),
229 Mockito.eq(TimeUnit.MILLISECONDS),
230 poolEntryCallbackCaptor.capture());
231 final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue();
232 callaback.failed(new Exception());
233
234 Assert.assertTrue(future.isDone());
235 future.get();
236 }
237
238 @Test(expected = CancellationException.class)
239 public void testRequestConnectionCancelled() throws Exception {
240 final HttpHost target = new HttpHost("localhost");
241 final HttpRoute route = new HttpRoute(target);
242 final Future<NHttpClientConnection> future = connman.requestConnection(
243 route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, null);
244 Assert.assertNotNull(future);
245
246 Mockito.verify(pool).lease(
247 Mockito.same(route),
248 Mockito.eq("some state"),
249 Mockito.eq(1000L),
250 Mockito.eq(2000L),
251 Mockito.eq(TimeUnit.MILLISECONDS),
252 poolEntryCallbackCaptor.capture());
253 final FutureCallback<CPoolEntry> callaback = poolEntryCallbackCaptor.getValue();
254 callaback.cancelled();
255
256 Assert.assertTrue(future.isDone());
257 Assert.assertTrue(future.isCancelled());
258 future.get();
259 }
260
261 @Test
262 public void testConnectionInitialize() throws Exception {
263 final HttpHost target = new HttpHost("somehost", -1, "http");
264 final HttpRoute route = new HttpRoute(target);
265 final HttpContext context = new BasicHttpContext();
266
267 final Log log = Mockito.mock(Log.class);
268 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
269 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
270
271 Mockito.when(conn.getIOSession()).thenReturn(iosession);
272 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
273
274 connman.startRoute(managedConn, route, context);
275
276 Mockito.verify(noopStrategy, Mockito.never()).upgrade(target, iosession);
277 Mockito.verify(conn, Mockito.never()).bind(iosession);
278
279 Assert.assertFalse(connman.isRouteComplete(managedConn));
280 }
281
282 @Test
283 public void testConnectionInitializeHttps() throws Exception {
284 final HttpHost target = new HttpHost("somehost", 443, "https");
285 final HttpRoute route = new HttpRoute(target, null, true);
286 final HttpContext context = new BasicHttpContext();
287
288 final Log log = Mockito.mock(Log.class);
289 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
290 poolentry.markRouteComplete();
291 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
292
293 Mockito.when(conn.getIOSession()).thenReturn(iosession);
294 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
295
296 connman.startRoute(managedConn, route, context);
297
298 Mockito.verify(sslStrategy).upgrade(target, iosession);
299 Mockito.verify(conn).bind(iosession);
300 }
301
302 @Test
303 public void testConnectionInitializeContextSpecific() throws Exception {
304 final HttpHost target = new HttpHost("somehost", 80, "http11");
305 final HttpRoute route = new HttpRoute(target);
306 final HttpContext context = new BasicHttpContext();
307
308 final Registry<SchemeIOSessionStrategy> reg = RegistryBuilder.<SchemeIOSessionStrategy>create()
309 .register("http11", noopStrategy)
310 .build();
311 context.setAttribute(PoolingNHttpClientConnectionManager.IOSESSION_FACTORY_REGISTRY, reg);
312
313 final Log log = Mockito.mock(Log.class);
314 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
315 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
316
317 Mockito.when(conn.getIOSession()).thenReturn(iosession);
318 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
319
320 connman.startRoute(managedConn, route, context);
321
322 Mockito.verify(noopStrategy, Mockito.never()).upgrade(target, iosession);
323 Mockito.verify(conn, Mockito.never()).bind(iosession);
324
325 Assert.assertFalse(connman.isRouteComplete(managedConn));
326 }
327
328 @Test(expected=UnsupportedSchemeException.class)
329 public void testConnectionInitializeUnknownScheme() throws Exception {
330 final HttpHost target = new HttpHost("somehost", -1, "whatever");
331 final HttpRoute route = new HttpRoute(target, null, true);
332 final HttpContext context = new BasicHttpContext();
333
334 final Log log = Mockito.mock(Log.class);
335 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
336 poolentry.markRouteComplete();
337 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
338
339 Mockito.when(conn.getIOSession()).thenReturn(iosession);
340 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
341
342 connman.startRoute(managedConn, route, context);
343 }
344
345 @Test
346 public void testConnectionUpgrade() throws Exception {
347 final HttpHost target = new HttpHost("somehost", 443, "https");
348 final HttpRoute route = new HttpRoute(target);
349 final HttpContext context = new BasicHttpContext();
350
351 final Log log = Mockito.mock(Log.class);
352 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
353 poolentry.markRouteComplete();
354 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
355
356 Mockito.when(conn.getIOSession()).thenReturn(iosession);
357 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
358
359 connman.upgrade(managedConn, route, context);
360
361 Mockito.verify(sslStrategy).upgrade(target, iosession);
362 Mockito.verify(conn).bind(iosession);
363 }
364
365 @Test(expected=UnsupportedSchemeException.class)
366 public void testConnectionUpgradeUnknownScheme() throws Exception {
367 final HttpHost target = new HttpHost("somehost", -1, "whatever");
368 final HttpRoute route = new HttpRoute(target);
369 final HttpContext context = new BasicHttpContext();
370
371 final Log log = Mockito.mock(Log.class);
372 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
373 poolentry.markRouteComplete();
374 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
375
376 Mockito.when(conn.getIOSession()).thenReturn(iosession);
377 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
378
379 connman.upgrade(managedConn, route, context);
380 }
381
382 @Test(expected=UnsupportedSchemeException.class)
383 public void testConnectionUpgradeIllegalScheme() throws Exception {
384 final HttpHost target = new HttpHost("somehost", 80, "http");
385 final HttpRoute route = new HttpRoute(target);
386 final HttpContext context = new BasicHttpContext();
387
388 final Log log = Mockito.mock(Log.class);
389 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
390 poolentry.markRouteComplete();
391 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
392
393 Mockito.when(conn.getIOSession()).thenReturn(iosession);
394 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
395
396 connman.upgrade(managedConn, route, context);
397 }
398
399 @Test
400 public void testConnectionRouteComplete() throws Exception {
401 final HttpHost target = new HttpHost("somehost", 80, "http");
402 final HttpRoute route = new HttpRoute(target);
403 final HttpContext context = new BasicHttpContext();
404
405 final Log log = Mockito.mock(Log.class);
406 final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
407 poolentry.markRouteComplete();
408 final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
409
410 Mockito.when(conn.getIOSession()).thenReturn(iosession);
411 Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);
412
413 connman.startRoute(managedConn, route, context);
414 connman.routeComplete(managedConn, route, context);
415
416 Assert.assertTrue(connman.isRouteComplete(managedConn));
417 }
418
419 @Test
420 public void testDelegationToCPool() throws Exception {
421 connman.closeExpiredConnections();
422 Mockito.verify(pool).closeExpired();
423
424 connman.closeIdleConnections(3, TimeUnit.SECONDS);
425 Mockito.verify(pool).closeIdle(3, TimeUnit.SECONDS);
426
427 connman.getMaxTotal();
428 Mockito.verify(pool).getMaxTotal();
429
430 connman.getDefaultMaxPerRoute();
431 Mockito.verify(pool).getDefaultMaxPerRoute();
432
433 final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
434 connman.getMaxPerRoute(route);
435 Mockito.verify(pool).getMaxPerRoute(route);
436
437 connman.setMaxTotal(200);
438 Mockito.verify(pool).setMaxTotal(200);
439
440 connman.setDefaultMaxPerRoute(100);
441 Mockito.verify(pool).setDefaultMaxPerRoute(100);
442
443 connman.setMaxPerRoute(route, 150);
444 Mockito.verify(pool).setMaxPerRoute(route, 150);
445
446 connman.getTotalStats();
447 Mockito.verify(pool).getTotalStats();
448
449 connman.getStats(route);
450 Mockito.verify(pool).getStats(route);
451 }
452
453 @Test
454 public void testInternalConnFactoryCreate() throws Exception {
455 final ConfigData configData = new ConfigData();
456 final InternalConnectionFactory internalConnFactory = new InternalConnectionFactory(
457 configData, connFactory);
458
459 final HttpRoute route = new HttpRoute(new HttpHost("somehost", 80));
460 internalConnFactory.create(route, iosession);
461
462 Mockito.verify(sslStrategy, Mockito.never()).upgrade(Mockito.eq(new HttpHost("somehost", 80)),
463 Mockito.<IOSession>any());
464 Mockito.verify(connFactory).create(Mockito.same(iosession), Mockito.<ConnectionConfig>any());
465 }
466
467 @Test
468 public void testInternalConnFactoryCreateViaProxy() throws Exception {
469 final ConfigData configData = new ConfigData();
470 final InternalConnectionFactory internalConnFactory = new InternalConnectionFactory(
471 configData, connFactory);
472
473 final HttpHost target = new HttpHost("somehost", 80);
474 final HttpHost proxy = new HttpHost("someproxy", 8888);
475 final HttpRoute route = new HttpRoute(target, null, proxy, false);
476
477 final ConnectionConfig config = ConnectionConfig.custom().build();
478 configData.setConnectionConfig(proxy, config);
479
480 internalConnFactory.create(route, iosession);
481
482 Mockito.verify(connFactory).create(iosession, config);
483 }
484
485 @Test
486 public void testInternalConnFactoryCreateDirect() throws Exception {
487 final ConfigData configData = new ConfigData();
488 final InternalConnectionFactory internalConnFactory = new InternalConnectionFactory(
489 configData, connFactory);
490
491 final HttpHost target = new HttpHost("somehost", 80);
492 final HttpRoute route = new HttpRoute(target);
493
494 final ConnectionConfig config = ConnectionConfig.custom().build();
495 configData.setConnectionConfig(target, config);
496
497 internalConnFactory.create(route, iosession);
498
499 Mockito.verify(connFactory).create(iosession, config);
500 }
501
502 @Test
503 public void testInternalConnFactoryCreateDefaultConfig() throws Exception {
504 final ConfigData configData = new ConfigData();
505 final InternalConnectionFactory internalConnFactory = new InternalConnectionFactory(
506 configData, connFactory);
507
508 final HttpHost target = new HttpHost("somehost", 80);
509 final HttpRoute route = new HttpRoute(target);
510
511 final ConnectionConfig config = ConnectionConfig.custom().build();
512 configData.setDefaultConnectionConfig(config);
513
514 internalConnFactory.create(route, iosession);
515
516 Mockito.verify(connFactory).create(iosession, config);
517 }
518
519 @Test
520 public void testInternalConnFactoryCreateGlobalDefaultConfig() throws Exception {
521 final ConfigData configData = new ConfigData();
522 final InternalConnectionFactory internalConnFactory = new InternalConnectionFactory(
523 configData, connFactory);
524
525 final HttpHost target = new HttpHost("somehost", 80);
526 final HttpRoute route = new HttpRoute(target);
527
528 configData.setDefaultConnectionConfig(null);
529
530 internalConnFactory.create(route, iosession);
531
532 Mockito.verify(connFactory).create(iosession, ConnectionConfig.DEFAULT);
533 }
534
535 @Test
536 public void testResolveLocalAddress() throws Exception {
537 final InternalAddressResolver addressResolver = new InternalAddressResolver(
538 schemePortResolver, dnsResolver);
539
540 final HttpHost target = new HttpHost("localhost");
541 final byte[] ip = new byte[] {10, 0, 0, 10};
542 final HttpRoute route = new HttpRoute(target, InetAddress.getByAddress(ip), false);
543 final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveLocalAddress(route);
544
545 Assert.assertNotNull(address);
546 Assert.assertEquals(InetAddress.getByAddress(ip), address.getAddress());
547 Assert.assertEquals(0, address.getPort());
548 }
549
550 @Test
551 public void testResolveLocalAddressNull() throws Exception {
552 final InternalAddressResolver addressResolver = new InternalAddressResolver(
553 schemePortResolver, dnsResolver);
554
555 final HttpHost target = new HttpHost("localhost");
556 final HttpRoute route = new HttpRoute(target);
557 final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveLocalAddress(route);
558
559 Assert.assertNull(address);
560 }
561
562 @Test
563 public void testResolveRemoteAddress() throws Exception {
564 final InternalAddressResolver addressResolver = new InternalAddressResolver(
565 schemePortResolver, dnsResolver);
566
567 final HttpHost target = new HttpHost("somehost", 80);
568 final HttpRoute route = new HttpRoute(target);
569
570 Mockito.when(schemePortResolver.resolve(target)).thenReturn(123);
571 final byte[] ip = new byte[] {10, 0, 0, 10};
572 Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] {InetAddress.getByAddress(ip)});
573
574 final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveRemoteAddress(route);
575
576 Assert.assertNotNull(address);
577 Assert.assertEquals(InetAddress.getByAddress(ip), address.getAddress());
578 Assert.assertEquals(123, address.getPort());
579 }
580
581 @Test
582 public void testResolveRemoteAddressViaProxy() throws Exception {
583 final InternalAddressResolver addressResolver = new InternalAddressResolver(
584 schemePortResolver, dnsResolver);
585
586 final HttpHost target = new HttpHost("somehost", 80);
587 final HttpHost proxy = new HttpHost("someproxy");
588 final HttpRoute route = new HttpRoute(target, null, proxy, false);
589
590 Mockito.when(schemePortResolver.resolve(proxy)).thenReturn(8888);
591 final byte[] ip = new byte[] {10, 0, 0, 10};
592 Mockito.when(dnsResolver.resolve("someproxy")).thenReturn(new InetAddress[] {InetAddress.getByAddress(ip)});
593
594 final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveRemoteAddress(route);
595
596 Assert.assertNotNull(address);
597 Assert.assertEquals(InetAddress.getByAddress(ip), address.getAddress());
598 Assert.assertEquals(8888, address.getPort());
599 }
600
601 }