Package com.sun.jini.qa.harness

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


        long nVal = -199;
        boolean caught = false;

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

        /*
         * try to write an entry within the transaction
         * with negative lease time other then Lease.ANY value.
         */
        origEntry = (SimpleEntry) sampleEntry.clone();

        try {
            space.write(sampleEntry, txn, nVal);
        } catch (IllegalArgumentException iae) {
            logDebugText("IllegalArgumentException is caught as expected"
                    + " while writing with " + nVal
                    + " value for lease time within the non null"
                    + " transaction.");
            caught = true;
        } catch (Exception ex) {
            throw new TestException(
                    "Unexpected exception has been thrown while using "
                    + nVal + " value for lease time: " + ex);
        }

        if (!caught) {
            throw new TestException(
                    "IllegalArgumentException was not"
                    + " thrown while specifying " + nVal
                    + " value for lease time.");
        }

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

        /*
         * check that entry has not been written to the space
         * within the transaction
         */
        result = (SimpleEntry) space.read(sampleEntry, txn, checkTime);

        if (result != null) {
            throw new TestException(
                    "performed write operation of " + sampleEntry
                    + " with " + nVal + " value for lease time within the"
                    + " non null transaction. In spite of throwing an"
                    + " IllegalArgumentException, entry has been written"
                    + " to the space.");
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 snapshot of 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 snapshot of 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 snapshot of 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 snapshot of 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 snapshot of 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

                returnedVal = retVal;
            }
        }

        if (returnedVal != true) {
            throw new TestException(
                    "" + " test failed");
        }
        return;
    }
