* @throws Exception
*/
@Test
public void testTwoHostsOneDead() throws Exception {
LOGGER.info("Running testTwoHostsOneDead...");
Server s1 = null;
RpcClient c1 = null, c2 = null;
try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
s1 = RpcTestUtils.startServer(h1);
// do not create a 2nd server (assume it's "down")
Properties p = new Properties();
p.put("hosts", "h1 h2");
p.put("client.type", "default_loadbalance");
p.put("hosts.h1", "127.0.0.1:" + 0); // port 0 should always be closed
p.put("hosts.h2", "127.0.0.1:" + s1.getPort());
// test batch API
c1 = RpcClientFactory.getInstance(p);
Assert.assertTrue(c1 instanceof LoadBalancingRpcClient);
for (int i = 0; i < 10; i++) {
c1.appendBatch(getBatchedEvent(i));
}
Assert.assertEquals(10, h1.getAppendBatchCount());
// test non-batch API
c2 = RpcClientFactory.getInstance(p);
Assert.assertTrue(c2 instanceof LoadBalancingRpcClient);
for (int i = 0; i < 10; i++) {
c2.append(getEvent(i));
}
Assert.assertEquals(10, h1.getAppendCount());
} finally {
if (s1 != null) s1.close();
if (c1 != null) c1.close();
if (c2 != null) c2.close();
}
}