Package net.jini.lease

Examples of net.jini.lease.LeaseRenewalSet


  // get a lease renewal set w/ duration for as long as we can
  logger.log(Level.FINE, "Creating the lease renewal set with duration" +
        " of Lease.FOREVER");
  LeaseRenewalService lrs = getLRS();
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  lrm.renewFor(prepareLease(set.getRenewalSetLease()), Lease.FOREVER, null);

  // register listener to receive events
  logger.log(Level.FINE, "Registering listener for renewal failure" +
        " events.");
  set.setRenewalFailureListener(rrl, null);

  // create a lease that will ultimately fail renewal
  logger.log(Level.FINE, "Creating lease with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
  logger.log(Level.FINE, "Adding lease to renewal set.");
  set.renewFor(lease, Long.MAX_VALUE);
 
  // wait for the failing lease to renew
  rstUtil.waitForRemoteEvents(rrl, 1, renewGrant*2);

  // Capture the event and ensure there is only one
View Full Code Here


  // create a renewal set
  logger.log(Level.FINE, "Creating renewal set with lease duration of " +
        "Lease.FOREVER.");
  long renewSetDur = Lease.FOREVER;
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);
  lrm.renewFor(prepareLease(set.getRenewalSetLease()), renewSetDur, null);

  // create 2 unreadable test leases to be managed
  logger.log(Level.FINE, "Creating an unreadable lease to be managed.");
  logger.log(Level.FINE, "Duration == Lease.FOREVER");
  TestLease specialLease01 =
      unreadableLeaseProvider.createNewLease(leaseOwner,
               Lease.FOREVER);

  logger.log(Level.FINE, "Creating an unreadable lease to be managed.");
  logger.log(Level.FINE, "Duration == Lease.FOREVER");
  TestLease specialLease02 =
      unreadableLeaseProvider.createNewLease(leaseOwner,
               Lease.FOREVER);
  // start managing the unreadable leases forever
  logger.log(Level.FINE, "Adding unreadable lease with membership of " +
        "Lease.FOREVER");
  set.renewFor(specialLease01, Lease.FOREVER);

  logger.log(Level.FINE, "Adding unreadable lease with membership of " +
        "Lease.FOREVER");
  set.renewFor(specialLease02, Lease.FOREVER);

  /* Assert that a LeaseUnmarshalException is thrown when getLeases()
     is called */
  try {
      UnreadableTestLease.setFailMode(true);
      Lease[] leaseArray = set.getLeases();
      UnreadableTestLease.setFailMode(false);

      /* here we have succeeded to getLeases so something went
         frightfully wrong */
      String message =
View Full Code Here

  // create a renewal set
  logger.log(Level.FINE, "Creating renewal set with lease duration of " +
        "Lease.FOREVER.");
  long renewSetDur = Lease.FOREVER;
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);
  lrm.renewFor(prepareLease(set.getRenewalSetLease()), renewSetDur, null);

  // create a test lease to be managed
  logger.log(Level.FINE, "Creating the lease to be managed.");
  logger.log(Level.FINE, "Duration == Lease.FOREVER");
  TestLease testLease =
      leaseProvider.createNewLease(leaseOwner, Lease.FOREVER);

  // remove the lease
  Lease managedLease = set.remove(testLease);
  if (managedLease != null) {
      String message = "Removal of non-managed lease does NOT\n" +
           "return null as required.";
      throw new TestException(message);
  }
