@Test
public void testLeaseExpiry() throws Exception {
setUp(true);
h.setIgnoreDatanodes(false);
LeaseManager leaseManager = cluster.getStandbyAvatar(0).avatar.namesystem.leaseManager;
// Set low lease periods.
leaseManager.setLeasePeriod(LEASE_PERIOD, LEASE_PERIOD);
String src = "/testLeaseExpiry";
// Create some data.
FSDataOutputStream out = fs.create(new Path(src));
byte[] buffer = new byte[BLOCK_SIZE * 2];
random.nextBytes(buffer);
out.write(buffer);
out.sync();
// Wait for the hard lease time to expire.
Thread.sleep(LEASE_PERIOD * 2);
cluster.failOver();
LOG.info("Failover done");
// Renew lease.
((DistributedFileSystem)fs).getClient().leasechecker.renew();
LOG.info("Lease renewal done");
// Wait to see whether lease expires.
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < MAX_WAIT_TIME
&& leaseManager.getLeaseByPath(src) != null) {
Thread.sleep(1000);
}
LOG.info("Wait for lease done");
// Now try to write to the file.