Package org.apache.hadoop.hdfs.server.namenode

Examples of org.apache.hadoop.hdfs.server.namenode.LeaseManager


  @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.
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hdfs.server.namenode.LeaseManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.