Package net.jini.core.lease

Examples of net.jini.core.lease.Lease


        SimpleEntry sampleEntry1 = new SimpleEntry("TestEntry #1", 1);
        SimpleEntry sampleEntry2 = new SimpleEntry("TestEntry #2", 2);
        SimpleEntry result;
        long leaseTime1 = timeout1;
        long leaseTime2 = timeout2;
        Lease lease1 = null;
        Lease lease2 = null;
        Transaction txn;

        // first check that space is empty
        if (!checkSpace(space)) {
            throw new TestException(
View Full Code Here


        long expirTime1;
        long expirTime2;
        long leaseTime1 = timeout1;
        long leaseTime2 = timeout2;
        long leaseTime3 = leaseTime1 + checkTime;
        Lease lease1 = null;
        Lease lease2 = null;
        Transaction txn;

        // first check that space is empty
        if (!checkSpace(space)) {
            throw new TestException(
                    "Space is not empty in the beginning.");
        }

        // create the non null transaction
        txn = getTransaction();

        // write an entry with Lease.ANY lease time within the transaction
        try {
            lease1 = space.write(sampleEntry1, txn, Lease.ANY);
        } catch (IllegalArgumentException iae) {
            throw new TestException(
                    "IllegalArgumentException was thrown while trying to"
                    + " write " + sampleEntry1 + " with Lease.ANY value for"
                    + " lease time within the transaction.");
        }
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();

        /*
         * check that returned lease is not equal to null,
         * expiration time is not less then current time
         */
        if (lease1 == null) {
            throw new TestException(
                    "performed write with Lease.ANY lease time within the"
                    + " non null transaction, expected result is non null"
                    + " lease but null has been returned.");
        }
        expirTime1 = lease1.getExpiration();

        if (expirTime1 < curTime1) {
            throw new TestException(
                    "performed write of " + sampleEntry1
                    + " with Lease.ANY lease time within the non null"
                    + " transaction, expected"
                    + " expiration time is greater then current time "
                    + curTime1 + " but returned value is " + expirTime1);
        }
        logDebugText("Write operation of " + sampleEntry1
                + " with Lease.ANY value for lease time within the"
                + " transaction works as expected.");

        // clean the space within the transaction
        cleanSpace(space, txn);

        /*
         * write an entry with Lease.FOREVER lease time
         * within the transaction
         */
        try {
            lease1 = space.write(sampleEntry1, txn, Lease.FOREVER);
        } catch (IllegalArgumentException iae) {
            throw new TestException(
                    "IllegalArgumentException was thrown while trying to"
                    + " write " + sampleEntry1
                    + " within the non null transaction with Lease.FOREVER"
                    + " value for lease time.");
        }
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();

        /*
         * check that returned lease is not equal to null,
         * expiration time is not less then current time
         */
        if (lease1 == null) {
            throw new TestException(
                    "performed write with Lease.FOREVER lease time within"
                    + " the non null transaction, expected result is non"
                    + " null lease but null has been returned.");
        }
        expirTime1 = lease1.getExpiration();

        if (expirTime1 < curTime1) {
            throw new TestException(
                    "performed write of " + sampleEntry1
                    + " with Lease.FOREVER lease time within the non null"
                    + " transaction, expected"
                    + " expiration time is greater then current time "
                    + curTime1 + " but returned value is " + expirTime1);
        }
        logDebugText("Write operation of " + sampleEntry1
                + " with Lease.FOREVER value for lease time within the non"
                + " null transaction works as expected.");

        // clean the space
        cleanSpace(space, txn);

        /*
         * write two sample entries with different
         * finite lease times into the space within the transaction.
         */
        lease1 = space.write(sampleEntry1, txn, leaseTime1);
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();
        expirTime1 = lease1.getExpiration();
        lease2 = space.write(sampleEntry2, txn, leaseTime2);
  lease2 = prepareLease(lease2);
        curTime2 = System.currentTimeMillis();
        expirTime2 = lease2.getExpiration();

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed write of " + sampleEntry1 + " with "
                    + leaseTime1 + " lease time within the non null"
                    + " transaction returned null lease.");
        }

        if (lease2 == null) {
            throw new TestException(
                    "performed write of " + sampleEntry2 + " with "
                    + leaseTime2 + " lease time within the non null"
                    + " transaction returned null lease.");
        }

        // check that write operations return required expiration times
        if (((expirTime1 - curTime1) > leaseTime1)
                || (expirTime1 - curTime1) < (leaseTime1 - instantTime)) {
            throw new TestException(
                    "performed write of " + sampleEntry1 + " with "
                    + leaseTime1 + " lease time within the non null "
                    + "transaction. Expected conditions are not satisfied: "
                    + leaseTime1 + "(specified lease time) <= ("
                    + expirTime1 + "(returned expiration time) - "
                    + curTime1 + "(current time)) >= (" + leaseTime1
                    + "(specified lease time) + " + instantTime + ").");
        }

        if (((expirTime2 - curTime2) > leaseTime2)
                || (expirTime2 - curTime2) < (leaseTime2 - instantTime)) {
            throw new TestException(
                    "performed write of " + sampleEntry2 + " with "
                    + leaseTime2 + " lease time within the non null "
                    + "transaction. Expected conditions are not satisfied: "
                    + leaseTime2 + "(specified lease time) <= ("
                    + expirTime2 + "(returned expiration time) - "
                    + curTime2 + "(current time)) >= (" + leaseTime2
                    + "(specified lease time) + " + instantTime + ").");
        }
        logDebugText("Write operations within the non null tranasction of "
                + sampleEntry1 + " with " + leaseTime1 + " lease time and\n"
                + sampleEntry2 + " with " + leaseTime2
                + " lease time work as expected.");

        /*
         * write 1-st sample entry with another finite lease time
         * to the space within the transaction again
         */
        lease1 = space.write(sampleEntry1, txn, leaseTime3);
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();
        expirTime1 = lease1.getExpiration();

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed 2-nd write of " + sampleEntry1 + " with "
                    + leaseTime3 + " lease time within the non null"
                    + " tranasaction returned null result.");
        }

        // check that write operations return required expiration times
        if (((expirTime1 - curTime1) > leaseTime3)
                || (expirTime1 - curTime1) < (leaseTime3 - instantTime)) {
            throw new TestException(
                    "performed 2-nd write of " + sampleEntry1 + " with "
                    + leaseTime3 + " lease time within the non null "
                    + "transaction. Expected conditions are not satisfied: "
                    + leaseTime3 + "(specified lease time) <= ("
                    + expirTime1 + "(returned expiration time) - "
                    + curTime1 + "(current time)) >= (" + leaseTime3
                    + "(specified lease time) + " + instantTime + ").");
        }
        logDebugText("2-nd write operation of " + sampleEntry1 + " with "
                + leaseTime3 + " lease time within the non null transaction"
                + " works as expected.");

        /*
         * write 2-nd sample entry with Lease.ANY value for lease time
         * to the space within the transaction again
         */
        lease2 = space.write(sampleEntry2, txn, Lease.ANY);
  lease2 = prepareLease(lease2);
        curTime2 = System.currentTimeMillis();
        expirTime2 = lease2.getExpiration();

        // check that returned leases are not equal to null
        if (lease2 == null) {
            throw new TestException(
                    "performed 2-nd write of " + sampleEntry2
View Full Code Here

  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();
  if (! isSameSet) {
View Full Code Here

        "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
     the test lease was originally created and its original
     expiration time.
      T0---------------T1----------T2-------------T3
       \lease          \renewal    \original      \current
        creation        time        expriation     expiration
       
      Calculate T1 (T3-renewalGrant) and show that T0 < T1 < T2 */
  long renewalTime = managedLease.getExpiration() - renewGrant;
  boolean inRange = renewalTime > leaseCreation &&
        renewalTime < originalExpTime;
  if (inRange == false) {
      String message = "Lease expiration does not reflect the\n" +
           "latest successful renewal.";
View Full Code Here

  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
  Long[] arrivalTimes = rrl.getArrivalTimes();
  RemoteEvent[] events = rrl.getEvents();
  if (events.length != 1 || arrivalTimes.length != 1) {
      String message = "Listener received " + events.length +
    " events but is required to receive exactly 1.";
      throw new TestException(message);
  }

  /* Assert that
     1) the expiration time of the lease whose renewal
        attempt failed, has an expiration time greater than
        the original expiration time.
     2) and greater than the arrival time of the renewal
        failure event
     3) and less than the expiration time that would have been
        granted had the renewal succeeded. */
  RenewalFailureEvent rfe = (RenewalFailureEvent) events[0];
  Lease managedLease = rfe.getLease();
  long currentExpiration = managedLease.getExpiration();
  long arrTime = arrivalTimes[0].longValue();
  boolean assert01 = currentExpiration > initialExpiration;
  boolean assert02 = currentExpiration > arrTime;
  boolean assert03 = currentExpiration < (arrTime + renewGrant);
  boolean correctExpiration = assert01 && assert02 && assert03;
View Full Code Here

                   null);
  evReg = prepareRegistration(evReg);
 
  /* ASSERTION #1
     The set lease and the registration lease are the same. */
  Lease lease01 = prepareLease(renewalSet[0].getRenewalSetLease());
  Lease lease02 = evReg.getLease();
  if (lease01.equals(lease02) == false) {
      String message = "The renewal set lease and the warning " +
           "event registration lease are not the same.";
      throw new TestException(message);
  }

  // register for RenewalFailureEvents
  evReg = renewalSet[0].setRenewalFailureListener(listener[0], null);
  evReg = prepareRegistration(evReg);
 
  /* ASSERTION #1 cont'd
     The set lease and the registration lease are the same. */
  Lease lease03 = evReg.getLease();
  if (lease01.equals(lease03) == false) {
      String message = "The renewal set lease and the failure" +
    "event registration lease are not the same.";
      throw new TestException(message);
  }
View Full Code Here

  }
  try {
      ProxyPreparer p = (ProxyPreparer) c.getEntry("test",
               "fiddlerLeasePreparer",
               ProxyPreparer.class);
      Lease l = reg.getLease();
      logger.log(Level.FINEST, "Returning prepared fiddler lease");
      return (Lease) p.prepareProxy(l);
  } catch (ConfigurationException e) {
      throw new RemoteException("Configuration Error", e);
  }
View Full Code Here

  // capture the two event whose sequence numbers overlap
  RenewalFailureEvent evt01 = (RenewalFailureEvent) evtArr01[evtIndex01];
  RenewalFailureEvent evt02 = (RenewalFailureEvent) evtArr02[evtIndex02];
 
  // they are the same if the leases that failed are the same
  Lease lease01 = evt01.getLease();
  Lease lease02 = evt02.getLease();

  // return the truth of the matter
  return lease01.equals(lease02) == false;
    }
View Full Code Here

        Entry snapshot1;
        Entry snapshot2;
        SimpleEntry result;
        long leaseTime1 = timeout1;
        long leaseTime2 = timeout2;
        Lease lease1 = null;
        Lease lease2 = null;
        Transaction txn;

        // first check that space is empty
        if (!checkSpace(space)) {
            throw new TestException(
View Full Code Here

  /* 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);
  }     
View Full Code Here

TOP

Related Classes of net.jini.core.lease.Lease

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.