本文整理匯總了Java中com.squareup.okhttp.RouteDatabase.failed方法的典型用法代碼示例。如果您正苦於以下問題:Java RouteDatabase.failed方法的具體用法?Java RouteDatabase.failed怎麽用?Java RouteDatabase.failed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.okhttp.RouteDatabase
的用法示例。
在下文中一共展示了RouteDatabase.failed方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: singleRouteReturnsFailedRoute
import com.squareup.okhttp.RouteDatabase; //導入方法依賴的package包/類
@Test public void singleRouteReturnsFailedRoute() throws Exception {
Address address = new Address(uriHost, uriPort, socketFactory, null, null, authenticator, null,
protocols);
RouteSelector routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns,
new RouteDatabase());
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 1);
Connection connection = routeSelector.next("GET");
RouteDatabase routeDatabase = new RouteDatabase();
routeDatabase.failed(connection.getRoute());
routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns, routeDatabase);
assertConnection(routeSelector.next("GET"), address, NO_PROXY, dns.inetAddresses[0], uriPort,
false);
assertFalse(routeSelector.hasNext());
try {
routeSelector.next("GET");
fail();
} catch (NoSuchElementException expected) {
}
}
示例2: singleRouteReturnsFailedRoute
import com.squareup.okhttp.RouteDatabase; //導入方法依賴的package包/類
@Test public void singleRouteReturnsFailedRoute() throws Exception {
Address address = new Address(uriHost, uriPort, null, null, authenticator, null, transports);
RouteSelector routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns,
new RouteDatabase());
assertTrue(routeSelector.hasNext());
dns.inetAddresses = makeFakeAddresses(255, 1);
Connection connection = routeSelector.next("GET");
RouteDatabase routeDatabase = new RouteDatabase();
routeDatabase.failed(connection.getRoute(), new IOException());
routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns, routeDatabase);
assertConnection(routeSelector.next("GET"), address, NO_PROXY, dns.inetAddresses[0], uriPort,
false);
assertFalse(routeSelector.hasNext());
try {
routeSelector.next("GET");
fail();
} catch (NoSuchElementException expected) {
}
}
示例3: failedRoutesAreLast
import com.squareup.okhttp.RouteDatabase; //導入方法依賴的package包/類
@Test public void failedRoutesAreLast() throws Exception {
Address address = new Address(uriHost, uriPort, socketFactory, sslSocketFactory,
hostnameVerifier, authenticator, Proxy.NO_PROXY, protocols);
RouteDatabase routeDatabase = new RouteDatabase();
RouteSelector routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns,
routeDatabase);
dns.inetAddresses = makeFakeAddresses(255, 1);
// Extract the regular sequence of routes from selector.
List<Connection> regularRoutes = new ArrayList<Connection>();
while (routeSelector.hasNext()) {
regularRoutes.add(routeSelector.next("GET"));
}
// Check that we do indeed have more than one route.
assertTrue(regularRoutes.size() > 1);
// Add first regular route as failed.
routeDatabase.failed(regularRoutes.get(0).getRoute());
// Reset selector
routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns, routeDatabase);
List<Connection> routesWithFailedRoute = new ArrayList<Connection>();
while (routeSelector.hasNext()) {
routesWithFailedRoute.add(routeSelector.next("GET"));
}
assertEquals(regularRoutes.get(0).getRoute(),
routesWithFailedRoute.get(routesWithFailedRoute.size() - 1).getRoute());
assertEquals(regularRoutes.size(), routesWithFailedRoute.size());
}
示例4: failedRoutesAreLast
import com.squareup.okhttp.RouteDatabase; //導入方法依賴的package包/類
@Test public void failedRoutesAreLast() throws Exception {
Address address = new Address(uriHost, uriPort, socketFactory, hostnameVerifier, authenticator,
Proxy.NO_PROXY, transports);
RouteDatabase routeDatabase = new RouteDatabase();
RouteSelector routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns,
routeDatabase);
dns.inetAddresses = makeFakeAddresses(255, 1);
// Extract the regular sequence of routes from selector.
List<Connection> regularRoutes = new ArrayList<Connection>();
while (routeSelector.hasNext()) {
regularRoutes.add(routeSelector.next("GET"));
}
// Check that we do indeed have more than one route.
assertTrue(regularRoutes.size() > 1);
// Add first regular route as failed.
routeDatabase.failed(regularRoutes.get(0).getRoute(), new SSLHandshakeException("none"));
// Reset selector
routeSelector = new RouteSelector(address, uri, proxySelector, pool, dns, routeDatabase);
List<Connection> routesWithFailedRoute = new ArrayList<Connection>();
while (routeSelector.hasNext()) {
routesWithFailedRoute.add(routeSelector.next("GET"));
}
assertEquals(regularRoutes.get(0).getRoute(),
routesWithFailedRoute.get(routesWithFailedRoute.size() - 1).getRoute());
assertEquals(regularRoutes.size(), routesWithFailedRoute.size());
}