Package net.jini.lease

Examples of net.jini.lease.LeaseRenewalSet


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

  // 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 a listener to receive renewal failure events
  logger.log(Level.FINE, "Registering listener to receive " +
        "RenewalFailureEvents.");
  EventRegistration reg = set.setRenewalFailureListener(rrl, null);
  reg = prepareRegistration(reg);

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

  // create the three leases to be managed
  logger.log(Level.FINE, "Creating lease #1 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease01 =
      leaseProvider.createNewLease(failingOwner,
           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(failingOwner,
           rstUtil.durToExp(renewGrant));
  set.renewFor(lease02, Long.MAX_VALUE);

  logger.log(Level.FINE, "Creating lease #3 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease03 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
  set.renewFor(lease03, Long.MAX_VALUE);

  // sleep until the leases have expired.
  rstUtil.waitForRemoteEvents(rrl, 3, renewGrant * 2);

  // ensure that we have exactly 3 events
View Full Code Here

  // clear the listener so we can reuse it
  rrl.clear();

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

  // register listener to receive events
  logger.log(Level.FINE, "Registering listener for renewal failure " +
        "events.");
  set.setRenewalFailureListener(rrl, null);
 
  /* create 10 test leases which will throw definite exceptions
     and add each to the renewal set. */
  for (int i = 0; i < NUMBER_OF_TEST_LEASES; ++i) {
      logger.log(Level.FINE, "Creating lease with duration of " +
            renewGrant + " milliseconds.");
      testLease[i] =
    leaseProvider.createNewLease(owner,
               rstUtil.durToExp(renewGrant));
      set.renewFor(testLease[i], Lease.FOREVER);
  }

  // wait until the test leases have expired
  rstUtil.waitForRemoteEvents(rrl, NUMBER_OF_TEST_LEASES,
            renewGrant * 2);
 
View Full Code Here

  LeaseRenewalService lrs = getLRS();

  // create a renewal set for the requested duration
  logger.log(Level.FINE, "Creating renewal set w/ duration = " +
        renewSetDur + " milliseconds.");
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(renewSetDur);
  set = prepareSet(set);

  // register listener #1 to receive events
  logger.log(Level.FINE, "Registering listener #1 for warning events.");
  logger.log(Level.FINE, "minWarning = " + minWarning + ".");
  set.setExpirationWarningListener(rrl01, minWarning, null);

  /* We want to wait for three renewals (or more)
     before switching listeners. Some implementations that refuse
     to give out leases for the request grant duration may send
     more events in that time. This is okay, it does not effect
     the validity of the test. */
  long timeOut = renewSetDur * 3;
  rstUtil.waitForRemoteEvents(rrl01, 3, timeOut);
 
  // start listening immediately with listener #2
  logger.log(Level.FINE, "Registering listener #2 for warning events.");
  logger.log(Level.FINE, "minWarning = " + minWarning + ".");
  set.setExpirationWarningListener(rrl02, minWarning, null);

  // now lets wait for 3 more events to arrive
  rstUtil.waitForRemoteEvents(rrl02, 3, timeOut);

  // report on how many events were received by each (3 = minimum)
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

  // 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));
  testLease.setSerialFormat(Lease.ABSOLUTE);
  long originalExpTime = testLease.getExpiration();

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

  // sleep until the test lease expires
  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 + ").";
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 3 test leases to be managed
  logger.log(Level.FINE, "Creating a normal lease #1 to be managed.");
  logger.log(Level.FINE, "Duration == Lease.FOREVER");
  TestLease testLease01 =
      leaseProvider.createNewLease(leaseOwner, Lease.FOREVER);

  logger.log(Level.FINE, "Creating a normal lease #2 to be managed.");
  logger.log(Level.FINE, "Duration == Lease.FOREVER");
  TestLease testLease02 =
      leaseProvider.createNewLease(leaseOwner, Lease.FOREVER);

  logger.log(Level.FINE, "Creating a normal lease #3 to be managed.");
  logger.log(Level.FINE, "Duration == Lease.FOREVER");
  TestLease testLease03 =
      leaseProvider.createNewLease(leaseOwner, Lease.FOREVER);

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

  logger.log(Level.FINE, "Adding normal lease #2 with membership of " +
        "Lease.FOREVER");
  set.renewFor(testLease02, Lease.FOREVER);

  logger.log(Level.FINE, "Adding normal lease #3 with membership of " +
        "Lease.FOREVER");
  set.renewFor(testLease03, Lease.FOREVER);

  // create 2 unreadable test leases to be managed
  logger.log(Level.FINE, "Creating an unreadable lease #1 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 #2 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 #1 with membership" +
        " of Lease.FOREVER");
  set.renewFor(specialLease01, Lease.FOREVER);

  logger.log(Level.FINE, "Adding unreadable lease #2 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

  logger.log(Level.FINE, "ExpireRemoveTest: 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.");
  logger.log(Level.FINE, "Duration == " + renewGrant);
  TestLease testLease =
      leaseProvider.createNewLease(owner,
           rstUtil.durToExp(renewGrant));

  // start managing the lease for only half of its grant time
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  long membership = renewGrant / 2;
  logger.log(Level.FINE, "Membership duration == " + membership);
  set.renewFor(testLease, membership);
 
  // sleep for 3/4 of the renewGrant time
  long sleeptime = renewGrant * 3 / 4;
  logger.log(Level.FINE, "Waiting " + sleeptime + " milliseconds for " +
        "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

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.