Package net.jini.lease

Examples of net.jini.lease.LeaseRenewalSet


    }

    public void run() throws Exception {
  specifyServices(new Class[]{LeaseRenewalService.class});
  final LeaseRenewalService lrs = (LeaseRenewalService)services[0];
  LeaseRenewalSet     set =
      lrs.createLeaseRenewalSet(eventWaitFor);
        set = prepareSet(set);
  final Lease setLease = prepareNormLease(set.getRenewalSetLease());
  addLease(setLease, false);


  // Create and register listeners
  warningListener = new WarningListener(failureFails?null:throwThis);
  failureListener = new BaseListener(failureFails?throwThis:null);

  MarshalledObject handback = new MarshalledObject(new Long(3));
  logger.log(Level.FINER, "setting expiration warning listener");
  EventRegistration reg =
      set.setExpirationWarningListener(warningListener,
    eventWaitFor - whenWarning, handback);
  logger.log(Level.FINER, "preparing returned registration");
        reg = prepareNormEventRegistration(reg);
  logger.log(Level.FINER, "completing initialization of listener");
  warningListener.setRegInfo(reg, handback);

  handback = null;
  reg = set.setRenewalFailureListener(failureListener, handback);
  reg = prepareNormEventRegistration(reg);
  failureListener.setRegInfo(reg, handback);

  // Create and add lease that will cause failure
  long now = System.currentTimeMillis();
  Lease l = LocalLease.getFailingLocalLease(now + whenFailure, 0, leaseID, 1, 0);
  set.renewFor(l, Lease.FOREVER);

  // Sleep
  logger.log(Level.INFO, "Sleeping for " + eventWaitFor  + " ms");
  Thread.sleep(eventWaitFor);
  logger.log(Level.INFO, "Awake");

  // Check to see if we have failed yet
  checkListener(warningListener, "Warning", true);
  checkListener(failureListener, "Failure", true);

  if (tryShutdown)
      shutdown(0);

  // Generate 2nd set of events

  // Create and add lease that will cause failure
  setLease.renew(eventWaitFor);
  now = System.currentTimeMillis();
  l = LocalLease.getFailingLocalLease(now + whenFailure, 0, leaseID, 1, 0);
  set.renewFor(l, Lease.FOREVER);

  // Sleep
  logger.log(Level.INFO, "Sleeping for " + eventWaitFor  + " ms");
  Thread.sleep(eventWaitFor);
  logger.log(Level.INFO, "Awake");
View Full Code Here


    }

    public void run() throws Exception {
  specifyServices(new Class[]{LeaseRenewalService.class});
  LeaseRenewalService lrs = (LeaseRenewalService)services[0];
  LeaseRenewalSet set =
      lrs.createLeaseRenewalSet((renewCount * renewGrant + slop) * 2);
  set = prepareSet(set);
  addLease(prepareNormLease(set.getRenewalSetLease()), false);

  final long now = System.currentTimeMillis();

  final LeaseBackEndImpl home = new LeaseBackEndImpl(1);
  final long initExp = now + renewGrant;
  final RenewingOwner owner = new RenewingOwner(initExp, renewCount,
                renewGrant,
                now + membershipDuration,
                slop);
  final Lease lease = home.newLease(owner, initExp);
  logger.log(Level.FINER, "calling renewFor with duration " + (now + membershipDuration) + " at " + System.currentTimeMillis());
  set.renewFor(lease, membershipDuration);
  logger.log(Level.FINER, "call to renewFor complete at " + System.currentTimeMillis());

  if (tryShutdown)
      shutdown(0);

  final String rslt =
      owner.waitForRenewals(renewCount * renewGrant + slop);

  if (rslt != null)
      throw new TestException(rslt);
  // Try to remove the lease
  final Lease rl = set.remove(lease);
  final long removeTime = System.currentTimeMillis();

  if (rl == null)
      throw new TestException("Could not remove lease");
  else if (!rl.equals(lease))
      throw new TestException("Removed lease (" + rl + ") was not equals() to lease we " +
         "added (" + lease + ")");

  final Lease rl2 = set.remove(lease);

  if (rl2 != null)
      throw new TestException("Lease still in set after removal");

  if (tryShutdown) {
      shutdown(0);

      // Try to remove the lease again
      final Lease rl3 = set.remove(lease);

      if (rl3 != null)
    throw new TestException("Lease still in set after removal and shutdown");
  }

View Full Code Here

  // The lease who's membership expiration we will let expire
  final Lease toExpire = LocalLease.getLocalLease(
            (4 * membershipDuration) + now, 60 * 1000, 3, 3);
  leases.add(toExpire);

  LeaseRenewalSet set =
      lrs.createLeaseRenewalSet(4 * membershipDuration);
  set = prepareSet(set);
  addLease(prepareNormLease(set.getRenewalSetLease()), false);

  logger.log(Level.INFO, "Adding leases to renewal set");

  for (final Iterator i=leases.iterator(); i.hasNext(); ) {
      final Lease toAdd = (Lease)i.next();
      if (toAdd.equals(toExpire)) {
    set.renewFor(toAdd, membershipDuration);
      } else {
    set.renewFor(toAdd, Lease.FOREVER);
      }
  }

  final long start = System.currentTimeMillis();

  if (tryShutdown) {
            logger.log(Level.INFO, "Shuting down at: " + start + " milliseconds");
      shutdown(0);
        }

  logger.log(Level.INFO, "Calling getLeases(), looking for all 4 leases");
  check(Arrays.asList(set.getLeases()),
        "Set is missing or holding leases it should not");

  logger.log(Level.INFO, "Removing 1 lease from the set");
  final Lease removed = set.remove(toRemove);
  if (removed == null || !removed.equals(toRemove)) {
      throw new TestException("Could not remove lease");
        }
  leases.remove(toRemove);

  if (tryShutdown) {
            logger.log(Level.INFO, "Shuting down at: "
                + System.currentTimeMillis() + " milliseconds");
      shutdown(0);
        }

  logger.log(Level.INFO, "Calling getLeases(), looking for 3 leases");
  check(Arrays.asList(set.getLeases()),"Set is missing or "
            + "holding leases it should not after removing one");

  // Wait for expiration to be reached on toExpire
  final long sleepTime =
      (membershipDuration - (System.currentTimeMillis() - start))
            + 10000;
  if (sleepTime > 0) {
      logger.log(Level.INFO, "Sleeping for: " + sleepTime + " milliseconds");
      Thread.sleep(sleepTime);
  }
  leases.remove(toExpire);

  if (tryShutdown) {
            logger.log(Level.INFO, "Shuting down at: "
                + System.currentTimeMillis() + " milliseconds");
      shutdown(0);
        }

  logger.log(Level.INFO, "Calling getLeases(), looking for 2 leases");
  check(Arrays.asList(set.getLeases()),
      "Set is missing or holding leases it should not after expire");
    }
