Package net.jini.core.lease

Examples of net.jini.core.lease.Lease


  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  set.renewFor(testLease, Lease.FOREVER);
 
  // remove the lease and make certain it is the same one we added
  logger.log(Level.FINE, "Removing the managed lease from the set.");
  Lease managedLease = set.remove(testLease);
  if (managedLease.equals(testLease) == false) {
      String message = "Remove failed to return the lease whose\n";
      message += "removal was requested.";
      throw new TestException(message);
  }

  // assuming a successful remove it better be gone now ...
  logger.log(Level.FINE, "Checking that removal was successful.");
  Lease duplicateLease = set.remove(testLease);
  if (duplicateLease != null) {
      String message = "Removal of the same lease was\n";
      message += "successfully performed twice.";
      throw new TestException(message);
  }
View Full Code Here


  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 + ").";
      throw new TestException(message);
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 snapshots
        snapshot1 = space.snapshot(sampleEntry1);
        snapshot2 = space.snapshot(sampleEntry2);

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

        /*
         * write an entry with Lease.ANY lease time using it's template
         * within the transaction
         */
  lease1 = space.write(snapshot1, txn, Lease.ANY);
        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 using it's snapshot"
                    + " 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 using it's snapshot"
                + " within the transaction works as expected.");

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

        /*
         * write an entry with Lease.FOREVER lease time using it's snapshot
         * within the transaction
         */
  lease1 = space.write(snapshot1, txn, Lease.FOREVER);
        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 using it's snapshot"
                    + " 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 using it's"
                + " snapshot within the non null transaction works"
                + " as expected.");

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

        /*
         * write two sample entries with different finite lease times
         * using their snapshots into the space within the transaction.
         */
        lease1 = space.write(snapshot1, txn, leaseTime1);
        curTime1 = System.currentTimeMillis();
        expirTime1 = lease1.getExpiration();
        lease2 = space.write(snapshot2, txn, leaseTime2);
        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 using it's snapshot"
                    + " within the non null transaction returned null"
                    + " lease.");
        }

        if (lease2 == null) {
            throw new TestException(
                    "performed write of " + sampleEntry2 + " with "
                    + leaseTime2 + " lease time using it's snapshot"
                    + " 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 uting it's snapshot"
                    + " 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 uting it's snapshot"
                    + " 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 using their snapshots work as expected.");

        /*
         * write 1-st sample entry with another finite lease time
         * using it's snapshot to the space within the transaction again
         */
        lease1 = space.write(snapshot1, txn, leaseTime3);
        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 using it's snapshot"
                    + " 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 using it's snapshot"
                    + " 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 using it's snapshot within the transaction again
         */
        lease2 = space.write(snapshot2, txn, Lease.ANY);
        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

        "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

      throw new TestException(message);
  }

  // get the lease and throwable objects from the event.
  RenewalFailureEvent rfe = (RenewalFailureEvent) events[0];
  Lease eventLease = rfe.getLease();
  IllegalArgumentException eventException =
      (IllegalArgumentException) rfe.getThrowable();

  /* try to recall 50 times and make certain that nothing changes
     and no exceptions are thrown */
  for(int i = 0; i < 50; ++i) {

      try {
    if (eventLease.equals(rfe.getLease()) == false) {
        String message = "The lease returned by getLeases()" +
      "has changed.";
        throw new TestException(message);
    }
      } catch (Exception ex) {
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 testLease =
      leaseProvider.createNewLease(owner,
           rstUtil.durToExp(renewGrant));

  // wait for the lease to expire
  rstUtil.waitForLeaseExpiration(testLease,
View Full Code Here

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

                                             Lease.ANY, null);
  reg = (EventRegistration)
              getConfig().prepare("test.outriggerEventRegistrationPreparer",
                                  reg);
        logger.log(Level.INFO, "Registered first event handler");
        Lease lease1 = reg.getLease();
        lease1 = (Lease)
                 getConfig().prepare("test.outriggerLeasePreparer", lease1);
        /*
         * The sequence number the first event should have, this would
         * be dicey in a real application but the QA tests assume a
         * very controled enviroment
         */
        final long ev1 = reg.getSequenceNumber() + 1;
        addOutriggerLease(lease1, true);
        addOutriggerLease(space.write(aEntry, null, Lease.ANY), false);
        logger.log(Level.INFO, "Wrote first Entry");

        /*
         * Wait for event and check to see if it is the right one and
         * that the lease was canceled
         */
        long listener1Rcvd;
        synchronized (listener1) {

            // Did it already happen?
            listener1Rcvd = listener1.lastEvent();

            if (listener1Rcvd < ev1) {

                // No, wait
                listener1.wait(wait);
                listener1Rcvd = listener1.lastEvent();

                if (listener1Rcvd < 0) {
                    throw new TestException(
                            "First listener never received event");
                } else if (ev1 < listener1Rcvd) {
                    throw new TestException(
                            "First listener received too many events");
                }
                logger.log(Level.INFO, "Received correct event");
            }
        }

        // Give the cancel a chance to happen
        Thread.sleep(10000);

        try {
            lease1.cancel();
            throw new TestException(
                    "Lease on first registion not cancled by"
                    + " Runtime exception");
        } catch (UnknownLeaseException e) {

            // Result we are looking for
        }
        logger.log(Level.INFO, "Lease on first registration is gone");

        // Register second handler and write second entry2
        EventRegistration reg2 = space.notify(aEntry, null, listener2,
                Lease.ANY, null);
  reg2 = (EventRegistration)
               getConfig().prepare("test.outriggerEventRegistrationPreparer",
                                   reg2);
        logger.log(Level.INFO, "Registered 2nd handler");
        Lease lease2 = reg2.getLease();
        lease2 = (Lease)
                 getConfig().prepare("test.outriggerLeasePreparer", lease2);
        addOutriggerLease(lease2, false);

        /*
 
View Full Code Here

     * @param entry entry object to be written
     */
    protected void writeEntry(int id, Transaction txn, Entry entry)
            throws TestException {
        try {
            Lease l = spaces[id].write(entry, txn, Lease.FOREVER);
            addOutriggerLease(l, true);
        } catch (Exception e) {
            throw new TestException("Can't write an entry with a transaction",
                    e);
        }
View Full Code Here

     * @param entry entry object to be written
     */
    protected void writeEntry(Transaction txn, Entry entry)
            throws TestException {
        try {
            Lease l = space.write(entry, txn, Lease.FOREVER);
            addOutriggerLease(l, true);
        } catch (Exception e) {
            throw new TestException("Can't write an entry with a transaction",
                    e);
        }
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.