Package net.jini.lease

Examples of net.jini.lease.LeaseRenewalSet


  // 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

  // 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

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

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

  // 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
  long membershipDur = renewGrant / 2;
  logger.log(Level.FINE, "Adding lease with membership of " +
        membershipDur + " milliseconds.");
  long startTrip = System.currentTimeMillis();
  set.renewFor(testLease, membershipDur);
  long endTrip = System.currentTimeMillis();
  // widen roundtrip to eliminate intermittent failures
  long roundTrip = (endTrip - startTrip) * 10;

  // sleep until the membership duration almost expires
  rstUtil.sleepAndTell(membershipDur * 2 / 3,
           "2/3 membership duration.");

  // assert that the lease has not been removed from the set
  Lease[] leaseArray = set.getLeases();

  if (leaseArray.length < 1) {
      String message = "The lease was removed from the renewal set" +
    " prematurely.";
      throw new TestException(message);
  }

  if (leaseArray.length > 1) {
      String message = "Error in test: More than one lease was" +
    "added to the lease renewal set.";
      throw new TestException(message);
  }

  // expiration time must remain unaltered
  long currentExpTime = leaseArray[0].getExpiration();
  long deltaExpTime = currentExpTime - originalExpTime;

  if (deltaExpTime > roundTrip) {
      String message = "The expiration of the lease has been altered."
    + "\n   originalExpTime = " + originalExpTime
    + "\n   currentExpTime = " + currentExpTime
    + "\n   deltaExpTime = " + deltaExpTime
    + "\n   roundTrip = " + roundTrip;
      throw new TestException(message);
  }

  // sleep again so that the test lease expires
  rstUtil.sleepAndTell(membershipDur / 3,
           "1/3 membership duration time.");

  // assert that the lease was removed from the set
  leaseArray = set.getLeases();
  if (leaseArray.length != 0) {
      String message = "The lease was not removed from the renewal" +
    " set as expected.";
      throw new TestException(message);
  }
