Package com.sun.jini.test.share

Examples of com.sun.jini.test.share.TestLease


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


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

  set.setRenewalFailureListener(rrl, null);

  // create a lease that will ultimately fail renewal
  logger.log(Level.FINE, "Creating lease with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
  logger.log(Level.FINE, "Adding lease to renewal set.");
  set.renewFor(lease, Long.MAX_VALUE);
 
View Full Code Here

  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.");
  logger.log(Level.FINE, "Duration == Lease.FOREVER");
  TestLease specialLease01 =
      unreadableLeaseProvider.createNewLease(leaseOwner,
               Lease.FOREVER);

  logger.log(Level.FINE, "Creating an unreadable lease 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 with membership of " +
        "Lease.FOREVER");
  set.renewFor(specialLease01, Lease.FOREVER);

  logger.log(Level.FINE, "Adding unreadable lease 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 =
    "The getLeases() method succeeded but should\n" +
    "have thrown a LeaseUnMarshalException.";
      throw new TestException(message);

  } catch (LeaseUnmarshalException ex) {

      // set failure mode
      UnreadableTestLease.setFailMode(false);

      /* assert that the getLeases has exactly the
         0 leases. */
      Lease[] goodLeases = ex.getLeases();
      if (goodLeases.length != 0) {
    String message = "The getLeases method returned " +
        goodLeases.length + " leases.\n" + "We were" +
        " expecting 0.";
        throw new TestException(message);
      }

      /* assert that the getMarshalledLeases has exactly the
         2 leases we are expecting. */
      MarshalledObject[] badLeases = ex.getMarshalledLeases();
      if (badLeases.length != 2) {
    String message = "The getLeases method returned " +
        badLeases.length + " marshalled objects.\n" +
        "We were expecting 2.";
        throw new TestException(message);
      }

      // are they the two that we expect??
      if (rstUtil.indexOfLease(specialLease01, badLeases) == -1) {
    String message = "StillMarshalled array is missing" +
        " special lease #1";
    throw new TestException(message);
      }

      if (rstUtil.indexOfLease(specialLease02, badLeases) == -1) {
    String message = "StillMarshalled array is missing" +
        " special lease #2";
    throw new TestException(message);
      }


      /* assert that the getExceptions has exactly the
         2 two we are expecting. */
      Throwable[] exception = ex.getExceptions();
      if (exception.length != 2) {
    String message = "The getExceptions method returned " +
        exception.length + " exceptions.\n" +
        "We were expecting 2.";
        throw new TestException(message);
      }

      /* the exceptions have the lease id embedded so we can
         check which exception goes with which lease */
      int[] exceptionID = new int[exception.length];
      for (int i = 0; i < exception.length; ++i) {
    String eMessage = exception[i].getMessage();
    StringTokenizer sTok =
        new StringTokenizer(eMessage, "=");
    sTok.nextToken(); // skip leading text
    String idStr = sTok.nextToken().trim();
    exceptionID[i] = Integer.parseInt(idStr);
      }

      // assert that the ids of the exceptions and leases match
      int leaseIndex =
    rstUtil.indexOfLease(specialLease01, badLeases);
      if (exceptionID[leaseIndex] != specialLease01.id()) {
    String message = "The order of the leases in the\n" +
        "bad leases array does not correspond to the\n" +
        "order of the exceptions in the exceptions array.";
    throw new TestException(message);
      }

      leaseIndex = rstUtil.indexOfLease(specialLease02, badLeases);
      if (exceptionID[leaseIndex] != specialLease02.id()) {
    String message = "The order of the leases in the\n" +
        "bad leases array does not correspond to the\n" +
        "order of the exceptions in the exceptions array.";
    throw new TestException(message);
      }
View Full Code Here

  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);

  // remove the lease
  Lease managedLease = set.remove(testLease);
  if (managedLease != null) {
View Full Code Here

  evReg = prepareRegistration(evReg);

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

  // start managing the lease for as long as we can
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  logger.log(Level.FINE, "Membership = Lease.FOREVER.");
  set.renewFor(testLease, Lease.FOREVER);
 
  // wait for the lease to expire
  rstUtil.waitForLeaseExpiration(testLease,
               "for client lease to expire.");

  /* Assert that the notification was received at approximately
     the lease expiration time */
  Long[] arrivalTimes = rrl.getArrivalTimes();

  // must at lease have received one event
  if (arrivalTimes.length == 0) {
      String message = "RenewalFailure 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? */
  long leaseExpiration = testLease.getExpiration();
  long maxAllowed = leaseExpiration + latencySlop;

  long actualArrivalTime = arrivalTimes[0].longValue();

  // event must arrive within our assumed constraints
View Full Code Here

  }     

  // create a lease that renews normally
  logger.log(Level.FINE, "Creating the lease to be managed.");
  logger.log(Level.FINE, "Duration == " + renewGrant);
  TestLease testLease =
      leaseProvider.createNewLease(leaseOwner,
           rstUtil.durToExp(renewGrant));

  // add the lease to set01
  set01.renewFor(testLease, renewGrant);
View Full Code Here

  set = prepareSet(set);
 
  // get a lease for 2 hours (that ought to suffice).
  logger.log(Level.FINE, "Creating the lease to be managed.");
  long duration = 120 * 60 * 1000;
  TestLease testLease =
      leaseProvider.createNewLease(rstUtil.durToExp(duration));

  // start managing the lease for as long as we can
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  set.renewFor(testLease, Lease.FOREVER);
View Full Code Here

  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 == " + renewGrant);
  TestLease testLease =
      leaseProvider.createNewLease(leaseOwner,
           rstUtil.durToExp(renewGrant));
  long originalExpTime = testLease.getExpiration();

  // start managing the lease
  logger.log(Level.FINE, "Adding lease with membership of " +
        "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.");
View Full Code Here

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

TOP

Related Classes of com.sun.jini.test.share.TestLease

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.