View Full Code Here

    }

    public void run() throws Exception {
  specifyServices(new Class[]{LeaseRenewalService.class});
  LeaseRenewalService lrs = (LeaseRenewalService)services[0];
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
        set = prepareSet(set);
  addLease(prepareNormLease(set.getRenewalSetLease()), false);

  long now = System.currentTimeMillis();

  // Add a local lease to get things primed
  set.renewFor(LocalLease.getLocalLease(now + 600000, 600000, 1, 1), Lease.FOREVER);

  // Create the object that will serve as the landlord
  final RenewAtOwner owners[] = new RenewAtOwner[8];
  final LeaseBackEndImpl home = new LeaseBackEndImpl(owners.length);
  int j = 0;

  // Desired exp before end of test, desired renewal < max grant
  owners[j++] = createOwner(6000060000300000,        30000);

  // Desired exp FOREVER, desired renewal = ANY
  owners[j++] = createOwner(3000045000,  Lease.FOREVER, Lease.ANY);

  // Desired exp FOREVER, desired renewal > max grant
  owners[j++] = createOwner(4500045000,  Lease.FOREVER, 60000);

  // Desired exp FOREVER, desired renewal < max grant
  owners[j++] = createOwner(45000600000, Lease.FOREVER, 75000);

  // Desired exp < current exp
  owners[j++] = createOwner(400000, 45000350000,        60000);

  // Desired exp after end of test, desired renewal < max grant
  owners[j++] = createOwner(3000060000600000,        45000);

  // Desired exp after end of test, desired renewal > max grant
  owners[j++] = createOwner(3000030000650000,        45000);

  // Desired exp before end of test, desired renewal > max grant
  owners[j++] = createOwner(6000030000250000,        60000);

  for (int i=0; i<owners.length; i++) {
      final RenewAtOwner owner = (RenewAtOwner)owners[i];

      final Lease lease = home.newLease(owner, owner.getExpiration());
      set.renewFor(lease, owner.getDesiredDuration(),
       owner.getDesiredRenewal());
  }

  if (tryShutdown)
      shutdown(0);
View Full Code Here


    public void run() throws Exception {
  specifyServices(new Class[]{LeaseRenewalService.class});
  LeaseRenewalService lrs = (LeaseRenewalService)services[0];
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  addLease(prepareNormLease(set.getRenewalSetLease()), false);

  // Add a local lease to get things primed
  long now = System.currentTimeMillis();
  set.renewFor(LocalLease.getLocalLease(now + 600000, 600000, 1, now),
         Lease.FOREVER);

  for (int i=0; i<homes.length; i++) {
      homes[i] = createBackEnd(set);
  }
View Full Code Here

    }

    public void run() throws Exception {
  specifyServices(new Class[]{LeaseRenewalService.class});
  LeaseRenewalService lrs = (LeaseRenewalService)services[0];
  LeaseRenewalSet     set = lrs.createLeaseRenewalSet(Lease.FOREVER);
        set = prepareSet(set);
  addLease(prepareNormLease(set.getRenewalSetLease()), false);

  // Register for failure events
  final OurListener listener = new OurListener();
  final MarshalledObject handback = new MarshalledObject(new Long(347));
  EventRegistration reg =
      set.setRenewalFailureListener(listener, handback);
  reg = prepareNormEventRegistration(reg);

  if (!set.equals(reg.getSource()))
      throw new TestException("Source object in event registration is not set");

  if (reg.getID() != LeaseRenewalSet.RENEWAL_FAILURE_EVENT_ID)
      throw new TestException("Event ID in registration is not correct");

  if (!reg.getLease().equals(prepareNormLease(set.getRenewalSetLease())))
      throw new TestException("Lease in registration is not correct");

  listener.setRegInfo(reg, handback);

  if (tryShutdown) {
      shutdown(0);
      Thread.sleep(10000);
        }

  // Create owners, leases, and registrations.
  logger.log(Level.INFO, "Creating leases and adding them to set");

  home = new LeaseBackEndImpl(17);
  createAndRegisterLease(
      new RemoteException("Synthetic RemoteException"), false, set);
  createAndRegisterLease(
      new NoSuchObjectException("Synthetic NoSuchObjectException"), true,
      set);
  createAndRegisterLease(
      new RuntimeException("Synthetic RuntimeException"), true, set);
  createAndRegisterLease(
      new Error("Synthetic Error"), true, set);
  createAndRegisterLease(
      new UnknownLeaseException("Synthetic UnknownLeaseException"), true,
      set);
  createAndRegisterLease(
      new LeaseDeniedException("Synthetic LeaseDeniedException"), true,
      set);
  createAndRegisterLease(
      new OutOfMemoryError("Synthetic OutOfMemoryError"),
      false, set);
  createAndRegisterLease(
      new LinkageError("Synthetic LinkageError"),
      false, set);
  createAndRegisterLease(
      new MarshalException("Synthetic MarshalException",
          new InvalidClassException("Synthetic")),
          true, set);
  createAndRegisterLease(
      new MarshalException("Synthetic MarshalException", null),
         false, set);
  createAndRegisterLease(
      new MarshalException("Synthetic MarshalException",
         new IOException()),
         false, set);
  createAndRegisterLease(
      new UnmarshalException("Synthetic UnmarshalException",
           new InvalidClassException("Synthetic")),
           true, set);
  createAndRegisterLease(
      new UnmarshalException("Synthetic UnmarshalException", null),
           false, set);
  createAndRegisterLease(
      new UnmarshalException("Synthetic UnmarshalException",
           new IOException()),
           false, set);
  createAndRegisterLease(
      new ServerException("Synthetic ServerException",
        new RemoteException()),
        false, set);
  createAndRegisterLease(
      new ServerException("Synthetic ServerException",
        new NoSuchObjectException("Synthetic")),
        true, set);
  createAndRegisterLease(
      new ServerException("Synthetic ServerException",
        new UnmarshalException("Synthetic UnmarshalException",
                   new InvalidClassException("Synthetic"))),
        true, set);


  // Wait for failures to hapen and events to be recieved
  final long sleepTime =
      (renewalsUntilFailure + 1) * renewGrant + // Time until errors
      renewGrant * 2// Allow for propagation and make sure
           // renews don't happen after failed renewals
  logger.log(Level.INFO, "Sleeping for " + sleepTime + "ms");
  Thread.sleep(sleepTime);

  // Try to remove all the lease (should get null back each time)
  Lease leases[] = home.getLeases();
  for (int i=0; i<leases.length; i++) {
      final Lease lease = leases[i];
      final Lease rtnLease = set.remove(lease);
      if (rtnLease != null)
    throw new TestException(rtnLease + " was not removed");
  }

  if (tryShutdown) {
      shutdown(0);
      Thread.sleep(10000);

      // Check removal again
      for (int i=0; i<leases.length; i++) {
    final Lease lease = leases[i];
    final Lease rtnLease = set.remove(lease);
    if (rtnLease != null)
        throw new TestException(rtnLease + " was not removed");
      }
  }

View Full Code Here

    // inherit javadoc from parent class
    public synchronized void notify(RemoteEvent theEvent)
           throws UnknownEventException, RemoteException {
  super.notify(theEvent);
  if (theEvent.getClass() == ExpirationWarningEvent.class) {
      LeaseRenewalSet set = (LeaseRenewalSet) theEvent.getSource();
      Lease lease = null;
      try {
    set = (LeaseRenewalSet)
          QAConfig.getConfig().prepare("test.normRenewalSetPreparer",
              set);
    lease = set.getRenewalSetLease();
    lease =  (Lease)
       QAConfig.getConfig().prepare("test.normLeasePreparer",
                 lease);
      } catch (TestException e) {
    renewalException = e;
View Full Code Here

    }

    public void run() throws Exception {
  specifyServices(new Class[]{LeaseRenewalService.class});
  final LeaseRenewalService lrs = (LeaseRenewalService)services[0];
  LeaseRenewalSet set = lrs.createLeaseRenewalSet(setLeaseLength);
  set = prepareSet(set);
  final Lease setLease = prepareNormLease(set.getRenewalSetLease());
  setLeaseCurrentExpiration = setLease.getExpiration();
  addLease(setLease, true);

  listener = new OurListener(setLease, setRenewals);

  // If we need to register for warning events
  if (shouldRegister) {     
      logger.log(Level.INFO, "Registering for warning events");

      final MarshalledObject handback =
    new MarshalledObject(new Long(348));
      EventRegistration reg = set.setExpirationWarningListener(
                listener, minWarning, handback);
            reg = prepareNormEventRegistration(reg);

      if (!set.equals(reg.getSource())) {
    throw new TestException(
                    "Source object in event registration is not set");
            }
      if (reg.getID() != LeaseRenewalSet.EXPIRATION_WARNING_EVENT_ID){
    throw new TestException(
                    "Event ID in registration is not correct");
            }
      if (!reg.getLease().equals(
                prepareNormLease(set.getRenewalSetLease())))
            {
    throw new TestException(
                    "Lease in registration is not correct");
            }
      listener.setRegInfo(reg, handback);
  }

  // Create owners and leases
  final LeaseBackEndImpl home = new LeaseBackEndImpl(leaseCount);
  for (int i = 0; i < leaseCount; i++) {
      final long now = System.currentTimeMillis();
      final long initExp = now + renewGrant;
      final OurOwner owner = new OurOwner(initExp);
      final Lease l = home.newLease(owner, initExp);
      set.renewFor(l, Lease.FOREVER, Lease.ANY);
  }

        if (tryShutdown) {
            logger.log(Level.INFO, "Shuting down at: "
                + System.currentTimeMillis() + " milliseconds");
View Full Code Here

    }

    public void run() throws Exception {
  specifyServices(new Class[]{LeaseRenewalService.class});
  LeaseRenewalService lrs = (LeaseRenewalService)services[0];
  LeaseRenewalSet     set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  addLease(prepareNormLease(set.getRenewalSetLease()), false);

  // Register for failure events
  final OurListener listener = new OurListener();
  final MarshalledObject handback = new MarshalledObject(new Long(347));
  EventRegistration reg =
      set.setRenewalFailureListener(listener, handback);
  reg = prepareNormEventRegistration(reg);

  if (!set.equals(reg.getSource()))
      throw new TestException( "Source object in event registration is not set");

  if (reg.getID() != LeaseRenewalSet.RENEWAL_FAILURE_EVENT_ID)
      throw new TestException( "Event ID in registration is not correct");

  if (!reg.getLease().equals(prepareNormLease(set.getRenewalSetLease())))
      throw new TestException( "Lease in registration is not correct");

  listener.setRegInfo(reg, handback);

  final Lease first = LocalLease.getLocalLease(0, 60000, 1, 1);
  listener.setExpectedLease(first);
  set.renewFor(first, Lease.FOREVER);

  logger.log(Level.INFO, "Sleeping for " + eventWait + " ms");
  Thread.sleep(eventWait);

  String listenerRslt = listener.didPass();
  if (listenerRslt != null) {
      throw new TestException( listenerRslt);
  }           

  if (!listener.didReceiveExpected())
      throw new TestException( "Did not receive an appropriate event");

  if (!tryShutdown)
      return;

  logger.log(Level.INFO, "First half of test passed, ");

  Admin admin = manager.getAdmin(lrs);
  if (admin instanceof ActivatableServiceStarterAdmin) {
      logger.log(Level.INFO, "trying second half");
      final Lease second = LocalLease.getDestructingLocalLease(Lease.FOREVER,
                 60000, 1, 1, 2);
      listener.setExpectedLease(second);
      set.renewFor(second, Lease.FOREVER);

      if (listener.didReceiveExpected()) {
    throw new TestException(
             "Got 2nd event before "
           + "we killed the server");  
View Full Code Here

    public void run() throws Exception {
  // Announce where we are in the test
  logger.log(Level.FINE, "OneExpireOneNotTest: In run() method.");

  long setCreation = System.currentTimeMillis();
  LeaseRenewalSet setExpire = lrs.createLeaseRenewalSet(setDuration);
  setExpire = prepareSet(setExpire);
  logger.log(Level.FINE, "OneExpireOneNotTest: Expire set created");
  LeaseRenewalSet setKeep = lrs.createLeaseRenewalSet(Lease.FOREVER);
  setKeep = prepareSet(setKeep);
  Lease expsLease = setExpire.getRenewalSetLease();
        expsLease = (Lease) getConfig().prepare(
            "test.normLeasePreparer", expsLease);

  final LeaseBackEndImpl backend = new LeaseBackEndImpl(leaseCount);

  for (int i=0; i<leaseCount; i+=2) {
      long initExpiration = System.currentTimeMillis() + renewGrant;
      LeaseOwner o = new ForeverOwner(initExpiration, renewGrant,
          latencySlop, Lease.FOREVER, this, true, getConfig());
      Lease l = backend.newLease(o, initExpiration);
      setKeep.renewFor(l, Lease.FOREVER);

      initExpiration = System.currentTimeMillis() + renewGrant;
      o = new ExpiryOwner(initExpiration, renewGrant,
          latencySlop, Lease.FOREVER, this, true, getConfig(), expsLease);
      l = backend.newLease(o, initExpiration);
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.