Package com.sun.jini.qa.harness

Examples of com.sun.jini.qa.harness.TestException


        try {
            while (!checkSpace(space, txn)) {
                space.takeIfExists(null, txn, JavaSpace.NO_WAIT);
            }
        } catch (Exception ex) {
            throw new TestException("Exception has been caught while"
                    + " cleaning the space: " + ex.getMessage());
        }
    }
View Full Code Here


            String txnMgrName = getConfig().getStringConfigVal(pkgName + ".txnManager",
                    TransactionManager.class.getName());
            printTxnMgrInfo(txnMgrName);
            mgr = (TransactionManager) manager.startService(txnMgrName); //prepared
        } catch (Exception e) {
            throw new TestException("Exception has been caught while"
                    + "trying to start Transaction Manager.", e);
        }

        if (mgr == null) {
            throw new TestException("Null Transaction Manager"
                    + " has been obtained.");
        }
        return mgr;
    }
View Full Code Here

        try {
            trc = TransactionFactory.create(mgr, lTime);

            if (trc == null) {
                throw new TestException("Null transaction"
                        + " has been obtained.");
            }
            txns.add(trc.transaction);
            return trc.transaction;
        } catch (Exception e) {
            throw new TestException("Could not create transaction.", e);
        }
    }
View Full Code Here

            if (txn != null) {
                txn.commit();
                txns.remove(txns.indexOf(txn));
            }
        } catch (Exception e) {
            throw new TestException(
                    "Exception has been caught while transaction committing:",
                    e);
        }
    }
View Full Code Here

  // remove the lease
  Lease managedLease = set.remove(testLease);
  if (managedLease != null) {
      String message = "Removal of non-managed lease does NOT\n" +
           "return null as required.";
      throw new TestException(message);
  }
    }
View Full Code Here

            if (txn != null) {
                txn.abort();
                txns.remove(txns.indexOf(txn));
            }
        } catch (Exception e) {
            throw new TestException(
                    "Exception has been caught while transaction aborting:", e);
        }
    }
View Full Code Here

        SimpleEntry result;
        Transaction txn1, txn2;

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

        // write sample entry to the space
        space.write(sampleEntry, null, leaseForeverTime);

        // create two non null transactions
        txn1 = getTransaction();
        txn2 = getTransaction();

        // take written entry from the space within 1-st transaction
        space.take(sampleEntry, txn1, checkTime);

        // check that we can not read the entry outside both transactions
        result = (SimpleEntry) space.read(sampleEntry, null, checkTime);

        if (result != null) {
            throw new TestException(
                    "performed read with template " + sampleEntry
                    + " outside both transactions while taking it within"
                    + " 1-st one, expected null but read " + result);
        }
        logDebugText("Entry can't be read outside both transactions.");

        // check that we can not read the entry within another transaction
        result = (SimpleEntry) space.read(sampleEntry, txn2, checkTime);

        if (result != null) {
            throw new TestException(
                    "performed read with template " + sampleEntry
                    + " within 2-nd transaction while taking it"
                    + " within 1-st one, expected null but read " + result);
        }
        logDebugText("Entry can't be read in 2-nd transaction.");

        // check that we can not take the entry outside both transactions
        result = (SimpleEntry) space.take(sampleEntry, null, checkTime);

        if (result != null) {
            throw new TestException(
                    "performed take with template " + sampleEntry
                    + " outside both transactions while taking it"
                    + " within 1-st one, expected null but took " + result);
        }
        logDebugText("Entry can't be taken outside both transactions.");

        // check that we can not take the entry within another transaction
        result = (SimpleEntry) space.take(sampleEntry, txn2, checkTime);

        if (result != null) {
            throw new TestException(
                    "performed take with template " + sampleEntry
                    + " within 2-nd transaction while taking it"
                    + " within 1-st one, expected null but took " + result);
        }
        logDebugText("Entry can't be taken in 2-nd transaction.");
