Package com.sun.jini.qa.harness

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


        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 snapshot of the same
         * one as a template with JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        for (int i = 1; i <= 2; i++) {
            msg = testTemplate(sampleEntry1, txn, JavaSpace.NO_WAIT, 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 snapshot of null as a template
         * and JavaSpace.NO_WAIT timeout within the transaction
         * 6 times to take all written entries from the space.
         */
        for (int i = 1; i <= 6; i++) {
            msg = testTemplate(null, txn, JavaSpace.NO_WAIT, 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 snapshot of template with
         * 1-st null field and JavaSpace.NO_WAIT timeout 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, JavaSpace.NO_WAIT, 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 snapshot of template with
         * 2-nd null field and JavaSpace.NO_WAIT timeout 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, JavaSpace.NO_WAIT, 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 snapshot of template with
         * both null fields and JavaSpace.NO_WAIT timeout 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, JavaSpace.NO_WAIT, i, 6,
                    false);

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

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


            URL httpmdUrl = createHTTPMDURL(filename);
            logger.log(Level.FINE, "httpmdUrl: " + httpmdUrl);

            /* Trying to get contents of the file specified by HTTPMD URL */
            String URLContents = getFileContents(httpmdUrl);
            throw new TestException(
                    "" + " test: Failed\n"
                    + "Expected result:\nWrongMessageDigestException\n"
                    + "Returned result:\n"
                    + "data from HTTPMD URL has been obtained successfully:\n"
                    + "  data:\n" + URLContents);
        } catch (WrongMessageDigestException e) {
            logger.log(Level.FINE, "Returned result:\n" + e);
        } catch (Exception e) {
            throw new TestException(
                    "" + " test: Failed\n"
                    + "Expected result:\nWrongMessageDigestException\n"
                    + "Returned result:\n" + e);
        }

View Full Code Here

  Long[] arrivalTimes = rrl.getArrivalTimes();
  RemoteEvent[] events = rrl.getEvents();
  if (events.length != 1 || arrivalTimes.length != 1) {
      String message = "Listener received " + events.length +
    " events but is required to receive exactly 1.";
      throw new TestException(message);
  }

  /* Assert that
     1) the expiration time of the lease whose renewal
        attempt failed, has an expiration time greater than
        the original expiration time.
     2) and greater than the arrival time of the renewal
        failure event
     3) and less than the expiration time that would have been
        granted had the renewal succeeded. */
  RenewalFailureEvent rfe = (RenewalFailureEvent) events[0];
  Lease managedLease = rfe.getLease();
  long currentExpiration = managedLease.getExpiration();
  long arrTime = arrivalTimes[0].longValue();
  boolean assert01 = currentExpiration > initialExpiration;
  boolean assert02 = currentExpiration > arrTime;
  boolean assert03 = currentExpiration < (arrTime + renewGrant);
  boolean correctExpiration = assert01 && assert02 && assert03;
  if (! correctExpiration) {
      String message = "The lease expiration time does not reflect" +
    " the result of the last successful renewal call because";
      if (assert01 == false || assert02 == false) {
    message += " the lease was never successfully renewed.";
      }
      if (assert03 == false) {
    message += " the lease was renewed in spite of the " +
        "renewal failure.";
      }

      throw new TestException(message);
  }
    }
View Full Code Here

        long timeout = leaseForeverTime;
        long leaseTime;

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

        // create snapshot of 1-st sample entry
        snapshot1 = space.snapshot(sampleEntry1);

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

        // create the non null transaction with finite time
        leaseTime = timeout2;
        txn = getTransaction(leaseTime);

        /*
         * take written entry from the space within the transaction
         * to lock read operations outside the transaction
         */
        space.take(sampleEntry1, txn, timeout);

        /*
         * read an entry from the space using it's snapshot
         * with timeout less then transaction's lease time,
         * check that read request will return null value
         * in time specified in read request
         */
        curTime1 = System.currentTimeMillis();
        result = (SimpleEntry) space.read(snapshot1, null, timeout1);
        curTime2 = System.currentTimeMillis();

        if (result != null) {
            throw new TestException(
                    "performed read with template " + sampleEntry1 + " and "
                    + timeout1 + " timeout using it's snapshot,"
                    + " expected null result but read " + result);
        }

        if ((curTime2 - curTime1) < timeout1
                || (curTime2 - curTime1) >= leaseTime) {
            throw new TestException(
                    "performed read with " + timeout1
                    + " timeout using snapshot,"
                    + " expected return time is greater then " + timeout1
                    + " and less then " + leaseTime
                    + ", but has returned in " + (curTime2 - curTime1));
        }
        logDebugText("Read with " + timeout1 + " timeout has returned in "
                + (curTime2 - curTime1));

        // commit the transaction and clean the space
        try {
            txnCommit(txn);
        } catch (Exception ex) {}
        cleanSpace(space);

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

        // create the non null transaction with finite time
        leaseTime = timeout1;
        curTime1 = System.currentTimeMillis();
        txn = getTransaction(leaseTime);

        /*
         * take written entry from the space within the transaction
         * to lock read operations outside the transaction
         */
        space.take(sampleEntry1, txn, timeout);

        /*
         * read an entry from the space using it's snapshot
         * with timeout greater then transaction's lease time,
         * check that read request will return
         * non null entry after transaction's expiration
         */
        result = (SimpleEntry) space.read(snapshot1, null, timeout2);
        curTime2 = System.currentTimeMillis();

        if (!sampleEntry1.equals(result)) {
            throw new TestException(
                    "performed read with template " + sampleEntry1 + " and "
                    + timeout2 + " timeout using it's snapshot, expected "
                    + sampleEntry1 + " result but read " + result);
        }

        if ((curTime2 - curTime1) < leaseTime
                || (curTime2 - curTime1) >= timeout2) {
            throw new TestException(
                    "performed read with " + timeout2
                    + " timeout using snapshot,"
                    + " expected return time is greater then " + leaseTime
                    + " and less then " + timeout2
                    + ", but has returned in " + (curTime2 - curTime1));
        }
        logDebugText("Read with " + timeout2 + " timeout has returned in "
                + (curTime2 - curTime1));

        // clean the space
        cleanSpace(space);

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

        // create the non null transaction with finite time
        leaseTime = timeout2 * 2;
        curTime1 = System.currentTimeMillis();
        txn = getTransaction(leaseTime);

        /*
         * take written entry from the space within the transaction
         * to lock read operations outside the transaction
         */
        space.take(sampleEntry1, txn, leaseForeverTime);

        /*
         * start thread which will write 2-nd sample entry
         * to the space in timeout1 ms
         */
        EntryWriter writer = new EntryWriter(sampleEntry2, timeout1, space);
        writer.start();

        // read any entry from the space using snapshot of null
        result = (SimpleEntry) space.read(space.snapshot(null), null,
                timeout2 * 2);
        curTime2 = System.currentTimeMillis();

        // check that read request has returned required entry
        if (!sampleEntry2.equals(result)) {
            throw new TestException(
                    "performed read with snapshot of null template and "
                    + (timeout2 * 2) + " timeout, expected " + sampleEntry1
                    + " result but read " + result);
        }

        /*
         * check that read request returns 2-nd written entry before
         * transaction's and read's expirations
         */
        if ((curTime2 - curTime1) > leaseTime
                || (curTime2 - curTime1) < timeout1) {
            throw new TestException(
                    "performed read with " + (timeout2 * 2)
                    + " timeout, expected return time is greater then "
                    + leaseTime + " and less then " + timeout1
                    + ", but has returned in " + (curTime2 - curTime1));
        }
View Full Code Here

         */
        gotMsg = e.getMessage();

        /* Comparing the messages */
        if (!originalMsg.equals(gotMsg)) {
            throw new TestException(
                    "The detailed message of this " + "WrongMessageDigestException object \""
                    + gotMsg + "\" isn't equal to the one specified while "
                    + "creating this object with "
                    + "WrongMessageDigestException(\"" + originalMsg
                    + "\") constructor.");
View Full Code Here

        long leaseTime3 = timeout2 * 3;
        int i;

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

        // create snapshots of sample entries
        snapshot1 = space.snapshot(sampleEntry1);
        snapshot2 = space.snapshot(sampleEntry2);
        snapshot3 = space.snapshot(sampleEntry3);

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

        /*
         * init 3 RemoteEvent counters for each of sample entries
         * and their snapshots
         */
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, leaseTime1,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, leaseTime2,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, leaseTime3,
                space);

        // init 5 counters with wrong templates and their snapshots
        template = new SimpleEntry("TestEntry #3", 1);
        snsh_ncs[3] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // 2-nd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #1", 3);
        snsh_ncs[4] = new SnapshotNotifyCounter(template, leaseTime2,
                space);

        // 3-rd wrong template it's snapshot
        template = new SimpleEntry("TestEntry #3", 3);
        snsh_ncs[5] = new SnapshotNotifyCounter(template, leaseTime3,
                space);

        // 4-th wrong template it's snapshot
        template = new SimpleEntry(null, 3);
        snsh_ncs[6] = new SnapshotNotifyCounter(template, leaseForeverTime,
                space);

        // 5-th wrong template it's snapshot
        template = new SimpleEntry("TestEntry #3", null);
        snsh_ncs[7] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // init counter with null entry as a template and it's snapshot
        snsh_ncs[8] = new SnapshotNotifyCounter(null, leaseForeverTime,
                space);

        // init 3 counters with null values for different fields
        template = new SimpleEntry("TestEntry #1", null);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // 2-nd template
        template = new SimpleEntry(null, 2);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, leaseTime2,
                space);

        // 3-rd template
        template = new SimpleEntry(null, null);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, leaseTime3,
                space);

        // now register all counters
        for (i = 0; i < 12; i++) {
            snsh_ers[i] = space.notify(snsh_ncs[i].getSnapshot(), txn,
                    snsh_ncs[i], snsh_ncs[i].getLeaseTime(), null);
        }

        // sleep for a while to let all listeners register properly
        Thread.sleep(timeout1);
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners register properly.");

        /*
         * write 3 sample entries 3 times to the space
         * within the transaction
         */
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        logDebugText("3 sample entries have been written"
                + " to the space 3 times.");

        // wait for a while to let all listeners get notifications
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners get notifications.");
        Thread.sleep(timeout1);

        // check, that listeners got required number of notifications
        for (i = 0; i < 12; i++) {
            if (snsh_ncs[i].getEventsNum(snsh_ers[i]) != evMatrix[i]) {
                failed = true;
                snsh_failMatrix[i] = true;
            } else {
                snsh_failMatrix[i] = false;
            }
        }

        for (i = 0; i < 12; i++) {
            if (snsh_failMatrix[i]) {
                logDebugText("FAILED: " + snsh_ncs[i] + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications instead of " + evMatrix[i]
                        + " required.");
            } else {
                logDebugText(snsh_ncs[i].toString() + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications as expected");
            }
        }
        logDebugText("Stage 1 with writing ordinal entries has been"
                + " completed.");
        logDebugText("------------------------------\n");
        logDebugText("Starting 2-nd stage with snapshots.");

        // clean the space
        cleanSpace(space, txn);

        /*
         * init 3 RemoteEvent counters for each of sample entries
         * and their snapshots
         */
        ncs[0] = new NotifyCounter(sampleEntry1, leaseTime1);
        ncs[1] = new NotifyCounter(sampleEntry2, leaseTime2);
        ncs[2] = new NotifyCounter(sampleEntry3, leaseTime3);
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, leaseTime1,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, leaseTime2,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, leaseTime3,
                space);

        // init 5 counters with wrong templates and their snapshots
        template = new SimpleEntry("TestEntry #3", 1);
        ncs[3] = new NotifyCounter(template, leaseTime1);
        snsh_ncs[3] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // 2-nd wrong template and it's snapshot
        template = new SimpleEntry("TestEntry #1", 3);
        ncs[4] = new NotifyCounter(template, leaseTime2);
        snsh_ncs[4] = new SnapshotNotifyCounter(template, leaseTime2,
                space);

        // 3-rd wrong template it's snapshot
        template = new SimpleEntry("TestEntry #3", 3);
        ncs[5] = new NotifyCounter(template, leaseTime3);
        snsh_ncs[5] = new SnapshotNotifyCounter(template, leaseTime3,
                space);

        // 4-th wrong template it's snapshot
        template = new SimpleEntry(null, 3);
        ncs[6] = new NotifyCounter(template, leaseForeverTime);
        snsh_ncs[6] = new SnapshotNotifyCounter(template, leaseForeverTime,
                space);

        // 5-th wrong template it's snapshot
        template = new SimpleEntry("TestEntry #3", null);
        ncs[7] = new NotifyCounter(template, leaseTime1);
        snsh_ncs[7] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // init counter with null entry as a template and it's snapshot
        ncs[8] = new NotifyCounter(null, leaseForeverTime);
        snsh_ncs[8] = new SnapshotNotifyCounter(null, leaseForeverTime,
                space);

        // init 3 counters with null values for different fields
        template = new SimpleEntry("TestEntry #1", null);
        ncs[9] = new NotifyCounter(template, leaseTime1);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, leaseTime1,
                space);

        // 2-nd template
        template = new SimpleEntry(null, 2);
        ncs[10] = new NotifyCounter(template, leaseTime2);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, leaseTime2,
                space);

        // 3-rd template
        template = new SimpleEntry(null, null);
        ncs[11] = new NotifyCounter(template, leaseTime3);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, leaseTime3,
                space);

        // now register all counters
        for (i = 0; i < 12; i++) {
            ers[i] = space.notify(ncs[i].getTemplate(), txn, ncs[i],
                    ncs[i].getLeaseTime(), null);
            snsh_ers[i] = space.notify(snsh_ncs[i].getSnapshot(), txn,
                    snsh_ncs[i], snsh_ncs[i].getLeaseTime(), null);
        }

        // sleep for a while to let all listeners register properly
        Thread.sleep(timeout1);
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners register properly.");

        /*
         * write 3 sample entries using their snapshots 3 times to the space
         * within the transaction
         */
        space.write(snapshot1, txn, leaseForeverTime);
        space.write(snapshot1, txn, leaseForeverTime);
        space.write(snapshot1, txn, leaseForeverTime);
        space.write(snapshot2, txn, leaseForeverTime);
        space.write(snapshot2, txn, leaseForeverTime);
        space.write(snapshot2, txn, leaseForeverTime);
        space.write(snapshot3, txn, leaseForeverTime);
        space.write(snapshot3, txn, leaseForeverTime);
        space.write(snapshot3, txn, leaseForeverTime);
        logDebugText("Snapshots of 3 sample entries have been written"
                + " to the space 3 times.");

        // wait for a while to let all listeners get notifications
        logDebugText("now sleeping for " + timeout1
                + " to let all listeners get notifications.");
        Thread.sleep(timeout1);

        // check, that listeners got required number of notifications
        for (i = 0; i < 12; i++) {
            if (ncs[i].getEventsNum(ers[i]) != evMatrix[i]) {
                failed = true;
                snsh_failMatrix[i] = true;
            } else {
                snsh_failMatrix[i] = false;
            }

            if (snsh_ncs[i].getEventsNum(snsh_ers[i]) != evMatrix[i]) {
                failed = true;
                failMatrix[i] = true;
            } else {
                failMatrix[i] = false;
            }
        }

        for (i = 0; i < 12; i++) {
            if (failMatrix[i]) {
                logDebugText("FAILED: " + ncs[i] + " has got "
                        + ncs[i].getEventsNum(ers[i])
                        + " notifications instead of " + evMatrix[i]
                        + " required.");
            } else {
                logDebugText(ncs[i].toString() + " has got "
                        + ncs[i].getEventsNum(ers[i])
                        + " notifications as expected");
            }

            if (snsh_failMatrix[i]) {
                logDebugText("FAILED: " + snsh_ncs[i] + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications instead of " + evMatrix[i]
                        + " required.");
            } else {
                logDebugText(snsh_ncs[i].toString() + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications as expected");
            }
        }
        logDebugText("Stage 2 with writing snapshots has been"
                + " completed.\n");

        // commit the transaction
        txnCommit(txn);

        // check: we fail of pass
        if (failed) {
            throw new TestException(
                    "Not all listeners've got expected number of events.");
        }
    }