View Full Code Here

  long actualExpTime = managedLease.getExpiration();
  long deltaExpTime = actualExpTime - originalExpTime;
  long roundTrip = time02 - time01;
  if (deltaExpTime >= roundTrip) {
      String message = "Expiration time was permaturely altered.";
      throw new TestException(message);
  }

  // just to make certain assert that there are no renew or cancels
  if (leaseOwner.getRenewCalls() > 0) {
      String message = "LRS made an erronous call to renew.";
      throw new TestException(message);
  }
  if (leaseOwner.getCancelCalls() > 0) {
      String message = "LRS made a forbidden call to cancel.";
      throw new TestException(message);
  }

  // create a test lease to be managed
  logger.log(Level.FINE, "Creating the lease to be managed.");
  logger.log(Level.FINE, "Duration == " + renewGrant);
  long leaseCreation = System.currentTimeMillis();
  testLease =
      leaseProvider.createNewLease(leaseOwner,
           rstUtil.durToExp(renewGrant));
  originalExpTime = testLease.getExpiration();

  // start managing the lease
  long membershipDuration = renewGrant + (renewGrant / 2);
  logger.log(Level.FINE, "Adding lease with membership of " +
        membershipDuration + " millseconds.");
  set.renewFor(testLease, membershipDuration);

  // wait for client lease to become renewed
  rstUtil.waitForLeaseExpiration(testLease,
               "for client lease to renew.");

  // remove the lease to prevent any further action
  managedLease = set.remove(testLease);

  /* By now the lease has been renewed (exactly) once.
     To show that the expiration time of the lease reflects
     the time set as a result of the last successful renew,
     we will show that the renewal time is between the time
     the test lease was originally created and its original
     expiration time.
      T0---------------T1----------T2-------------T3
       \lease          \renewal    \original      \current
        creation        time        expriation     expiration
       
      Calculate T1 (T3-renewalGrant) and show that T0 < T1 < T2 */
  long renewalTime = managedLease.getExpiration() - renewGrant;
  boolean inRange = renewalTime > leaseCreation &&
        renewalTime < originalExpTime;
  if (inRange == false) {
      String message = "Lease expiration does not reflect the\n" +
           "latest successful renewal.";
      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 with JavaSpace.NO_WAIT timeout
         * within the transaction
         */
        msg = testTemplate(sampleEntry1, txn, JavaSpace.NO_WAIT, 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
         * 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, 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, 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, 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, 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, 0,
                true);

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

        /*
         * takeIfExists 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, 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
         * and JavaSpace.NO_WAIT timeout within the transaction
         */
        template = new SimpleEntry("TestEntry #1", null);
        msg = testTemplate(template, txn, JavaSpace.NO_WAIT, 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, JavaSpace.NO_WAIT, 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, JavaSpace.NO_WAIT, 0, 0, true);

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

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

        long leaseTime3 = Lease.ANY;
        int i;

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

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

        /*
         * 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 with null transaction parameter
        for (i = 0; i < 12; i++) {
            ers[i] = space.notify(ncs[i].getTemplate(), null, ncs[i],
                    ncs[i].getLeaseTime(), null);
            snsh_ers[i] = space.notify(snsh_ncs[i].getSnapshot(), null,
                    snsh_ncs[i], snsh_ncs[i].getLeaseTime(), null);
        }

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

        /*
         * write 3 sample entries (or their snapshots) 3 times to the
         * space within the transaction
         */
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(sampleEntry1, txn, leaseForeverTime);
        space.write(snapshot1, txn, leaseForeverTime);
        space.write(snapshot2, txn, leaseForeverTime);
        space.write(snapshot2, txn, leaseForeverTime);
        space.write(sampleEntry2, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        space.write(snapshot3, txn, leaseForeverTime);
        space.write(sampleEntry3, txn, leaseForeverTime);
        logDebugText("3 sample entries have been written"
                + " to the space 3 times within the non null transaction.");

        /*
         * now take 1 sample entry 1 time, 2-nd - 2 and 3-rd 3 times
         * (or their snapshots) within the transaction
         */
        space.takeIfExists(sampleEntry1, txn, checkTime);
        space.takeIfExists(sampleEntry2, txn, checkTime);
        space.takeIfExists(snapshot2, txn, checkTime);
        space.takeIfExists(sampleEntry3, txn, checkTime);
        space.takeIfExists(snapshot3, txn, checkTime);
        space.takeIfExists(snapshot3, txn, checkTime);
        logDebugText(sampleEntry1.toString() + " has been taken 1 time, "
                + sampleEntry2 + " has been taken 2 times, " + sampleEntry3
                + " has been taken 3 times successfully within"
                + " the transaction by takeIfExists method.");

        // commit the transaction
        txnCommit(txn);

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

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

            if (snsh_ncs[i].getEventsNum(snsh_ers[i]) != evTxnMatrix[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 " + evTxnMatrix[i]
                        + " required after transaction's committing.");
            } else {
                logDebugText(ncs[i].toString() + " has got "
                        + ncs[i].getEventsNum(ers[i])
                        + " notifications as expected"
                        + " after transaction's committing");
            }

            if (snsh_failMatrix[i]) {
                logDebugText("FAILED: " + snsh_ncs[i] + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications instead of " + evTxnMatrix[i]
                        + " required after transaction's committing.");
            } else {
                logDebugText(snsh_ncs[i].toString() + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications as expected"
                        + " after transaction's committing");
            }
        }

        // check: we fail of pass
        if (failed) {
            throw new TestException(
                    "Not all listeners've got expected number of events.");
        }
    }
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);
  }

  // assert that the source is the one that we expect
  LeaseRenewalSet expiredSet =
      (LeaseRenewalSet) events[0].getSource();
  if (expiredSet.equals(set03) == false) {
      String message = "The source of the event was not the set" +
    " that caused the ExpirationWarningEvent.";
      throw new TestException(message);
  }
    }
View Full Code Here

        Transaction txn;
        int i;

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

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

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

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

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

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

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

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

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

        /*
         * init 3 counters for templates with null values for different
         * fields and their snapshots
         */
        template = new SimpleEntry("TestEntry #1", null);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 2-nd template and it's snapshot
        template = new SimpleEntry(null, 2);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, Lease.ANY,
                space);

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.ANY,
                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 to the space 3 times
         * 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, Lease.ANY);
        ncs[1] = new NotifyCounter(sampleEntry2, Lease.ANY);
        ncs[2] = new NotifyCounter(sampleEntry3, Lease.ANY);
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, Lease.ANY,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, Lease.ANY,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, Lease.ANY,
                space);

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

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

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

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

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

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

        /*
         * init 3 counters for templates with null values for different
         * fields and their snapshots
         */
        template = new SimpleEntry("TestEntry #1", null);
        ncs[9] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, Lease.ANY, space);

        // 2-nd template and it's snapshot
        template = new SimpleEntry(null, 2);
        ncs[10] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[10] = new SnapshotNotifyCounter(template, Lease.ANY,
                space);

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        ncs[11] = new NotifyCounter(template, Lease.ANY);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.ANY,
                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 to the space 3 times
         * 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

  Lease[] leaseArray = set.getLeases();

  if (leaseArray.length < 1) {
      String message = "The lease was removed from the renewal set" +
    " prematurely.";
      throw new TestException(message);
  }

  if (leaseArray.length > 1) {
      String message = "Error in test: More than one lease was" +
    "added to the lease renewal set.";
      throw new TestException(message);
  }

  // expiration time must remain unaltered
  long currentExpTime = leaseArray[0].getExpiration();
  long deltaExpTime = currentExpTime - originalExpTime;

  if (deltaExpTime > roundTrip) {
      String message = "The expiration of the lease has been altered."
    + "\n   originalExpTime = " + originalExpTime
    + "\n   currentExpTime = " + currentExpTime
    + "\n   deltaExpTime = " + deltaExpTime
    + "\n   roundTrip = " + roundTrip;
      throw new TestException(message);
  }

  // sleep again so that the test lease expires
  rstUtil.sleepAndTell(membershipDur / 3,
           "1/3 membership duration time.");

  // assert that the lease was removed from the set
  leaseArray = set.getLeases();
  if (leaseArray.length != 0) {
      String message = "The lease was not removed from the renewal" +
    " set as expected.";
      throw new TestException(message);
  }
    }
