Package net.jini.lease

Examples of net.jini.lease.LeaseRenewalSet


  // service under test
  LeaseRenewalService lrs = getLRS();

  // create a lease renewal set that hangs around a long time
  long renewSetDur = Lease.FOREVER;
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);
  logger.log(Level.FINE, "Created Set with lease duration of " +
        "Lease.FOREVER.");

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

  // check event registration (not formally part of this test)
  if (rstUtil.isValidRenewFailEventReg(evReg, set) == false) {
      String message = "Registration is invalid because:\n" +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }

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

  // start managing the lease for as long as we can
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  set.renewFor(testLease, Long.MAX_VALUE);
 
  // wait for the event to arrive
  long timeout = renewGrant * 2;
  boolean gotEvent = rstUtil.waitForRemoteEvents(rrl, 1, timeout);
  if (gotEvent == false) {
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 and add to renewal set
  Lease testLease[] = new Lease[3];
  for (int i = 0; i < 3; ++i) {
      logger.log(Level.FINE, "Creating the lease to be managed.");
      logger.log(Level.FINE, "Duration == " + renewGrant);
      testLease[i] = leaseProvider.createNewLease
    (leaseOwner, rstUtil.durToExp(renewGrant));

      long membershipDur = renewGrant * (i+1);
      // start managing the lease
      logger.log(Level.FINE, "Adding lease with membership of " +
            membershipDur + " milliseconds.");
      set.renewFor(testLease[i], membershipDur);
  }

  // take a snap shot of the leases (should have them all)
  Lease[] leaseArray01 = set.getLeases();

  // sleep until the membership expiration ends for lease #1
  rstUtil.sleepAndTell(renewGrant,
           "for membership duration on lease #1 " +
           "to expire.");

  // take another snap shot (all but #1 should be present)
  Lease[] leaseArray02 = set.getLeases();

  // sleep again so that that lease #2 membership expires
  rstUtil.sleepAndTell(renewGrant,
           "for membership duration on lease #2 " +
           "to expire.");

  // take another snap shot (only #3 should be left)
  Lease[] leaseArray03 = set.getLeases();

  // sleep again so that that lease #3 membership expires
  rstUtil.sleepAndTell(renewGrant,
           "for membership duration on lease #3 " +
           "to expire.");

  // take another snap shot (the array should be empty)
  Lease[] leaseArray04 = set.getLeases();

  // assert that array #1 has all three leases
  int numberOfLeases = leaseArray01.length;
  if (numberOfLeases != 3) {
      String message = "Lease array #1 should contain 3 leases" +
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

  // Create 2 renewal sets for the supplied duration
  LeaseRenewalService lrs = getLRS();

  logger.log(Level.FINE, "Creating the lease renewal set #1 with " +
        "duration of " + renewSetDur + " milliseconds.");
  LeaseRenewalSet set01 = lrs.createLeaseRenewalSet(renewSetDur);
  set01 = prepareSet(set01);

  logger.log(Level.FINE, "Creating the lease renewal set #2 with " +
        "duration of " + renewSetDur + " milliseconds.");
  LeaseRenewalSet set02 = lrs.createLeaseRenewalSet(renewSetDur);
  set02 = prepareSet(set02);

  // register a failing listener for expiration warning events
  long minWarning = renewSetDur * 2 / 10;
  logger.log(Level.FINE, "Registering failing listener #1 with set #1" +
        " for\n" + "expiration warning events : " +
        "minWarning = " + minWarning);
  set01.setExpirationWarningListener(failingListener01, minWarning,
             null);

  // register a normal listener for expiration warning events
  logger.log(Level.FINE, "Registering normal listener #1 with set #2" +
        " for\n" + "expiration warning events : " +
        "minWarning = " + minWarning);
  set02.setExpirationWarningListener(normalListener01, minWarning,
             null);

  // register a failing listener for renewal failure events
  logger.log(Level.FINE, "Registering failing listener #2 with set #2" +
        " for renewal failure events");
  set02.setRenewalFailureListener(failingListener02, null);

  // register a normal listener for renewal failure events
  logger.log(Level.FINE, "Registering normal listener #2 with set #1" +
        " for renewal failure events");
  set01.setRenewalFailureListener(normalListener02, null);

  // create a 2 leases that will fail on renewal
  long renewGrant = renewSetDur * 5 / 10;
  logger.log(Level.FINE, "Creating failing lease #1 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease01 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
 
  logger.log(Level.FINE, "Creating failing lease # 2 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease02 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
 
  // add lease01 to set01 and lease02 to set02
  logger.log(Level.FINE, "Adding lease #1 to set #1");
  set01.renewFor(lease01, Long.MAX_VALUE);
  logger.log(Level.FINE, "Adding lease #2 to set #2");
  set02.renewFor(lease02, Long.MAX_VALUE);
 
  /* wait for the expiration warning events to arrive.
     By the time they do, all RenewalFailureEvents should also
     have arrived. */
  rstUtil.waitForRemoteEvents(normalListener01, 1, renewSetDur);
  rstUtil.waitForRemoteEvents(failingListener01, 1, renewSetDur);
 
  // Assert that we had one call each on the failing listeners
  RemoteEvent[] events01 = failingListener01.getEvents();
  RemoteEvent[] events02 = failingListener02.getEvents();

  if (events01.length != 1) {
      String message = "Failing Listener #1 received " +
    events01.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  if (events02.length != 1) {
      String message = "Failing Listener #2 received " +
    events02.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  // Assert that we had one call each on the normal listeners
  events01 = normalListener01.getEvents();
  events02 = normalListener02.getEvents();

  if (events01.length != 1) {
      String message = "Normal Listener #1 received " +
    events01.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  if (events02.length != 1) {
      String message = "Normal Listener #2 received " +
    events02.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  // Assert we can renew both set's leases without error
  renewSetDur = renewSetDur * 6 / 10; // use a shorter time

  try {
      logger.log(Level.FINE, "Renewing set #1's lease with duration " +
            "of " + renewSetDur + " milliseconds.");
      prepareLease(set01.getRenewalSetLease()).renew(renewSetDur);
  } catch (UnknownLeaseException ex) {
      String message = "Attempt to renew lease for renewal set\n" +
    "#1 has failed due to " + ex;
      throw new TestException(message, ex);
  }     

  try {
      logger.log(Level.FINE, "Renewing set #2's lease with duration " +
            "of " + renewSetDur + " milliseconds.");
      prepareLease(set02.getRenewalSetLease()).renew(renewSetDur);
  } catch (UnknownLeaseException ex) {
      String message = "Attempt to renew lease for renewal set\n" +
    "#2 has failed due to " + ex;
      throw new TestException(message, ex);
  }     

  /* Assert that calls to remove do not result in a
     NoSuchObjectException. Given the renewal of the leases
     above this assertion is probably somewhat redundant. */

  try {
      Lease managedLease = set01.remove(lease01);
  } catch (NoSuchObjectException ex) {
      String message = "Attempt to call remove on set\n" +
    "#1 has failed due to a NoSuchObjectException";
      throw new TestException(message, ex);
  }     

  try {
      Lease managedLease = set02.remove(lease02);
  } catch (NoSuchObjectException ex) {
      String message = "Attempt to call remove on set\n" +
    "#2 has failed due to a NoSuchObjectException";
      throw new TestException(message, ex);
  }     

  // Restore both sets to original configurations
  renewGrant = renewSetDur * 3 / 10;
  logger.log(Level.FINE, "Creating failing lease #3 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease03 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
  logger.log(Level.FINE, "Adding lease #3 to set #1");
  set01.renewFor(lease03, Long.MAX_VALUE);
 
  logger.log(Level.FINE, "Creating failing lease #4 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease04 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
  logger.log(Level.FINE, "Adding lease #4 to set #2");
  set02.renewFor(lease04, Long.MAX_VALUE);
 
  /*
   * Wait until the expiration warning event rolls in.
   * By that time the renewal failure event should also have arrived.
   */
 
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 two leases that will not fail on renewal
  logger.log(Level.FINE, "Creating lease #1 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease01 =
      leaseProvider.createNewLease(succeedingOwner,
           rstUtil.durToExp(renewGrant));
  set.renewFor(lease01, Long.MAX_VALUE);
 
  logger.log(Level.FINE, "Creating lease #2 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease02 =
      leaseProvider.createNewLease(succeedingOwner,
           rstUtil.durToExp(renewGrant));
  set.renewFor(lease02, Long.MAX_VALUE);

  // create the lease to be managed
  long longerGrant = renewGrant * 2;
  logger.log(Level.FINE, "Creating lease #3 with duration of " +
        longerGrant + " milliseconds.");
  TestLease lease03 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(longerGrant));
  set.renewFor(lease03, Long.MAX_VALUE);

  // wait for the failing lease to renew
  rstUtil.waitForRemoteEvents(rrl, 1, longerGrant);

  // assert we only received 1 event
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);

  // start managing the lease forever
  logger.log(Level.FINE, "Adding lease with membership of " +
        "Lease.FOREVER");
  set.renewFor(testLease, Lease.FOREVER);

  // remove the lease
  Lease managedLease = set.remove(testLease);
  if (managedLease.equals(testLease) == false) {
      String message = "Lease removed does not match the lease\n" +
           "originally added to the set.";
      throw new TestException(message);
  }
View Full Code Here

  // get a lease renewal set w/ duration of 1/5 the max grant time
  logger.log(Level.FINE, "Creating the lease renewal set.");
  setLeaseGrant = renewGrant / 5;
  logger.log(Level.FINE, "Lease duration == " + setLeaseGrant);
  LeaseRenewalService lrs = getLRS();
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(setLeaseGrant);
  set = prepareSet(set);
 
  // get three leases with their repective durations
  logger.log(Level.FINE, "Creating the leases to be managed.");

  logger.log(Level.FINE, "Duration (lease #1) == " + grant1);
  TestLease testLease1 =
      leaseProvider.createNewLease(owner, rstUtil.durToExp(grant1));

  logger.log(Level.FINE, "Duration (lease #2) == " + grant2);
  TestLease testLease2 =
      leaseProvider.createNewLease(owner, rstUtil.durToExp(grant2));

  logger.log(Level.FINE, "Duration (lease #3) == " + grant3);
  TestLease testLease3 =
      leaseProvider.createNewLease(owner, rstUtil.durToExp(grant3));

  // start managing the leases for as long as we can
  logger.log(Level.FINE, "Adding managed leases to lease renewal set.");
  set.renewFor(testLease1, Lease.FOREVER);
  set.renewFor(testLease2, Lease.FOREVER);
  set.renewFor(testLease3, Lease.FOREVER);
 
  // allow the lease of the renewal set to expire
  logger.log(Level.FINE, "Getting the renewal set lease.");
  Lease setLease = prepareLease(set.getRenewalSetLease());
  boolean success = expireRenewalSetLease(setLease);
  if (success == false) {
      String message = "Lease did not expire as expected.\n";
      throw new TestException(message);
  }

  // assert that any attempt to use the set results in an exception
  try {
      Lease managedLease = set.remove(testLease1);
      String message = "Performed successful remove operation on\n";
      message += " renewal set after its lease had expired.";
      throw new TestException(message);
  } catch (NoSuchObjectException ex) {
      // we passed so just keep on going ...
  }

  try {
      Lease managedLease = leaseProvider.createNewLease(owner,
                    renewGrant);
      set.renewFor(managedLease, Lease.FOREVER);
      managedLease.cancel();
      String message = "Performed successful add operation on\n";
      message += " renewal set after its lease had expired.";
      throw new TestException(message);
  } catch (NoSuchObjectException ex) {
View Full Code Here

      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);
      logger.log(Level.FINE, "Expiration = " + anyExp);
      String message = "LRS granted a time in the past when";
      message += " given Lease.FORVER as duration request.";
View Full Code Here

  // create a lease renewal set that hangs around a long time
  logger.log(Level.FINE, "Creating set with lease duration of " +
        "Lease.FOREVER.");
  long renewSetDur = Lease.FOREVER;
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);

  // register the listeners to receive renewal failure events
  set.setRenewalFailureListener(failingListener, null);

  // create 3 leases that will fail during renewal attempts
  logger.log(Level.FINE, "Creating failing lease #1 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease01 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
 
  logger.log(Level.FINE, "Creating failing lease #2 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease02 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
 
  logger.log(Level.FINE, "Creating failing lease #3 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease03 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
 
  // add all the leases to the set
  logger.log(Level.FINE, "Adding client leases to renewal set.");
  set.renewFor(lease01, Long.MAX_VALUE);
  set.renewFor(lease02, Long.MAX_VALUE);
  set.renewFor(lease03, Long.MAX_VALUE);

  // wait for the failures to roll in ...
  rstUtil.waitForRemoteEvents(failingListener, 3, renewGrant * 2);

  // assert that the three events have arrived
  long numberOfFailedEvents = failingListener.getEvents().length;
  if (numberOfFailedEvents < 3) {
      String message = "The failing remote listener received " +
    numberOfFailedEvents + " events but was required to " +
    "receive at least 3.";
      throw new TestException(message);
  }

  // Replace the failing listener with a normal one
  logger.log(Level.FINE, "Replacing failing listener with a" +
        " succeeding one.");
  set.setRenewalFailureListener(normalListener, null);

  // wait for events to get forwarded
  rstUtil.waitForRemoteEvents(normalListener, 3, renewGrant * 2);
 
  // assert that the normal listener received at least one event
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.