Package com.sun.jini.qa.harness

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


    case QATestRegistrar.SELECT_METHOD_SAME_ONE:
              /* Verify that the service returned is always the
               * same service each time lookup() is called.
         */
              if (histogram[j].size() != 1) {
                  throw new TestException
                                ("histogram["+j+"].size ("
                                       +histogram[j].size()+") != 1" );
        }
              break;
    case QATestRegistrar.SELECT_METHOD_RANDOM:
              /* Test for randomness. A formal test for randomness (such
               * as a test for a Guassian Distribution) is not used.
               * For the purposes of this test, it is enough that at
               * least half of the number of possible matches have been
               * returned. This is true if the number of "hits" in the
               * histogram is at least half the value of
               * expectedNMatchesExact.
         */
              if (histogram[j].size()<(RN*expectedNMatchesExact[j])/RD) {
                  throw new TestException
                     (" histogram["+j+"].size() ("
                             +histogram[j].size()+") < ("
                             +RN+"*"+expectedNMatchesExact[j]+")/"+RD+
                            " (= "+(RN*expectedNMatchesExact[j])/RD+")");
        }
              break;
    default:
              throw new TestException
             ("INVALID Selection Method Value ("+selectMethod+")");
      }
  }
    }
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.");
        }

        // create snapshot
        snapshot = space.snapshot(sampleEntry);

        // 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
         * using it's snapshot
         */
        space.take(snapshot, 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 outside both transactions
         * using it's snapshot
         */
        result = (SimpleEntry) space.read(snapshot, null, checkTime);

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

        // 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 read the entry within another transaction
         * using it's snapshot
         */
        result = (SimpleEntry) space.read(snapshot, txn2, checkTime);

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

        // 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 outside both transactions
         * using it's snapshot
         */
        result = (SimpleEntry) space.take(snapshot, null, checkTime);

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

        // 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.");

        /*
         * check that we can not take the entry within another transaction
         * using it's snapshot
         */
        result = (SimpleEntry) space.take(snapshot, txn2, checkTime);

        if (result != null) {
            throw new TestException(
                    "performed take with template " + sampleEntry
                    + " within 2-nd transaction using it's snapshot"
                    + " while taking it"
                    + " within 1-st one, expected null but took " + result);
        }
View Full Code Here

  for (int i=0; i<nClasses; i++) {
      classTypes = proxy.getServiceTypes(classTmpls[i],null);     
      if (!QATestUtils.classTypesEqualTypeDescriptors(classTypes,
                  expectedTypeDescs[i]))
      {
    throw new TestException("For Attribute["+i+ "], "
            + "not all service type "
            + "descriptors were returned");
      }
  }
    }
View Full Code Here

      classTypes = proxy.getEntryClasses(tmpls[i]);
      if (!QATestUtils.classTypesEqualTypeDescriptors
                                    (classTypes,
                                                 expectedTypeDescs[i]))
      {
    throw new TestException("not ALL expected service type "
          + "descriptors were returned");
      }
  }
    }
View Full Code Here

   */
  if (evntVec.size() != 0) {
      String message = "evntVec.size() != 0\n" +
    "Event leases expired yet " + evntVec.size() +
    " event(s) arrived.";
      throw new TestException(message);
  }
    }