View Full Code Here

  // validate the registration (just for grins)
  if (rstUtil.isValidExpWarnEventReg(reg01, set01) == false) {
      String message = "Registration #1 is invalid because:\n" +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }

  logger.log(Level.FINE, "Registering listener to receive " +
        "ExpirationWarngingEvents for set #2.");
  logger.log(Level.FINE, "minWarning = " + minWarning + " milliseconds");
  EventRegistration reg02 =
      set02.setExpirationWarningListener(rrl, minWarning, null);
  reg02 = prepareRegistration(reg02);

  // validate the registration (just for grins)
  if (rstUtil.isValidExpWarnEventReg(reg02, set02) == false) {
      String message = "Registration #2 is invalid because:\n" +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }

  logger.log(Level.FINE, "Registering listener to receive " +
        "ExpirationWarngingEvents for set #3.");
  logger.log(Level.FINE, "minWarning = " + minWarning + " milliseconds");
  EventRegistration reg03 =
      set03.setExpirationWarningListener(rrl, minWarning, null);
  reg03 = prepareRegistration(reg03);

  // validate the registration (just for grins)
  if (rstUtil.isValidExpWarnEventReg(reg03, set03) == false) {
      String message = "Registration #3 is invalid because:\n" +
    rstUtil.getFailureReason();
      throw new TestException(message);
  }

  // wait for the events to roll in ...
  rstUtil.waitForRemoteEvents(rrl, 3, renewSetDur);

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

  // assert that each event holds the expected ID value
  for (int i = 0; i < events.length; ++i) {
      ExpirationWarningEvent ewe =
    (ExpirationWarningEvent) events[i];
      if (ewe.getID() !=
    LeaseRenewalSet.EXPIRATION_WARNING_EVENT_ID) {
      String message = "Event #" + i + " has the wrong event ID.\n" +
    "ID = " + ewe.getID() + " but it should be " +
    LeaseRenewalSet.EXPIRATION_WARNING_EVENT_ID;
      throw new TestException(message);
      }
  }
    }