View Full Code Here

  LeaseRenewalService lrs = getLRS();

  // create a lease renewal set that hangs around a long time
  logger.log(Level.FINE, "Creating Set with lease duration of " +
        "Lease.FOREVER.");
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  lrm.renewFor(prepareLease(set.getRenewalSetLease()), Long.MAX_VALUE, null);

  // create a handback object
  MarshalledObject handback = new MarshalledObject(new Integer(99));

  // register listener to receive events
  EventRegistration evReg =
      set.setRenewalFailureListener(rrl, handback);
  evReg = prepareRegistration(evReg);

  // create a lease that will fail to renew
  logger.log(Level.FINE, "Creating the lease to be managed.");
  logger.log(Level.FINE, "Duration == " + renewGrant);
  TestLease testLease =
      leaseProvider.createNewLease(definiteOwner,
           rstUtil.durToExp(renewGrant));

  // start managing the lease for as long as we can
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  logger.log(Level.FINE, "Membership = Lease.FOREVER.");
  set.renewFor(testLease, Lease.FOREVER);
 
  // wait for the lease to expire
  rstUtil.waitForLeaseExpiration(testLease,
               "for client lease to expire.");

  /* Assert that the notification was received at approximately
     the lease expiration time */
  Long[] arrivalTimes = rrl.getArrivalTimes();

  // must at lease have received one event
  if (arrivalTimes.length == 0) {
      String message = "RenewalFailure event never received.";
      throw new TestException(message);
  }

  // must NOT have received more than one event
  if (arrivalTimes.length > 1) {
      String message = "Too many events received.";
      throw new TestException(message);
  }

  /* TESTING ASSERTION #1
     was the event received around the right time? */
  long leaseExpiration = testLease.getExpiration();
  long maxAllowed = leaseExpiration + latencySlop;

  long actualArrivalTime = arrivalTimes[0].longValue();

  // event must arrive within our assumed constraints
  if (actualArrivalTime < maxAllowed) {
      // we say event was received around the right time
      logger.log(Level.FINE, "Assertion #1 passes!");
  } else {
      /* There was a lag. This could be a network problem or an
         overloaded cpu but we will just have to assume that the
         specification was not met. */
      String message = "Assertion #1 failed ...\n" +
    "Event was not received within " + latencySlop +
    " milliseconds of client lease expiration.";
      throw new TestException(message);
  }

  /* TESTING ASSERTION #2
     the handback object is the one we expect. */
  RemoteEvent[] events = rrl.getEvents();
  MarshalledObject mObj = events[0].getRegistrationObject();
  if (handback.equals(mObj) == false) {
      String message = "Assertion #2 failed ...\n" +
    "Handback object does not match original.";
      throw new TestException(message);
  }
  logger.log(Level.FINE, "Assertion #2 passes!");
 
  /* TESTING ASSERTION #3
     The lease for the event registration is the same as the event's
     lease */
  if (rstUtil.isValidRenewFailEventReg(evReg, set) == false) {
      String message = "Assertion #3 failed ...\n" +
    "Event Registration is invalid." +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }
  logger.log(Level.FINE, "Assertion #3 passes!");

  /* TESTING ASSERTION #4
     a null listener results in a NullPointException. */
  set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  logger.log(Level.FINE, "Created Set with lease duration of " +
        "Lease.FOREVER.");
  try {
      evReg = set.setRenewalFailureListener(null, handback);
      evReg = prepareRegistration(evReg);
      if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
    String message = "Assertion #4 failed ...\n" +
        "Event Registration is invalid.";
    throw new TestException(message);
View Full Code Here

  // grab the ever popular LRS
  LeaseRenewalService lrs = getLRS();

  // create 2 renewal sets
  long renewSetDur = Lease.FOREVER;
  LeaseRenewalSet set01 = lrs.createLeaseRenewalSet(renewSetDur);
  set01 = prepareSet(set01);
  logger.log(Level.FINE, "Created Set 01 with lease duration of " +
        "Lease.FOREVER.");
  LeaseRenewalSet set02 = lrs.createLeaseRenewalSet(renewSetDur);
  set02 = prepareSet(set02);
  logger.log(Level.FINE, "Created Set 02 with lease duration of " +
        "Lease.FOREVER.");

  /* assert that attempting to add the set's lease to itself
     generates an IllegalArgumentException */
  Lease setLease = prepareLease(set01.getRenewalSetLease());
  logger.log(Level.FINE, "Lease is " + setLease);
  try {
      set01.renewFor(setLease, renewGrant);
      String message = "An attempt to add a renewal set's lease\n";
      message += " to itself has succeeded.";
      throw new TestException(message);
  } catch (IllegalArgumentException ex) {
      // success, keep on trucking ...
  }     

  /* assert that attempting to add the set01's lease to set02
     generates an IllegalArgumentException */
  try {
      set02.renewFor(setLease, renewGrant);
      String message = "An attempt to add a renewal set's lease\n";
      message += " to another set has succeeded.";
      throw new TestException(message);
  } catch (IllegalArgumentException ex) {
      // success, keep on trucking ...
  }     

  // create a lease that renews normally
  logger.log(Level.FINE, "Creating the lease to be managed.");
  logger.log(Level.FINE, "Duration == " + renewGrant);
  TestLease testLease =
      leaseProvider.createNewLease(leaseOwner,
           rstUtil.durToExp(renewGrant));

  // add the lease to set01
  set01.renewFor(testLease, renewGrant);

  /* assert that attempting to add the test lease to set02
     succeeds. */
  try {
      set02.renewFor(testLease, renewGrant);
      // success
  } catch (IllegalArgumentException ex) {
      String message = "An attempt to add a client lease\n";
      message += " to two different sets has failed.";
      throw new TestException(message, ex);
  }     

  /*
   * Assert that adding set01's lease to set02 succeeds if set01's
   * lease has been cancelled.
   */
  setLease.cancel();
  try {
      set02.renewFor(setLease, renewGrant);
  } catch (IllegalArgumentException ex) {
    throw new TestException("Failed to add an expired set "
          + "lease to another set",
          ex);
  }
View Full Code Here

  // get a lease renewal set w/ a fixed expiration time
  logger.log(Level.FINE, "Creating the lease renewal set.");
  logger.log(Level.FINE, "Duration = Lease.FOREVER");
  LeaseRenewalService lrs = getLRS();
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  lrm.renewFor(prepareLease(set.getRenewalSetLease()), Lease.FOREVER, null);
 
  // register listener to receive events
  logger.log(Level.FINE, "Registering listener for renewal failure" +
        " events.");
  set.setRenewalFailureListener(rrl  , null);

  // create 9 leases (3 for each type of owner)
  TestLease[] shortLease = new TestLease[3];
  TestLease[] exactLease = new TestLease[3];
  TestLease[] longLease = new TestLease[3];
  long duration = renewGrant;
  for (int i = 0; i < 3; ++i) {

      logger.log(Level.FINE, "Creating the short owner lease #" + i +
            " to be managed.");
      logger.log(Level.FINE, "Duration = " + duration);
      shortLease[i] =
    leaseProvider.createNewLease(shortGrantor[i],
               rstUtil.durToExp(duration));

      logger.log(Level.FINE, "Creating the exact owner lease #" + i +
            " to be managed.");
      logger.log(Level.FINE, "Duration = " + duration);
      exactLease[i] =
    leaseProvider.createNewLease(exactGrantor[i],
               rstUtil.durToExp(duration));

      logger.log(Level.FINE, "Creating the long owner lease #" + i +
            " to be managed.");
      logger.log(Level.FINE, "Duration = " + duration);
      longLease[i] =
    leaseProvider.createNewLease(longGrantor[i],
               rstUtil.durToExp(duration));

      duration += renewDelta;
  }

  /* add all leases to the renewal set. The leases belonging to the
     shortGrantor will terminate before the renewal set lease
     expires. */
  for (int i = 0; i < 3; ++i) {

      logger.log(Level.FINE, "Adding short owner lease #" + i +
            " to renewal set.\n" +
            "Renew duration = " + renewDuration +
            " milliseconds.\n" +
            "Membership = Long.MAX_VALUE");
      set.renewFor(shortLease[i], shortMembership, renewDuration);

      logger.log(Level.FINE, "Adding exact owner lease #" + i +
            " to renewal set.\n" +
            "Renew duration = " + renewDuration +
            " milliseconds.\n" +
            "Membership = Long.MAX_VALUE");
      set.renewFor(exactLease[i], Long.MAX_VALUE, renewDuration);

      logger.log(Level.FINE, "Adding long owner lease #" + i +
            " to renewal set.\n" +
            "Renew duration = " + renewDuration +
            " milliseconds.\n" +
            "Membership = Long.MAX_VALUE");
      set.renewFor(longLease[i], Long.MAX_VALUE, renewDuration);

  }

  // sleep past the short membership duration
  long sleepTime = shortMembership + (shortMembership / 4);
  rstUtil.sleepAndTell(sleepTime,
           "For short client leases to expire.");

  // grab all the remaining leases and assert that only 6 are left
  Lease[] leases = set.getLeases();
  if (leases.length != 6) {
      String message = "After set lease expiration, the set " +
    "contains " + leases.length + " leases, but " +
    "is expected to contain exactly 6.";
      throw new TestException(message);
View Full Code Here

     */
    protected boolean isValidEventReg(EventRegistration evReg,
              LeaseRenewalSet lrSet,
              long evID) throws TestException {
  // evReg must have been prepared by the caller
  LeaseRenewalSet source = (LeaseRenewalSet) evReg.getSource();
  source =
      (LeaseRenewalSet)
      QAConfig.getConfig().prepare("test.normRenewalSetPreparer",
                source);
  // lease isn't prepared, since only equals is called
  Lease lease = source.getRenewalSetLease();

  // test to ensure that all fields match
  boolean isSameSet = source.equals(lrSet);
  boolean isSameLease = lease.equals(lrSet.getRenewalSetLease());
  boolean isExpectedID = evReg.getID() == evID;

  // create a failure message (if necessary)
  failureReason = new String();
View Full Code Here

  logger.log(Level.FINE, "AddRemoveTest: 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();
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
 
  // get a lease for 2 hours (that ought to suffice).
  logger.log(Level.FINE, "Creating the lease to be managed.");
  long duration = 120 * 60 * 1000;
  TestLease testLease =
      leaseProvider.createNewLease(rstUtil.durToExp(duration));

  // start managing the lease for as long as we can
  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

  // create a renewal set
  logger.log(Level.FINE, "Creating renewal set with lease duration of " +
        "Lease.FOREVER.");
  long renewSetDur = Lease.FOREVER;
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);
  lrm.renewFor(prepareLease(set.getRenewalSetLease()), renewSetDur, null);

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

  // start managing the lease
  logger.log(Level.FINE, "Adding lease with membership of " +
        "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
View Full Code Here

  // Create two renewal sets with a lease of forever
  LeaseRenewalService lrs = getLRS();
  logger.log(Level.FINE, "Creating the lease renewal set #1 " +
        "with duration of Lease.FOREVER");
  LeaseRenewalSet set01 = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set01 = prepareSet(set01);
 
  logger.log(Level.FINE, "Creating the lease renewal set #2 with " +
        "duration of Lease.FOREVER");
  LeaseRenewalSet set02 = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set02 = prepareSet(set02);
 
  // create a set with a lease of 30 milliseconds
  logger.log(Level.FINE, "Creating the lease renewal set #3 with " +
        "duration of " + renewSetDur + " milliseconds.");
  LeaseRenewalSet set03 = lrs.createLeaseRenewalSet(renewSetDur);
  set03 = prepareSet(set03);
 
  // register listener to receive expiration warning events
  long minWarning = renewSetDur / 3;
  logger.log(Level.FINE, "Registering listener for expiration" +
        " warning events.");
  logger.log(Level.FINE, "minWarning = " + minWarning + " milliseconds");
  set01.setExpirationWarningListener(rrl, minWarning, null);
  set02.setExpirationWarningListener(rrl, minWarning, null);
  set03.setExpirationWarningListener(rrl, minWarning, null);

  // wait for the lease on set03 to expire
  rstUtil.waitForRemoteEvents(rrl, 1, renewSetDur);

  // assert we received exactly one event
  RemoteEvent[] events = rrl.getEvents();
  if (events.length != 1) {
      String message = "Listener received " + events.length +
    " events but is required to receive exactly 1.";
      throw new TestException(message);
  }

  // assert that the source is the one that we expect
  LeaseRenewalSet expiredSet =
      (LeaseRenewalSet) events[0].getSource();
  if (expiredSet.equals(set03) == false) {
      String message = "The source of the event was not the set" +
    " that caused the ExpirationWarningEvent.";
      throw new TestException(message);
  }
    }
View Full Code Here

TOP

Related Classes of net.jini.lease.LeaseRenewalSet

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.