use of org.orcid.jaxb.model.record_rc2.Address in project okhttp by square.
the class RouteSelectorTest method proxySelectorReturnsNull.
@Test
public void proxySelectorReturnsNull() throws Exception {
ProxySelector nullProxySelector = new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
assertEquals(uriHost, uri.getHost());
return null;
}
@Override
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) {
throw new AssertionError();
}
};
Address address = new Address(uriHost, uriPort, dns, socketFactory, null, null, null, authenticator, null, protocols, connectionSpecs, nullProxySelector);
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
assertTrue(routeSelector.hasNext());
dns.set(uriHost, dns.allocate(1));
assertRoute(routeSelector.next(), address, NO_PROXY, dns.lookup(uriHost, 0), uriPort);
dns.assertRequests(uriHost);
assertFalse(routeSelector.hasNext());
}
use of org.orcid.jaxb.model.record_rc2.Address in project okhttp by square.
the class RouteSelectorTest method multipleProxiesMultipleInetAddressesMultipleConfigurations.
@Test
public void multipleProxiesMultipleInetAddressesMultipleConfigurations() throws Exception {
Address address = httpsAddress();
proxySelector.proxies.add(proxyA);
proxySelector.proxies.add(proxyB);
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
// Proxy A
dns.set(proxyAHost, dns.allocate(2));
assertRoute(routeSelector.next(), address, proxyA, dns.lookup(proxyAHost, 0), proxyAPort);
dns.assertRequests(proxyAHost);
assertRoute(routeSelector.next(), address, proxyA, dns.lookup(proxyAHost, 1), proxyAPort);
// Proxy B
dns.set(proxyBHost, dns.allocate(2));
assertRoute(routeSelector.next(), address, proxyB, dns.lookup(proxyBHost, 0), proxyBPort);
dns.assertRequests(proxyBHost);
assertRoute(routeSelector.next(), address, proxyB, dns.lookup(proxyBHost, 1), proxyBPort);
// No more proxies to attempt.
assertFalse(routeSelector.hasNext());
}
use of org.orcid.jaxb.model.record_rc2.Address in project okhttp by square.
the class RouteSelectorTest method failedRoutesAreLast.
@Test
public void failedRoutesAreLast() throws Exception {
Address address = httpsAddress();
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
final int numberOfAddresses = 2;
dns.set(uriHost, dns.allocate(numberOfAddresses));
// Extract the regular sequence of routes from selector.
List<Route> regularRoutes = new ArrayList<>();
while (routeSelector.hasNext()) {
regularRoutes.add(routeSelector.next());
}
// Check that we do indeed have more than one route.
assertEquals(numberOfAddresses, regularRoutes.size());
// Add first regular route as failed.
routeDatabase.failed(regularRoutes.get(0));
// Reset selector
routeSelector = new RouteSelector(address, routeDatabase);
List<Route> routesWithFailedRoute = new ArrayList<>();
while (routeSelector.hasNext()) {
routesWithFailedRoute.add(routeSelector.next());
}
assertEquals(regularRoutes.get(0), routesWithFailedRoute.get(routesWithFailedRoute.size() - 1));
assertEquals(regularRoutes.size(), routesWithFailedRoute.size());
}
use of org.orcid.jaxb.model.record_rc2.Address in project okhttp by square.
the class RouteSelectorTest method proxyDnsFailureContinuesToNextProxy.
@Test
public void proxyDnsFailureContinuesToNextProxy() throws Exception {
Address address = httpAddress();
proxySelector.proxies.add(proxyA);
proxySelector.proxies.add(proxyB);
proxySelector.proxies.add(proxyA);
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
proxySelector.assertRequests(address.url().uri());
assertTrue(routeSelector.hasNext());
dns.set(proxyAHost, dns.allocate(1));
assertRoute(routeSelector.next(), address, proxyA, dns.lookup(proxyAHost, 0), proxyAPort);
dns.assertRequests(proxyAHost);
assertTrue(routeSelector.hasNext());
dns.clear(proxyBHost);
try {
routeSelector.next();
fail();
} catch (UnknownHostException expected) {
}
dns.assertRequests(proxyBHost);
assertTrue(routeSelector.hasNext());
dns.set(proxyAHost, dns.allocate(1));
assertRoute(routeSelector.next(), address, proxyA, dns.lookup(proxyAHost, 0), proxyAPort);
dns.assertRequests(proxyAHost);
assertFalse(routeSelector.hasNext());
}
use of org.orcid.jaxb.model.record_rc2.Address in project okhttp by square.
the class RouteSelectorTest method proxySelectorReturnsMultipleProxies.
@Test
public void proxySelectorReturnsMultipleProxies() throws Exception {
Address address = httpAddress();
proxySelector.proxies.add(proxyA);
proxySelector.proxies.add(proxyB);
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
proxySelector.assertRequests(address.url().uri());
// First try the IP addresses of the first proxy, in sequence.
assertTrue(routeSelector.hasNext());
dns.set(proxyAHost, dns.allocate(2));
assertRoute(routeSelector.next(), address, proxyA, dns.lookup(proxyAHost, 0), proxyAPort);
assertRoute(routeSelector.next(), address, proxyA, dns.lookup(proxyAHost, 1), proxyAPort);
dns.assertRequests(proxyAHost);
// Next try the IP address of the second proxy.
assertTrue(routeSelector.hasNext());
dns.set(proxyBHost, dns.allocate(1));
assertRoute(routeSelector.next(), address, proxyB, dns.lookup(proxyBHost, 0), proxyBPort);
dns.assertRequests(proxyBHost);
// No more proxies to try.
assertFalse(routeSelector.hasNext());
}
Aggregations