Package net.jini.core.lease

Examples of net.jini.core.lease.Lease


  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  set.renewFor(testLease, Lease.FOREVER);
 
  // remove the lease and make certain it is the same one we added
  logger.log(Level.FINE, "Removing the managed lease from the set.");
  Lease managedLease = set.remove(testLease);
  if (managedLease.equals(testLease) == false) {
      String message = "Remove failed to return the lease whose\n";
      message += "removal was requested.";
      throw new TestException(message);
  }

  // assuming a successful remove it better be gone now ...
  logger.log(Level.FINE, "Checking that removal was successful.");
  Lease duplicateLease = set.remove(testLease);
  if (duplicateLease != null) {
      String message = "Removal of the same lease was\n";
      message += "successfully performed twice.";
      throw new TestException(message);
  }
View Full Code Here


        "Lease.FOREVER");
  long time01 = System.currentTimeMillis();
  set.renewFor(testLease, Lease.FOREVER);

  // Assert that the managed lease has original expiration time
  Lease managedLease = set.remove(testLease);
  long time02 = System.currentTimeMillis();
  long actualExpTime = managedLease.getExpiration();
  long deltaExpTime = actualExpTime - originalExpTime;
  long roundTrip = time02 - time01;
  if (deltaExpTime >= roundTrip) {
      String message = "Expiration time was permaturely altered.";
      throw new TestException(message);
  }

  // just to make certain assert that there are no renew or cancels
  if (leaseOwner.getRenewCalls() > 0) {
      String message = "LRS made an erronous call to renew.";
      throw new TestException(message);
  }
  if (leaseOwner.getCancelCalls() > 0) {
      String message = "LRS made a forbidden call to cancel.";
      throw new TestException(message);
  }

  // create a test lease to be managed
  logger.log(Level.FINE, "Creating the lease to be managed.");
  logger.log(Level.FINE, "Duration == " + renewGrant);
  long leaseCreation = System.currentTimeMillis();
  testLease =
      leaseProvider.createNewLease(leaseOwner,
           rstUtil.durToExp(renewGrant));
  originalExpTime = testLease.getExpiration();

  // start managing the lease
  long membershipDuration = renewGrant + (renewGrant / 2);
  logger.log(Level.FINE, "Adding lease with membership of " +
        membershipDuration + " millseconds.");
  set.renewFor(testLease, membershipDuration);

  // wait for client lease to become renewed
  rstUtil.waitForLeaseExpiration(testLease,
               "for client lease to renew.");

  // remove the lease to prevent any further action
  managedLease = set.remove(testLease);

  /* By now the lease has been renewed (exactly) once.
     To show that the expiration time of the lease reflects
     the time set as a result of the last successful renew,
     we will show that the renewal time is between the time
     the test lease was originally created and its original
     expiration time.
      T0---------------T1----------T2-------------T3
       \lease          \renewal    \original      \current
        creation        time        expriation     expiration
       
      Calculate T1 (T3-renewalGrant) and show that T0 < T1 < T2 */
  long renewalTime = managedLease.getExpiration() - renewGrant;
  boolean inRange = renewalTime > leaseCreation &&
        renewalTime < originalExpTime;
  if (inRange == false) {
      String message = "Lease expiration does not reflect the\n" +
           "latest successful renewal.";
View Full Code Here

  set.setRenewalFailureListener(rrl  , null);

  // create the lease to be managed
  logger.log(Level.FINE, "Creating lease with duration of " +
        renewGrant + " milliseconds.");
  Lease passFailLease =
      leaseProvider.createNewLease(owner,
           rstUtil.durToExp(renewGrant));
  initialExpiration = passFailLease.getExpiration();
  set.renewFor(passFailLease, Lease.FOREVER);

  // wait for the failure event to roll in ...
  rstUtil.waitForRemoteEvents(rrl, 1, renewGrant * 2);

  // we should have a failure event on record
  Long[] arrivalTimes = rrl.getArrivalTimes();
  RemoteEvent[] events = rrl.getEvents();
  if (events.length != 1 || arrivalTimes.length != 1) {
      String message = "Listener received " + events.length +
    " events but is required to receive exactly 1.";
      throw new TestException(message);
  }

  /* Assert that
     1) the expiration time of the lease whose renewal
        attempt failed, has an expiration time greater than
        the original expiration time.
     2) and greater than the arrival time of the renewal
        failure event
     3) and less than the expiration time that would have been
        granted had the renewal succeeded. */
  RenewalFailureEvent rfe = (RenewalFailureEvent) events[0];
  Lease managedLease = rfe.getLease();
  long currentExpiration = managedLease.getExpiration();
  long arrTime = arrivalTimes[0].longValue();
  boolean assert01 = currentExpiration > initialExpiration;
  boolean assert02 = currentExpiration > arrTime;
  boolean assert03 = currentExpiration < (arrTime + renewGrant);
  boolean correctExpiration = assert01 && assert02 && assert03;
View Full Code Here

                   null);
  evReg = prepareRegistration(evReg);
 
  /* ASSERTION #1
     The set lease and the registration lease are the same. */
  Lease lease01 = prepareLease(renewalSet[0].getRenewalSetLease());
  Lease lease02 = evReg.getLease();
  if (lease01.equals(lease02) == false) {
      String message = "The renewal set lease and the warning " +
           "event registration lease are not the same.";
      throw new TestException(message);
  }

  // register for RenewalFailureEvents
  evReg = renewalSet[0].setRenewalFailureListener(listener[0], null);
  evReg = prepareRegistration(evReg);
 
  /* ASSERTION #1 cont'd
     The set lease and the registration lease are the same. */
  Lease lease03 = evReg.getLease();
  if (lease01.equals(lease03) == false) {
      String message = "The renewal set lease and the failure" +
    "event registration lease are not the same.";
      throw new TestException(message);
  }
