use of com.twitter.finagle.ChannelWriteException in project distributedlog by twitter.
the class TestConsistentHashRoutingService method testBlackoutHost.
@Test(timeout = 60000)
public void testBlackoutHost() throws Exception {
TestName name = new TestName();
RoutingService routingService = ConsistentHashRoutingService.newBuilder().serverSet(new NameServerSet(name)).resolveFromName(true).numReplicas(997).blackoutSeconds(2).build();
InetSocketAddress inetAddress = new InetSocketAddress("127.0.0.1", 3181);
Address address = Addresses.newInetAddress(inetAddress);
List<Address> addresses = new ArrayList<Address>(1);
addresses.add(address);
name.changeAddrs(addresses);
routingService.startService();
RoutingService.RoutingContext routingContext = RoutingService.RoutingContext.of(new DefaultRegionResolver());
String streamName = "test-blackout-host";
assertEquals(inetAddress, routingService.getHost(streamName, routingContext));
routingService.removeHost(inetAddress, new ChannelWriteException(new IOException("test exception")));
try {
routingService.getHost(streamName, routingContext);
fail("Should fail to get host since no brokers are available");
} catch (NoBrokersAvailableException nbae) {
// expected
}
TimeUnit.SECONDS.sleep(3);
assertEquals(inetAddress, routingService.getHost(streamName, routingContext));
routingService.stopService();
}
Aggregations