View Full Code Here

  // assert we received exactly one event
  RemoteEvent[] events = rrl.getEvents();
  if (events.length != 1) {
      String message = "Listener received " + events.length +
    " events but is required to receive exactly 1.";
      throw new TestException(message);
  }

  // the encapsulated Throwable should be null
  RenewalFailureEvent rfe = (RenewalFailureEvent) events[0];
  Throwable except = rfe.getThrowable();
  if (except != null) {
      String message = "The event encapsulated a Throwable of " +
    "type " + except.getClass() + " but should have returned" +
    " a value of null.";
      throw new TestException(message);
  }
    }
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.");
        }

        // write three sample entries twice to the space
        space.write(sampleEntry1, null, leaseForeverTime);
        space.write(sampleEntry1, null, leaseForeverTime);
        space.write(sampleEntry2, null, leaseForeverTime);
        space.write(sampleEntry2, null, leaseForeverTime);
        space.write(sampleEntry3, null, leaseForeverTime);
        space.write(sampleEntry3, null, leaseForeverTime);

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

        /*
         * readIfExists 1-st entry from the space using snapshot of
         * the same one as a template with JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        msg = testTemplate(sampleEntry1, txn, JavaSpace.NO_WAIT, 0, true);

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

        /*
         * readIfExists sample entry from the space using snapshots of
         * wrong template entries and JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        template = new SimpleEntry("TestEntry #3", 1);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

        // 2-nd wrong template
        template = new SimpleEntry("TestEntry #1", 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

        // 3-rd wrong template
        template = new SimpleEntry("TestEntry #3", 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

        // 4-th wrong template
        template = new SimpleEntry(null, 3);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

        // 5-th wrong template
        template = new SimpleEntry("TestEntry #3", null);
        msg = testWrongTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

        /*
         * readIfExists entry from the space using snapshot of null as a
         * template and JavaSpace.NO_WAIT timeout within the transaction
         */
        msg = testTemplate(null, txn, JavaSpace.NO_WAIT, 0, true);

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

        /*
         * readIfExists sample entries from the space using snapshots of
         * templates with null as a wildcard for different fields
         * and JavaSpace.NO_WAIT timeout within the transaction
         */
        template = new SimpleEntry("TestEntry #1", null);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

        // try 2-nd template
        template = new SimpleEntry(null, 2);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

        // 3-rd template
        template = new SimpleEntry(null, null);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 0, true);

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

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

        long leaseTime1 = timeout1;
        long leaseTime2 = timeout2;

        // 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 snapshot of 1-st entry with Lease.FOREVER lease time
         * to the space within the transaction
         */
        space.write(snapshot1, txn, Lease.FOREVER);

        /*
         * 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(
                    "written within the non null transaction snapshot of "
                    + sampleEntry1 + " with Lease.FOREVER lease time"
                    + " is not available in the space"
                    + " within the transaction.");
        }
        logDebugText(sampleEntry1.toString() + " with Lease.FOREVER"
                + " lease time has been successfully"
                + " written to the space using it's snapshot"
                + " within the non null transaction.");

        /*
         * write snapshot of 2-nd entry with Lease.ANY value for lease time
         * to the space within the transaction
         */
        space.write(snapshot2, txn, Lease.ANY);

        /*
         * 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(
                    "written within the non null transaction snapshot of "
                    + sampleEntry2 + " with Lease.ANY value for lease time"
                    + " is not available in the space"
                    + " within the transaction.");
        }
        logDebugText(sampleEntry1.toString() + " with Lease.ANY value"
                + " for lease time has been successfully"
                + " written to the space using it's snapshot"
                + " within the non null transaction.");

        /*
         * write snapshot of 1-st and 2-nd entries to the space within the
         * transaction again with finite lease times
         */
        space.write(snapshot1, txn, leaseTime1);
        logDebugText(sampleEntry1.toString() + " with " + leaseTime1
                + " has been successfully written again to the space"
                + " using it's snapshot within the non null transaction.");
        space.write(snapshot2, txn, leaseTime2);
        logDebugText(sampleEntry2.toString() + " with " + leaseTime2
                + " has been successfully written again to the space"
                + " using it's snapshot within the non null transaction.");

        // abort the transaction
        txnAbort(txn);

        // check that there are no entries in the space
        result = (SimpleEntry) space.read(null, null, checkTime);

        if (result != null) {
            throw new TestException(
                    "there is " + result + " still available in the"
                    + " space after transaction's aborting"
                    + " but null is expected.");
        }
        logDebugText("There are no entries in the space after"
View Full Code Here

  Lease managedLease = set.remove(testLease);
  if (managedLease == null) { // new membership was not honored
      String message = "The membership duration was apparently ";
      message += "not updated to the longer value\n";
      message += "when the lease was re-added to the set.";
      throw new TestException(message);
  }

  /* now assert that a shorter time will also be honored.
     start managing the lease for the base membership time
     again */
  logger.log(Level.FINE, "Adding lease with membership of " +
        doubleDuration + " milliseconds");
  set.renewFor(testLease, doubleDuration);
  logger.log(Level.FINE, "Re-adding lease with membership of " +
        membershipDuration + " milliseconds");
  set.renewFor(testLease, membershipDuration);
 
  // sleep 1.5 times the membership to ensure expiration
  sleepTime = membershipDuration + (membershipDuration / 2);
  rstUtil.sleepAndTell(sleepTime, "1.5 X membership duration.");

  /* if the membership duration was honored we should NOT be able
     to remove the lease because its membership has expired */
  managedLease = set.remove(testLease);
  if (managedLease != null) { // new membership was not honored
      String message = "The membership duration was apparently\n";
      message += "updated to a value that was longer than\n";
      message += "the base membership duration when the lease\n";
      message += "was re-added to the set.";
      throw new TestException(message);
  }
    }
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 three sample entries into the space
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * takeIfExists 1-st entry from the space using snapshot of
         * the same one as a template within the transaction
         */
        msg = testTemplate(sampleEntry1, txn, Long.MAX_VALUE, 0, 0, true);

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

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

        /*
         * takeIfExists sample entry from the space using snapshots of
         * different wrong template entries within the transaction
         */
        template = new SimpleEntry("TestEntry #3", 1);
        msg = testWrongTemplate(template, txn, checkTime, 0, 0, true);

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

        // 2-nd wrong template
        template = new SimpleEntry("TestEntry #1", 3);
        msg = testWrongTemplate(template, txn, timeout1, 0, 0, true);

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

        // 3-rd wrong template
        template = new SimpleEntry("TestEntry #3", 3);
        msg = testWrongTemplate(template, txn, timeout2, 0, 0, true);

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

        // 4-th wrong template
        template = new SimpleEntry(null, 3);
        msg = testWrongTemplate(template, txn, checkTime, 0, 0, true);

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

        // 5-th wrong template
        template = new SimpleEntry("TestEntry #3", null);
        msg = testWrongTemplate(template, txn, timeout2, 0, 0, true);

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

        /*
         * takeIfExists entry from the space using snapshot of null
         * as a template within the transaction
         */
        msg = testTemplate(null, txn, checkTime, 0, 0, true);

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

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        /*
         * takeIfExists sample entries from the space using snapshots of
         * templates with null as a wildcard for different fields
         * within the transaction
         */
        template = new SimpleEntry("TestEntry #1", null);
        msg = testTemplate(template, txn, checkTime, 0, 0, true);

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

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        // try 2-nd template
        template = new SimpleEntry(null, 2);
        msg = testTemplate(template, txn, timeout1, 0, 0, true);

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

        // clean the space and write 3 entries again
        cleanSpace(space, txn);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);

        // 3-rd template
        template = new SimpleEntry(null, null);
        msg = testTemplate(template, txn, timeout2, 0, 0, true);

        if (msg != null) {
            throw new TestException(msg);
        }
    }
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.