Examples of LeaseRenewalService


Examples of net.jini.lease.LeaseRenewalService

  // Announce where we are in the test
  logger.log(Level.FINE, "LeaseDurationTest: In run() method.");

  // get a lease renewal set w/ duration for as long as we can
  logger.log(Level.FINE, "Creating the lease renewal set.");
  LeaseRenewalService lrs = getLRS();

  // start with 1 and increase duration requests by power of 10

  // test 1000 - 10 ^ 9
  for (int i = 3; i < NUMBER_OF_LEASES; i++) {
      long duration = (long) Math.pow(10, i);
      logger.log(Level.FINE, "Create renewal set with duration of " +
            duration);
      // short time in the past before creation
      long preLease = System.currentTimeMillis();
      LeaseRenewalSet set = lrs.createLeaseRenewalSet(duration);
      set = prepareSet(set);
      long now = System.currentTimeMillis();
      long expTime = now + duration;
      long leaseExpTime = prepareLease(set.getRenewalSetLease()).getExpiration();

      // It is impossible to calc. expTime exactly, there is slop
      logger.log(Level.FINE, "Calculated lease expiration ==> " +
            expTime);
      logger.log(Level.FINE, "Actual lease expiration ======> " +
            leaseExpTime);
      logger.log(Level.FINE, "slop =========================> " +
            (expTime - leaseExpTime));

      // lease must not be in the past
      if (leaseExpTime < preLease) {
    logger.log(Level.FINE, "lease duration = " + duration);
    logger.log(Level.FINE, "leaseExpTime = " + leaseExpTime);
    logger.log(Level.FINE, "less than now = " + now);
    String message =
        "LRS granted a lease for a renewal set" +
        " with an expiration in the past.";
    throw new TestException(message);
      }

      // lease expiration must be less or equal to calculated
      if (prepareLease(set.getRenewalSetLease()).getExpiration() > expTime) {
    String message =
        "LRS granted a lease for a renewal set" +
        " with an expiration time greater\n" +
        "than requested.";
    throw new TestException(message);
      }
  }     

  // test Lease.ANY
  logger.log(Level.FINE, "Create lease with duration of " +
        "Lease.ANY");
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.ANY);
  set = prepareSet(set);
  long now = System.currentTimeMillis();
  long anyExp = prepareLease(set.getRenewalSetLease()).getExpiration();
  if ( anyExp < now) {
      logger.log(Level.FINE, "Now        = " + now);
      logger.log(Level.FINE, "Expiration = " + anyExp);
      String message = "LRS granted a time in the past when";
      message += " given Lease.ANY as duration request.";
      throw new TestException(message);
  }

  // test Lease.FOREVER
  logger.log(Level.FINE, "Create lease with duration of " +
        "Lease.FOREVER");
  set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  now = System.currentTimeMillis();
  long foreverExp = prepareLease(set.getRenewalSetLease()).getExpiration();
  if ( foreverExp < now) {
      logger.log(Level.FINE, "Now        = " + now);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.