@Test
public void testLeaseExpiry() throws Exception {
setUp(true, "testLeaseExpiry");
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.
String clientName = ((DistributedFileSystem)fs).getClient().getClientName();
cluster.getPrimaryAvatar(0).avatar.renewLease(clientName);
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) {
DFSTestUtil.waitSecond();
}
LOG.info("Wait for lease done");
// Now try to write to the file.