View Full Code Here

        SimpleEntry result;
        Transaction txn;

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

        // init original entries for comparing
        origEntry1 = (SimpleEntry) sampleEntry1.clone();
        origEntry2 = (SimpleEntry) sampleEntry2.clone();

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

        /*
         * write 1-st entry with Lease.ANY value for lease time
         * within the non null transaction
         */
        try {
            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 non null transaction.");
        }

        // check that original entry has not been changed
        if (!origEntry1.equals(sampleEntry1)) {
            throw new TestException(
                    "performed write operation with Lease.ANY value"
                    + " for lease time within the non null transaction"
                    + " has changed entry object: original entry "
                    + origEntry1 + " has been changed by " + sampleEntry1);
        }

        /*
         * check that written entry is available
         * in the space within the transaction
         */
        result = (SimpleEntry) space.read(sampleEntry1, txn, checkTime);

        if (result == null) {
            throw new TestException(
                    "performed write of " + sampleEntry1
                    + " with Lease.ANY value for lease time"
                    + " within the non null transaction, written entry"
                    + " is not available in the space.");
        }
        logDebugText("Write of " + sampleEntry1
                + " with Lease.ANY lease time within the non null"
                + " transaction works as expected.");

        /*
         * write 2-nd entry with Lease.ANY value for lease time
         * within the non null transaction
         */
        try {
            space.write(sampleEntry2, txn, Lease.ANY);
        } catch (IllegalArgumentException iae) {
            throw new TestException(
                    "IllegalArgumentException was thrown while trying to"
                    + " write " + sampleEntry2
                    + " with Lease.ANY value for lease time"
                    + " within the non null transaction.");
        }

        // check that original entry has not been changed
        if (!origEntry2.equals(sampleEntry2)) {
            throw new TestException(
                    "performed write operation with Lease.ANY value"
                    + " for lease time within the non null transaction"
                    + " has changed entry object: original entry "
                    + origEntry2 + " has been changed by " + sampleEntry2);
        }

        /*
         * check that written entry is available
         * in the space within the transaction
         */
        result = (SimpleEntry) space.read(sampleEntry2, txn, checkTime);

        if (result == null) {
            throw new TestException(
                    "performed write of " + sampleEntry2
                    + " with Lease.ANY value for lease time"
                    + " within the non null transaction, written entry"
                    + " is not available in the space.");
        }
        logDebugText("Write of " + sampleEntry2
                + " with Lease.ANY lease time within the non null"
                + " transaction works as expected.");

        /*
         * write 1-st entry with Lease.ANY value for lease time again
         * within the same non null transaction
         */
        try {
            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 non null transaction again.");
        }

        // check that original entry has not been changed
        if (!origEntry1.equals(sampleEntry1)) {
            throw new TestException(
                    "performed 2-nd write operation for the same entry"
                    + " with Lease.ANY value for lease time"
                    + " within the non null transaction has changed"
                    + " entry object: original entry " + origEntry1
                    + " has been changed by " + sampleEntry1);
        }

        // check that written entries are available in the space
        result = (SimpleEntry) space.take(sampleEntry1, txn, checkTime);

        if (result == null) {
            throw new TestException(
                    "performed 2-nd write operation for the same "
                    + sampleEntry1 + " with Lease.ANY value for lease time"
                    + " within the non null transaction, 1-st written"
                    + " entry is not available in the space.");
        }
        result = (SimpleEntry) space.take(sampleEntry1, txn, checkTime);

        if (result == null) {
            throw new TestException(
                    "performed 2-nd write operation for the same "
                    + sampleEntry1 + " with Lease.ANY value for lease time"
                    + " within the non null transaction, 2-nd written"
                    + " entry is not available in the space.");
        }
View Full Code Here

  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
  if (actualArrivalTime < maxAllowed) {
      // we say event was received around the right time
      logger.log(Level.FINE, "Assertion #1 passes!");
  } else {
      /* There was a lag. This could be a network problem or an
         overloaded cpu but we will just have to assume that the
         specification was not met. */
      String message = "Assertion #1 failed ...\n" +
    "Event was not received within " + latencySlop +
    " milliseconds of client lease expiration.";
      throw new TestException(message);
  }

  /* TESTING ASSERTION #2
     the handback object is the one we expect. */
  RemoteEvent[] events = rrl.getEvents();
  MarshalledObject mObj = events[0].getRegistrationObject();
  if (handback.equals(mObj) == false) {
      String message = "Assertion #2 failed ...\n" +
    "Handback object does not match original.";
      throw new TestException(message);
  }
  logger.log(Level.FINE, "Assertion #2 passes!");
 
  /* TESTING ASSERTION #3
     The lease for the event registration is the same as the event's
     lease */
  if (rstUtil.isValidRenewFailEventReg(evReg, set) == false) {
      String message = "Assertion #3 failed ...\n" +
    "Event Registration is invalid." +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }
  logger.log(Level.FINE, "Assertion #3 passes!");

  /* TESTING ASSERTION #4
     a null listener results in a NullPointException. */
  set = lrs.createLeaseRenewalSet(Lease.FOREVER);
  set = prepareSet(set);
  logger.log(Level.FINE, "Created Set with lease duration of " +
        "Lease.FOREVER.");
  try {
      evReg = set.setRenewalFailureListener(null, handback);
      evReg = prepareRegistration(evReg);
      if (rstUtil.isValidExpWarnEventReg(evReg, set) == false) {
    String message = "Assertion #4 failed ...\n" +
        "Event Registration is invalid.";
    throw new TestException(message);
      }

      String message = "Assertion #4 failed ...\n" +
    "Registration of null listener was allowed.";
      throw new TestException(message);

  } catch (NullPointerException ex) {
      // success, continue with the rest of the test
      logger.log(Level.FINE, "Assertion #4 passes!");
  }
View Full Code Here

        Transaction txn;
        String msg;

        // 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 two sample entries twice to the space
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);

        /*
         * take 1-st entry twice from the space using the same one as
         * a template within the transaction
         */
        for (int i = 1; i <= 2; i++) {
            msg = testTemplate(sampleEntry1, txn, Long.MAX_VALUE, i, 2,
                    false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write taken entries to the space again
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);

        // write 3-rd sample entry twice to the space
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using null as a template
         * within the transaction 6 times to take all written
         * entries from the space.
         */
        for (int i = 1; i <= 6; i++) {
            msg = testTemplate(null, txn, checkTime, i, 6, false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write all taken entries to the space again
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using template with 1-st null field
         * within the transaction 4 times to take all matching written
         * entries from the space.
         */
        template = new SimpleEntry(null, 2);

        for (int i = 1; i <= 4; i++) {
            msg = testTemplate(template, txn, timeout1, i, 4, false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write taken entries back to the space
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using template with 2-nd null field
         * within the transaction 4 times to take all matching written
         * entries from the space.
         */
        template = new SimpleEntry("TestEntry #1", null);

        for (int i = 1; i <= 4; i++) {
            msg = testTemplate(template, txn, timeout2, i, 4, false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // write taken entries back to the space
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * Take entry from the space using template with both null fields
         * within the transaction 6 times to take all matching written
         * entries from the space.
         */
        template = new SimpleEntry(null, null);

        for (int i = 1; i <= 6; i++) {
            msg = testTemplate(template, txn, checkTime, i, 6, false);

            if (msg != null) {
                throw new TestException(msg);
            }
        }

        // commit the transaction
        txnCommit(txn);
View Full Code Here

TOP

Related Classes of com.sun.jini.qa.harness.TestException

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.