Search in sources :

Example 1 with ChannelWriteException

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();
}
Also used : ChannelWriteException(com.twitter.finagle.ChannelWriteException) DLSocketAddress(com.twitter.distributedlog.service.DLSocketAddress) SocketAddress(java.net.SocketAddress) Address(com.twitter.finagle.Address) InetSocketAddress(java.net.InetSocketAddress) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NoBrokersAvailableException(com.twitter.finagle.NoBrokersAvailableException) IOException(java.io.IOException) DefaultRegionResolver(com.twitter.distributedlog.client.resolver.DefaultRegionResolver) Test(org.junit.Test)

Aggregations

DefaultRegionResolver (com.twitter.distributedlog.client.resolver.DefaultRegionResolver)1 DLSocketAddress (com.twitter.distributedlog.service.DLSocketAddress)1 Address (com.twitter.finagle.Address)1 ChannelWriteException (com.twitter.finagle.ChannelWriteException)1 NoBrokersAvailableException (com.twitter.finagle.NoBrokersAvailableException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Test (org.junit.Test)1