@Test
public void testRoundRobinBackoffIncreasingBackoffs() throws Exception {

  Properties p = new Properties();
  List<LoadBalancedAvroHandler> hosts =
      new ArrayList<LoadBalancedAvroHandler>();
  List<Server> servers = new ArrayList<Server>();
  StringBuilder hostList = new StringBuilder("");
  for (int i = 0; i < 3; i++) {
    LoadBalancedAvroHandler s = new LoadBalancedAvroHandler();
    hosts.add(s);
    if (i == 1) {
      s.setFailed();
    }
    Server srv = RpcTestUtils.startServer(s);
    servers.add(srv);
    String name = "h" + i;
    p.put("hosts." + name, "127.0.0.1:" + srv.getPort());
    hostList.append(name).append(" ");
  }
  p.put("hosts", hostList.toString().trim());
  p.put("client.type", "default_loadbalance");
  p.put("host-selector", "round_robin");
  p.put("backoff", "true");
  RpcClient c = RpcClientFactory.getInstance(p);
  Assert.assertTrue(c instanceof LoadBalancingRpcClient);
  for (int i = 0; i < 3; i++) {
    c.append(EventBuilder.withBody("testing".getBytes()));
  }
  Assert.assertEquals(0, hosts.get(1).getAppendCount());
  Thread.sleep(2100);
  // this should let the sink come out of backoff and get backed off  for a longer time
  for (int i = 0; i < 3; i++) {
    c.append(EventBuilder.withBody("testing".getBytes()));
  }
  Assert.assertEquals(0, hosts.get(1).getAppendCount());
  hosts.get(1).setOK();
  Thread.sleep(2100);
  // this time it shouldn't come out of backoff yet as the timeout isn't over
  for (int i = 0; i < 3; i++) {
    c.append(EventBuilder.withBody("testing".getBytes()));
  }
  Assert.assertEquals(0, hosts.get(1).getAppendCount());
  // after this s2 should be receiving events again
  Thread.sleep(2500);
  int numEvents = 60;
  for (int i = 0; i < numEvents; i++) {
    c.append(EventBuilder.withBody("testing".getBytes()));
  }
  Assert.assertEquals(2 + 2 + 1 + (numEvents / 3), hosts.get(0).getAppendCount());
  Assert.assertEquals((numEvents / 3), hosts.get(1).getAppendCount());
  Assert.assertEquals(1 + 1 + 2 + (numEvents / 3), hosts.get(2).getAppendCount());
}