Package net.jini.lease

Examples of net.jini.lease.LeaseRenewalService


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

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

  // 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.");
View Full Code Here


    public void run() throws Exception {

  // Announce where we are in the test
  logger.log(Level.FINE, "RenewalFailureIndefiniteTest: In run() method.");
  // 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
View Full Code Here

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

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

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

  logger.log(Level.FINE, "EventSequenceFailTest: 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 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.");
View Full Code Here

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

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

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

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

  logger.log(Level.FINE, "LeaseExpirationTest: In run() method.");

  // get a lease renewal set w/ duration of as long as possible
  logger.log(Level.FINE, "Creating the lease renewal set.");
  logger.log(Level.FINE, "Duration = Lease.FOREVER.");
  LeaseRenewalService lrs = getLRS();
  set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  lrm.renewFor(prepareLease(set.getRenewalSetLease()), Lease.FOREVER, null);
 
  /**************** Bad Object Exception Tests ***************/

 
View Full Code Here

  logger.log(Level.FINE, "AssocRenewalFailSetTest: 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 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" +
View Full Code Here

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

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

  // 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.");
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.");
View Full Code Here

TOP

Related Classes of net.jini.lease.LeaseRenewalService

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.