View Full Code Here

  long sleepTime = renewGrant * 2;
  logger.log(Level.FINE, "Sleeping for " + sleepTime + " milliseconds");
  Thread.sleep(sleepTime);

  // assert that the current expiration time is Long.MAX_VALUE
  Lease managedLease = set.remove(testLease);
  long currentExpTime = managedLease.getExpiration();
  if (currentExpTime != Long.MAX_VALUE) {
      String message = "The current expiration time of the lease" +
    " is " + currentExpTime + " but should be Long.MAX_VALUE" +
    " (" + Long.MAX_VALUE + ").";
      throw new TestException(message);
View Full Code Here

        "membership duration to expire.");
  Thread.sleep(sleeptime);

  // attempt to remove the lease. Removal should fail.
  logger.log(Level.FINE, "Removing the managed lease from the set.");
  Lease managedLease = set.remove(testLease);
  logger.log(Level.FINE, "Lease ==> " + managedLease);
  if (managedLease != null) {
      String message = "Lease was not removed after membership\n";
      message += "duration expired.";
      throw new TestException(message);
View Full Code Here

      throw new TestException(message);
  }

  // get the lease and throwable objects from the event.
  RenewalFailureEvent rfe = (RenewalFailureEvent) events[0];
  Lease eventLease = rfe.getLease();
  IllegalArgumentException eventException =
      (IllegalArgumentException) rfe.getThrowable();

  /* try to recall 50 times and make certain that nothing changes
     and no exceptions are thrown */
  for(int i = 0; i < 50; ++i) {

      try {
    if (eventLease.equals(rfe.getLease()) == false) {
        String message = "The lease returned by getLeases()" +
      "has changed.";
        throw new TestException(message);
    }
      } catch (Exception ex) {
View Full Code Here

  set.setRenewalFailureListener(rrl  , null);

  // create the lease to be managed
  logger.log(Level.FINE, "Creating lease with duration of " +
        renewGrant + " milliseconds.");
  Lease testLease =
      leaseProvider.createNewLease(owner,
           rstUtil.durToExp(renewGrant));

  // wait for the lease to expire
  rstUtil.waitForLeaseExpiration(testLease,
View Full Code Here

  sleepTime = doubleDuration * 3 / 4;
  rstUtil.sleepAndTell(sleepTime, "3/4 lease membership duration.");

  /* if the membership duration was honored we should be able
     to remove the lease */
  Lease managedLease = set.remove(testLease);
  if (managedLease == null) { // new membership was not honored
      String message = "The membership duration was apparently ";
      message += "not updated to the longer value\n";
      message += "when the lease was re-added to the set.";
      throw new TestException(message);
View Full Code Here

    "events.\n" + "Should have received exactly one.";
      throw new TestException(message);
  }

  // There is only one event received, now allow lease to expire
  Lease setLease = rrl.getLastLeaseRenewed();
  rstUtil.waitForLeaseExpiration(setLease,
               "for renewal set to expire.");
 
  // lease should now be expired, prove it ...
  try {
View Full Code Here

TOP

Related Classes of net.jini.core.lease.Lease

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.