Examples of TestLease


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

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

  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

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

  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

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

  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

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

  // create a 2 leases that will fail on renewal
  long renewGrant = renewSetDur * 5 / 10;
  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));
 
  // add lease01 to set01 and lease02 to set02
  logger.log(Level.FINE, "Adding lease #1 to set #1");
  set01.renewFor(lease01, Long.MAX_VALUE);
  logger.log(Level.FINE, "Adding lease #2 to set #2");
  set02.renewFor(lease02, Long.MAX_VALUE);
 
  /* wait for the expiration warning events to arrive.
     By the time they do, all RenewalFailureEvents should also
     have arrived. */
  rstUtil.waitForRemoteEvents(normalListener01, 1, renewSetDur);
  rstUtil.waitForRemoteEvents(failingListener01, 1, renewSetDur);
 
  // Assert that we had one call each on the failing listeners
  RemoteEvent[] events01 = failingListener01.getEvents();
  RemoteEvent[] events02 = failingListener02.getEvents();

  if (events01.length != 1) {
      String message = "Failing Listener #1 received " +
    events01.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  if (events02.length != 1) {
      String message = "Failing Listener #2 received " +
    events02.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  // Assert that we had one call each on the normal listeners
  events01 = normalListener01.getEvents();
  events02 = normalListener02.getEvents();

  if (events01.length != 1) {
      String message = "Normal Listener #1 received " +
    events01.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  if (events02.length != 1) {
      String message = "Normal Listener #2 received " +
    events02.length + " events but is required to\n" +
    "receive exactly 1.";
      throw new TestException(message);
  }

  // Assert we can renew both set's leases without error
  renewSetDur = renewSetDur * 6 / 10; // use a shorter time

  try {
      logger.log(Level.FINE, "Renewing set #1's lease with duration " +
            "of " + renewSetDur + " milliseconds.");
      prepareLease(set01.getRenewalSetLease()).renew(renewSetDur);
  } catch (UnknownLeaseException ex) {
      String message = "Attempt to renew lease for renewal set\n" +
    "#1 has failed due to " + ex;
      throw new TestException(message, ex);
  }     

  try {
      logger.log(Level.FINE, "Renewing set #2's lease with duration " +
            "of " + renewSetDur + " milliseconds.");
      prepareLease(set02.getRenewalSetLease()).renew(renewSetDur);
  } catch (UnknownLeaseException ex) {
      String message = "Attempt to renew lease for renewal set\n" +
    "#2 has failed due to " + ex;
      throw new TestException(message, ex);
  }     

  /* 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);
  }     

  // Restore both sets to original configurations
  renewGrant = renewSetDur * 3 / 10;
  logger.log(Level.FINE, "Creating failing lease #3 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease03 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
  logger.log(Level.FINE, "Adding lease #3 to set #1");
  set01.renewFor(lease03, Long.MAX_VALUE);
 
  logger.log(Level.FINE, "Creating failing lease #4 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease04 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(renewGrant));
  logger.log(Level.FINE, "Adding lease #4 to set #2");
  set02.renewFor(lease04, Long.MAX_VALUE);
 
View Full Code Here

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

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

  // start managing the lease for as long as we can
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  set.renewFor(testLease, Long.MAX_VALUE);
 
  // wait for the event to arrive
  long timeout = renewGrant * 2;
  boolean gotEvent = rstUtil.waitForRemoteEvents(rrl, 1, timeout);
  if (gotEvent == false) {
      String message = "RenewalFailureEvent was not received\n" +
    "within the " + timeout + " millisecond window.";
      throw new TestException(message);
  }

  /* Assert that the notification was received after
     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
     was the event received after lease expiration? */
  long leaseExpiration = testLease.getExpiration();

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

  // events should not arrive before expiration
  if (actualArrivalTime < leaseExpiration) {
View Full Code Here

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

    private String testBadObjectException(FailingOpCountingOwner owner)
          throws UnknownLeaseException, InterruptedException, RemoteException {

  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 as long as we can
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
  logger.log(Level.FINE, "Membership duration = Long.MAX_VALUE");
View Full Code Here

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

        throws RemoteException, UnknownLeaseException, InterruptedException {

  // get a lease for testing indefinite exceptions
  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 as long as we can
  logger.log(Level.FINE, "Adding managed lease to lease renewal set.");
View Full Code Here

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

  set.setRenewalFailureListener(rrl  , null);

  // create two leases that will not fail on renewal
  logger.log(Level.FINE, "Creating lease #1 with duration of " +
        renewGrant + " milliseconds.");
  TestLease lease01 =
      leaseProvider.createNewLease(succeedingOwner,
           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(succeedingOwner,
           rstUtil.durToExp(renewGrant));
  set.renewFor(lease02, Long.MAX_VALUE);

  // create the lease to be managed
  long longerGrant = renewGrant * 2;
  logger.log(Level.FINE, "Creating lease #3 with duration of " +
        longerGrant + " milliseconds.");
  TestLease lease03 =
      leaseProvider.createNewLease(failingOwner,
           rstUtil.durToExp(longerGrant));
  set.renewFor(lease03, Long.MAX_VALUE);

  // wait for the failing lease to renew
View Full Code Here

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

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

  // start managing the lease forever
  logger.log(Level.FINE, "Adding lease with membership of " +
        "Lease.FOREVER");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.