View Full Code Here

        long curTime2;
        long leaseTime;

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

        // create snapshot of sample entry
        snapshot1 = space.snapshot(sampleEntry1);

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

        // create the non null transaction with finite time
        leaseTime = timeout2;
        txn = getTransaction(leaseTime);

        /*
         * take written entry from the space within the transaction
         * to lock read operations outside the transaction
         */
        space.take(sampleEntry1, txn, checkTime);

        /*
         * readIfExists an entry from the space with timeout less then
         * transaction's lease time using it's snapshot,
         * check that readIfExists request will
         * return null value in time specified in this request
         */
        curTime1 = System.currentTimeMillis();
        result = (SimpleEntry) space.readIfExists(snapshot1, null,
                timeout1);
        curTime2 = System.currentTimeMillis();

        if (result != null) {
            throw new TestException(
                    "performed readIfExists of " + sampleEntry1 + " with "
                    + timeout1 + " timeout using it's snapshot,"
                    + " expected null result but read " + result);
        }

        if (((curTime2 - curTime1) < timeout1)
                || ((curTime2 - curTime1) >= leaseTime)) {
            throw new TestException(
                    "performed readIfExists with " + timeout1
                    + " timeout using it's snapshot,"
                    + " transaction's lease time is " + leaseTime
                    + ", expected return time is greater then " + timeout1
                    + " and less then " + leaseTime
                    + ", but has returned in " + (curTime2 - curTime1));
        }
        logDebugText("readIfExists with " + timeout1
                + " timeout using it's snapshot and transaction with "
                + leaseTime + " lease time" + " works as expected.");

        // commit the transaction and clean the space
        try {
            txnCommit(txn);
        } catch (Exception ex) {}
        cleanSpace(space);

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

        // create the non null transaction with finite time
        curTime1 = System.currentTimeMillis();
        leaseTime = timeout1;
        txn = getTransaction(leaseTime);

        /*
         * take written entry from the space within the transaction
         * to lock read operations outside the transaction
         */
        space.take(sampleEntry1, txn, checkTime);

        /*
         * readIfExists an entry from the space with timeout greater
         * then transaction's lease time using it's snapshot,
         * check that readIfExists request
         * will return non null entry after transaction's expiration
         */
        result = (SimpleEntry) space.readIfExists(snapshot1, null,
                timeout2);
        curTime2 = System.currentTimeMillis();

        if (result == null) {
            throw new TestException(
                    "performed readIfExists of " + sampleEntry1 + " with "
                    + timeout2 + " timeout using it's snapshot,"
                    + " expected non null but read null result.");
        }

        if (((curTime2 - curTime1) < leaseTime)
                || ((curTime2 - curTime1) >= timeout2)) {
            throw new TestException(
                    "performed readIfExists with " + timeout2
                    + " timeout using it's snapshot,"
                    + " transaction's lease time is " + leaseTime
                    + ", expected return time is greater then " + leaseTime
                    + " and less then " + timeout2
                    + ", but has returned in " + (curTime2 - curTime1));
        }
        logDebugText("readIfExists with " + timeout2
                + " timeout using it's snapshot and transaction with "
                + leaseTime + " lease time" + " works as expected.");

        // clean the space
        cleanSpace(space);

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

        // create the non null transaction with finite time
        curTime1 = System.currentTimeMillis();
        leaseTime = timeout2 * 2;
        txn = getTransaction(leaseTime);

        /*
         * take written entry from the space within the transaction
         * to lock read operations outside the transaction
         */
        space.take(sampleEntry1, txn, checkTime);

        /*
         * start thread which will write 2-nd sample entry
         * to the space in timeout1 ms
         */
        EntryWriter writer = new EntryWriter(sampleEntry2, timeout1, space);
        writer.start();

        // readIfExists any entry from the space using snapshot of null
        result = (SimpleEntry) space.readIfExists(space.snapshot(null),
                null, timeout2);
        curTime2 = System.currentTimeMillis();

        /*
         * check that readIfExists request returns 2-nd written entry
         * before transaction's and readIfExists expirations
         */
        if (result == null) {
            throw new TestException(
                    "performed readIfExists with snapshot of null template"
                    + " and " + timeout2
                    + " timeout, expected non null but read null result.");
        }

        if (((curTime2 - curTime1) < timeout1)
                || ((curTime2 - curTime1) >= timeout2)) {
            throw new TestException(
                    "performed readIfExists with " + timeout2
                    + " timeout using snapshot of null template,"
                    + " transaction's lease time is " + leaseTime
                    + " 2-nd entry has been written to the space in "
                    + timeout1 + " ms,"
View Full Code Here

  Lease lease01 = prepareLease(renewalSet[0].getRenewalSetLease());
  Lease lease02 = evReg.getLease();
  if (lease01.equals(lease02) == false) {
      String message = "The renewal set lease and the warning " +
           "event registration lease are not the same.";
      throw new TestException(message);
  }

  // register for RenewalFailureEvents
  evReg = renewalSet[0].setRenewalFailureListener(listener[0], null);
  evReg = prepareRegistration(evReg);
 
  /* ASSERTION #1 cont'd
     The set lease and the registration lease are the same. */
  Lease lease03 = evReg.getLease();
  if (lease01.equals(lease03) == false) {
      String message = "The renewal set lease and the failure" +
    "event registration lease are not the same.";
      throw new TestException(message);
  }

  logger.log(Level.FINE, "Assertion #1 passed.");

  // register all twenty remote listeners
  for (int i = 0; i < NUMBER_OF_RENEWAL_SETS; ++i) {
      evReg =
    renewalSet[i].setExpirationWarningListener(listener[i], 1,
                 null);
      evReg = prepareRegistration(evReg);
      warnReg[i] = evReg;
      evReg =
    renewalSet[i].setRenewalFailureListener(listener[i], null);
      evReg = prepareRegistration(evReg);
      failReg[i] = evReg;
  }

  /* ASSERTION #2
     The registrations are unique and event ids are valid across
     all active registrations. */
  for (int i = 0; i < NUMBER_OF_RENEWAL_SETS; ++i) {

      if (rstUtil.isValidExpWarnEventReg(warnReg[i],
               renewalSet[i]) == false) {
    String message = "Warning event registration # " + i +
        " is invalid." + rstUtil.getFailureReason();
    throw new TestException(message);
      }

      if (rstUtil.isValidRenewFailEventReg(failReg[i],
           renewalSet[i]) == false) {
    String message = "Failure event registration # " + i +
        " is invalid." + rstUtil.getFailureReason();
    throw new TestException(message);
      }

      // create yet another RemoteEventListener
      Exporter exp = null;
      RememberingRemoteListener newListener =
    new RememberingRemoteListener(getExporter());
      evReg =
    renewalSet[0].setExpirationWarningListener(newListener,
                 1, null);
      evReg = prepareRegistration(evReg);

      /* ASSERTION #3
         When a listener is replaced the event registration has
         the same event id */
      if (! (evReg.getID() == warnReg[0].getID())) {
    String message = "When a warning registration is " +
        "replaced, the event id is not preserved.";
    throw new TestException(message);
      }
     
      // and just for grins check the lease as well
      if (evReg.getLease().equals(warnReg[0].getLease()) == false) {
    String message = "When a warning registration is " +
        "replaced, the lease is not preserved.";
    throw new TestException(message);
      }
     
      /* ASSERTION #3 (cont'd for renewal failure events)
         When a listener is replaced the event registration has
         the same event id */
      evReg =
    renewalSet[0].setRenewalFailureListener(newListener,
              null);
      evReg = prepareRegistration(evReg);
      if (! (evReg.getID() == failReg[0].getID())) {
    String message = "When a failure registration is " +
        "replaced, the event id is not preserved.";
    throw new TestException(message);
      }
     
      // and just for grins check the lease as well
      if (evReg.getLease().equals(failReg[0].getLease()) == false) {
    String message = "When a failure registration is " +
        "replaced, the lease is not preserved.";
    throw new TestException(message);
      }

  }

  logger.log(Level.FINE, "Assertion #2 passed.");
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 within the transaction
         */
        msg = testTemplate(sampleEntry1, txn, Long.MAX_VALUE, 0, true);

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

        /*
         * readIfExists sample entry from the space using snapshots of
         * wrong template entries within the transaction
         */
        template = new SimpleEntry("TestEntry #3", 1);
        msg = testWrongTemplate(template, txn, checkTime, 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, true);

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

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

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

        // 4-th wrong template
        template = new SimpleEntry(null, 3);
        msg = testWrongTemplate(template, txn, checkTime, 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, true);

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

        /*
         * readIfExists entry from the space using snapshot of null
         * as a template within the transaction
         */
        msg = testTemplate(null, txn, timeout1, 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, timeout1, 0, true);

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

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

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

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

        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.