View Full Code Here

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

  // Create three renewal sets with a lease of 40000 milliseconds
  LeaseRenewalService lrs = getLRS();
  logger.log(Level.FINE, "Creating the lease renewal set with duration" +
        " of " + renewSetDur + " milliseconds");
  LeaseRenewalSet set01 = lrs.createLeaseRenewalSet(renewSetDur);
  set01 = prepareSet(set01);
  lrm.renewFor(prepareLease(set01.getRenewalSetLease()), renewSetDur, null);
 
  logger.log(Level.FINE, "Creating the lease renewal set with duration" +
        " of " + renewSetDur + " milliseconds");
  LeaseRenewalSet set02 = lrs.createLeaseRenewalSet(renewSetDur);
  set02 = prepareSet(set02);
  lrm.renewFor(prepareLease(set02.getRenewalSetLease()), renewSetDur, null);

  logger.log(Level.FINE, "Creating the lease renewal set with duration" +
        " of " + renewSetDur + " milliseconds");
  LeaseRenewalSet set03 = lrs.createLeaseRenewalSet(renewSetDur);
  set03 = prepareSet(set03);
  lrm.renewFor(prepareLease(set03.getRenewalSetLease()), renewSetDur, null);
 
  // register the listener to receive expiration events
  logger.log(Level.FINE, "Registering listener to receive " +
        "ExpirationWarngingEvents for set #1.");
  long minWarning = renewSetDur / 3;
  logger.log(Level.FINE, "minWarning = " + minWarning + " milliseconds");
  EventRegistration reg01 =
      set01.setExpirationWarningListener(rrl, minWarning, null);
  reg01 = prepareRegistration(reg01);

  // validate the registration (just for grins)
  if (rstUtil.isValidExpWarnEventReg(reg01, set01) == false) {
      String message = "Registration #1 is invalid because:\n" +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }

  logger.log(Level.FINE, "Registering listener to receive " +
        "ExpirationWarngingEvents for set #2.");
  logger.log(Level.FINE, "minWarning = " + minWarning + " milliseconds");
  EventRegistration reg02 =
      set02.setExpirationWarningListener(rrl, minWarning, null);
  reg02 = prepareRegistration(reg02);

  // validate the registration (just for grins)
  if (rstUtil.isValidExpWarnEventReg(reg02, set02) == false) {
      String message = "Registration #2 is invalid because:\n" +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }

  logger.log(Level.FINE, "Registering listener to receive " +
        "ExpirationWarngingEvents for set #3.");
  logger.log(Level.FINE, "minWarning = " + minWarning + " milliseconds");
  EventRegistration reg03 =
      set03.setExpirationWarningListener(rrl, minWarning, null);
  reg03 = prepareRegistration(reg03);

  // validate the registration (just for grins)
  if (rstUtil.isValidExpWarnEventReg(reg03, set03) == false) {
      String message = "Registration #3 is invalid because:\n" +
View Full Code Here

  // IllegalArgumentException should be thrown with arg of -99
  logger.log(Level.FINE, "Creating the lease renewal set with " +
             "-99 duration.");
  try {
      LeaseRenewalService lrs = getLRS();
      LeaseRenewalSet set = lrs.createLeaseRenewalSet(-99);
      set = prepareSet(set);
      String message = "IllegalArgumentException expected from\n";
      message += "createLeaseRenewalSet(-99)";
      throw new TestException(message);
  } catch (IllegalArgumentException ex) {
      // we passed so just continue
      logger.log(Level.FINE, "Caught IllegalArgumentException as " +
            "expected.");
  }
 
  // No exception thrown for Lease.ANY argument
  logger.log(Level.FINE, "Creating the lease renewal set with " +
             "Lease.ANY duration.");
  try {
      LeaseRenewalService lrs = getLRS();
      LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.ANY);
      set = prepareSet(set);
      // we passed so just continue
      logger.log(Level.FINE, "Caught no exceptions as expected.");
  } catch (IllegalArgumentException ex) {
      String message = "IllegalArgumentException caught from\n";
      message += "createLeaseRenewalSet(Lease.ANY)";
      throw new TestException(message, ex);
  }

  // No exception thrown for Lease.FOREVER argument
  logger.log(Level.FINE, "Creating the lease renewal set with " +
        "Lease.FOREVER duration.");
  try {
      LeaseRenewalService lrs = getLRS();
      LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
      set = prepareSet(set);
      // we passed so just continue
      logger.log(Level.FINE, "Caught no exceptions as expected.");
  } catch (IllegalArgumentException ex) {
      String message = "IllegalArgumentException caught from\n";
      message += "createLeaseRenewalSet(Lease.FOREVER)";
      throw new TestException(message, ex);
  }

  // No exception thrown for argument value of 0
  logger.log(Level.FINE, "Creating the lease renewal set with " +
        "0 duration.");
  try {
      LeaseRenewalService lrs = getLRS();
      LeaseRenewalSet set = lrs.createLeaseRenewalSet(0);
      set = prepareSet(set);
      // we passed so just continue
      logger.log(Level.FINE, "Caught no exceptions as expected.");
  } catch (IllegalArgumentException ex) {
      String message = "IllegalArgumentException caught from\n";
      message += "createLeaseRenewalSet(0)";
      throw new TestException(message, ex);
  }

  // No exception thrown for argument value of 1
  logger.log(Level.FINE, "Creating the lease renewal set with " +
        "1 duration.");
  try {
      LeaseRenewalService lrs = getLRS();
      LeaseRenewalSet set = lrs.createLeaseRenewalSet(1);
      set = prepareSet(set);
      // we passed so just continue
      logger.log(Level.FINE, "Caught no exceptions as expected.");
  } catch (IllegalArgumentException ex) {
      String message = "IllegalArgumentException caught from\n";
View Full Code Here

  // 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);
 
  // register listener #1 to receive events
  logger.log(Level.FINE, "Registering listener #1 for renewal failure" +
        " events.");
  set.setRenewalFailureListener(rrl01, null);

  /* create 8 test leases which will throw definite exceptions
     and add then to the renewal set. Each lease's expriation
     time is 30 seconds greater than the previous one. */
  long duration = 0;
  TestLease[] lease = new TestLease[8];
      TestLeaseProvider leaseProvider = null;
  for (int i = 0; i < 8; ++i) {
      duration = renewGrant * (i+1);
      logger.log(Level.FINE, "Creating lease #" + i +
            " with duration of " + duration +
            " milliseconds.");
      leaseProvider = (i < 4) ? earlyLeaseProvider :
              lateLeaseProvider;
      lease[i] =
    leaseProvider.createNewLease(owner,
               rstUtil.durToExp(duration));
      logger.log(Level.FINE, "Adding lease #" + i + " to renewal set " +
            "with membership duration = Lease.FOREVER.");
      set.renewFor(lease[i], Lease.FOREVER);
  }

  // wait for the listener to receive four events.
  long timeOut = duration;
  rstUtil.waitForRemoteEvents(rrl01, 4, timeOut);

  // assign the other listener to receive events
  logger.log(Level.FINE, "Replacing listener #1 with listener #2 to" +
        " receive renewal failure events.");
  set.setRenewalFailureListener(rrl02, null);

  // wait for the other listener to receive four events.
  rstUtil.waitForRemoteEvents(rrl02, 4, timeOut);

  // report on how many events were received by each (must be >= 3)
View Full Code Here

  // get the service for test
  LeaseRenewalService lrs = getLRS();

  // create a lease renewal set
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);

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

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

  if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
      String message = "Event Registration is invalid.";
      message += rstUtil.getFailureReason();
      throw new TestException(message);
  }

  // allow the set's lease to expire
  rstUtil.waitForRemoteEvents(rrl, 1, renewSetDur);

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

  // must at lease have received one event
  if (arrivalTimes.length == 0) {
      String message = "ExpirationWarning 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? */
  String prop = "com.sun.jini.test.spec.renewalservice." +
         "slop_percent_tolerance";
  int tolerance =
      getConfig().getIntConfigVal(prop, SLOP_PERCENT_TOLERANCE);
  logger.log(Level.FINE, "Allowing a slop tolerance of (+/-)" +
        tolerance + "% of expected warning time.");

  long leaseExpiration = prepareLease(set.getRenewalSetLease()).getExpiration();
  long idealArrival = leaseExpiration - minWarning;
  long arrivalSlop = minWarning * tolerance / 100;
  long minAllowed = idealArrival - arrivalSlop;
  long maxAllowed = idealArrival + arrivalSlop;
  long actualArrivalTime = arrivalTimes[0].longValue();

  if (actualArrivalTime > minAllowed &&
      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 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";
      message += "Event was not received +/- " + arrivalSlop;
      message += " milliseconds.";
      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";
      message += "Handback object does not match original.";
      throw new TestException(message);
  }
  logger.log(Level.FINE, "Assertion #2 passes!");
 
  /* TESTING ASSERTION #3
     a null listener results in a NullPointException. */
  set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);
  logger.log(Level.FINE, "Created Set with lease duration of " +
        renewSetDur + " milliseconds");
  try {
      evReg = set.setExpirationWarningListener(null, minWarning,
                 handback);
      evReg = prepareRegistration(evReg);
      if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
    String message = "Assertion #3 failed ...\n";
    message += "Event Registration is invalid.";
    throw new TestException(message);
      }

      String message = "Assertion #3 failed ...\n";
      message += "Registration of null listener was allowed.";
      throw new TestException(message);

  } catch (NullPointerException ex) {
      // success, continue with the rest of the test
      logger.log(Level.FINE, "Assertion #3 passes!");
  }
 
  /* TESTING ASSERTION #4
     a negative value for minWarning results in an
     IllegalArgumentException */
  try {
      evReg = set.setExpirationWarningListener(rrl, -10, handback);
      evReg = prepareRegistration(evReg);
      if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
    String message = "Assertion #4 failed ...\n";
    message += "Event Registration is invalid.";
    throw new TestException(message);
      }

      String message = "Assertion #4 failed ...\n";
      message += "A negative minWarning value was allowed.";
      throw new TestException(message);
  } catch (IllegalArgumentException ex) {
      // success, continue with the rest of the test
  }
 
  // edge case (try 0 to ensure it is allowed)
  try {
      evReg = set.setExpirationWarningListener(rrl, 0, handback);
      evReg = prepareRegistration(evReg);
      if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
    String message = "Assertion #4 failed ...\n";
    message += "Event Registration is invalid.";
    throw new TestException(message);
      }

      // success, continue with the rest of the test

  } catch (IllegalArgumentException ex) {
      String message = "Assertion #4 failed ...\n";
      message += "A minWarning value of 0 was not allowed.";
      logger.log(Level.SEVERE, message, ex);
      throw new TestException(message, ex);
  }
  logger.log(Level.FINE, "Assertion #4 passes!");
 
  /* TESTING ASSERTION #5
     a minWarning value greater than the duration of the set's
     lease causes an immediate delivery of the
     ExpirationWarningEvent */

  // forget about all previous events
  rrl.clear();
  events = rrl.getEvents();
  if (events.length > 0) {
      String message = "Assertion #5 failed ...\n";
      message += "An expected error. RemoteListener did";
      message += " not reset properly.";
      throw new TestException(message);
  }
 
  // create a renewal set
  set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);
  logger.log(Level.FINE, "Created Set with lease duration of " +
        renewSetDur + " milliseconds");

  // register with minWarning after lease expiration
  leaseExpiration = prepareLease(set.getRenewalSetLease()).getExpiration();
  long duration = rstUtil.expToDur(leaseExpiration);
  long lateWarning = duration + 10000;
  evReg =
      set.setExpirationWarningListener(rrl, lateWarning, handback);
  evReg = prepareRegistration(evReg);
  logger.log(Level.FINE, "minWarning on lease expiration is " +
        lateWarning + " milliseconds");
 
  if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
      String message = "Assertion #5 failed ...\n";
      message += "Event Registration is invalid.";
      throw new TestException(message);
  }

  /* we should have the event already but still, perform check ...*/
  rstUtil.waitForRemoteEvents(rrl, 1, renewSetDur);

  // check to see if event has arrived there
  arrivalTimes = rrl.getArrivalTimes();
  if (arrivalTimes.length == 0) {
      String message = "Assertion #5 failed ...\n";
      message += "Remote event was never delivered.";
      throw new TestException(message);
  }
 
  // check for extra event received
  if (arrivalTimes.length > 1) {
      String message = "Assertion #5 failed ...\n";
      message += "Spurious RemoteEvent(s) detected.";
      throw new TestException(message);
  }
 
  // Check that the arrival time is in range
  idealArrival = prepareLease(set.getRenewalSetLease()).getExpiration();
  arrivalSlop = latencySlop;
  maxAllowed = idealArrival + arrivalSlop;
  actualArrivalTime = arrivalTimes[0].longValue();

  if (actualArrivalTime < maxAllowed) {
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.