View Full Code Here

        long txnLeaseTime = leaseTime1 + timeout1;
        int i;

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

        // snapshot sample entry
        snapshot = space.snapshot(sampleEntry);

        /*
         * init 5 RemoteEvent counters with different lease times
         * and snapshot to use with null transaction parameter
         */
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry, leaseTime1,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry, leaseTime2,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry, leaseTime3,
                space);
        snsh_ncs[3] = new SnapshotNotifyCounter(sampleEntry,
                leaseForeverTime, space);
        snsh_ncs[4] = new SnapshotNotifyCounter(sampleEntry, Lease.FOREVER,
                space);

        /*
         * init 5 RemoteEvent counters with different lease times
         * and snapshot to use with non null transaction parameter
         */
        snsh_ncs[5] = new SnapshotNotifyCounter(sampleEntry, leaseTime1,
                space);
        snsh_ncs[6] = new SnapshotNotifyCounter(sampleEntry, leaseTime2,
                space);
        snsh_ncs[7] = new SnapshotNotifyCounter(sampleEntry, leaseTime3,
                space);
        snsh_ncs[8] = new SnapshotNotifyCounter(sampleEntry,
                leaseForeverTime, space);
        snsh_ncs[9] = new SnapshotNotifyCounter(sampleEntry, Lease.FOREVER,
                space);

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

        // create the non null transaction with finite lease time
        txn = getTransaction(txnLeaseTime);

        // now register all counters with non null transaction parameter
        for (i = 5; i < 10; i++) {
            snsh_ers[i] = space.notify(snsh_ncs[i].getSnapshot(), txn,
                    snsh_ncs[i], snsh_ncs[i].getLeaseTime(), null);
        }

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

        // sleep for a while to let some listeners expire
        Thread.sleep(timeout2 + instantTime);
        logDebugText("now sleeping for " + (timeout2 + instantTime)
                + " to to let some listeners expire...");

        // write sample entry twice again
        space.write(sampleEntry, null, leaseForeverTime);
        space.write(sampleEntry, null, leaseForeverTime);

        // sleep again for a while to let transaction expires
        Thread.sleep(timeout1);
        logDebugText("now sleeping for " + timeout1
                + " to let to let transaction expires...");

        // write sample entry twice again
        space.write(sampleEntry, null, leaseForeverTime);
        space.write(sampleEntry, null, leaseForeverTime);

        // sleep again for a while to let some listeners expire
        Thread.sleep(timeout2 - timeout1);
        logDebugText("now sleeping for " + (timeout2 - timeout1)
                + " to to let some listeners expire...");

        // write sample entry twice again
        space.write(sampleEntry, null, leaseForeverTime);
        space.write(sampleEntry, null, leaseForeverTime);

        // sleep again for a while to let some listeners expire
        Thread.sleep(timeout2);
        logDebugText("now sleeping for " + timeout2
                + " to to let some listeners expire...");

        // write sample entry twice again
        space.write(sampleEntry, null, leaseForeverTime);
        space.write(sampleEntry, null, leaseForeverTime);

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

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

        for (i = 0; i < 10; i++) {
            if (snsh_failMatrix[i]) {
                logDebugText("FAILED: " + snsh_ncs[i] + " has got "
                        + snsh_ncs[i].getEventsNum(snsh_ers[i])
                        + " notifications instead of " + evTxnMatrix[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);

        /*
         * init 5 RemoteEvent counters with different lease times
         * to use with null transaction parameter
         */
        ncs[0] = new NotifyCounter(sampleEntry, leaseTime1);
        ncs[1] = new NotifyCounter(sampleEntry, leaseTime2);
        ncs[2] = new NotifyCounter(sampleEntry, leaseTime3);
        ncs[3] = new NotifyCounter(sampleEntry, leaseForeverTime);
        ncs[4] = new NotifyCounter(sampleEntry, Lease.FOREVER);

        /*
         * init 5 RemoteEvent counters with different lease times
         * and snapshot to use with null transaction parameter
         */
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry, leaseTime1,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry, leaseTime2,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry, leaseTime3,
                space);
        snsh_ncs[3] = new SnapshotNotifyCounter(sampleEntry,
                leaseForeverTime, space);
        snsh_ncs[4] = new SnapshotNotifyCounter(sampleEntry, Lease.FOREVER,
                space);

        /*
         * init 5 RemoteEvent counters with different lease times
         * to use with non null transaction parameter
         */
        ncs[5] = new NotifyCounter(sampleEntry, leaseTime1);
        ncs[6] = new NotifyCounter(sampleEntry, leaseTime2);
        ncs[7] = new NotifyCounter(sampleEntry, leaseTime3);
        ncs[8] = new NotifyCounter(sampleEntry, leaseForeverTime);
        ncs[9] = new NotifyCounter(sampleEntry, Lease.FOREVER);

        /*
         * init 5 RemoteEvent counters with different lease times
         * and snapshot to use with non null transaction parameter
         */
        snsh_ncs[5] = new SnapshotNotifyCounter(sampleEntry, leaseTime1,
                space);
        snsh_ncs[6] = new SnapshotNotifyCounter(sampleEntry, leaseTime2,
                space);
        snsh_ncs[7] = new SnapshotNotifyCounter(sampleEntry, leaseTime3,
                space);
        snsh_ncs[8] = new SnapshotNotifyCounter(sampleEntry,
                leaseForeverTime, space);
        snsh_ncs[9] = new SnapshotNotifyCounter(sampleEntry, Lease.FOREVER,
                space);

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

        // create the non null transaction with finite lease time
        txn = getTransaction(txnLeaseTime);

        // now register all counters with non null transaction parameter
        for (i = 5; i < 10; 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);
        }

        // write sample entry using it's snapshot twice
        space.write(snapshot, null, leaseForeverTime);
        space.write(snapshot, null, leaseForeverTime);

        // sleep for a while to let some listeners expire
        Thread.sleep(timeout2 + instantTime);
        logDebugText("now sleeping for " + (timeout2 + instantTime)
                + " to to let some listeners expire...");

        // write sample entry using it's snapshot twice again
        space.write(snapshot, null, leaseForeverTime);
        space.write(snapshot, null, leaseForeverTime);

        // sleep again for a while to let transaction expires
        Thread.sleep(timeout1);
        logDebugText("now sleeping for " + timeout1
                + " to let to let transaction expires...");

        // write sample entry using it's snapshot twice again
        space.write(snapshot, null, leaseForeverTime);
        space.write(snapshot, null, leaseForeverTime);

        // sleep again for a while to let some listeners expire
        Thread.sleep(timeout2 - timeout1);
        logDebugText("now sleeping for " + (timeout2 - timeout1)
                + " to to let some listeners expire...");

        // write sample entry using it's snapshot twice again
        space.write(snapshot, null, leaseForeverTime);
        space.write(snapshot, null, leaseForeverTime);

        // sleep again for a while to let some listeners expire
        Thread.sleep(timeout2);
        logDebugText("now sleeping for " + timeout2
                + " to to let some listeners expire...");

        // write sample entry using it's snapshot twice again
        space.write(snapshot, null, leaseForeverTime);
        space.write(snapshot, null, leaseForeverTime);

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

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

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

        for (i = 0; i < 10; i++) {
            if (failMatrix[i]) {
                logDebugText("FAILED: " + ncs[i] + " has got "
                        + ncs[i].getEventsNum(ers[i])
                        + " notifications instead of " + evTxnMatrix[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 " + evTxnMatrix[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");

        // check: we fail of pass
        if (failed) {
            throw new TestException(
                    "Not all listeners've got expected number of events.");
        }
    }
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.