Package com.sun.jini.qa.harness

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


        Lease lease2 = null;
        Transaction txn;

        // 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 with different
         * finite lease times into the space within the transaction
         */
        lease1 = space.write(sampleEntry1, txn, leaseTime1);
        lease1 = prepareLease(lease1);
        lease2 = space.write(sampleEntry2, txn, leaseTime2);
        lease2 = prepareLease(lease2);

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed write of " + sampleEntry1 + " with "
                    + leaseTime1 + " lease time within the non null"
                    + " transaction returned null lease.");
        }

        if (lease2 == null) {
            throw new TestException(
                    "performed write of " + sampleEntry2 + " with "
                    + leaseTime2 + " lease time within the non null"
                    + " transaction returned null lease.");
        }

        /*
         * check that written entries are available in the space
         * within the transaction
         */
        result = (SimpleEntry) space.readIfExists(sampleEntry1, txn,
          JavaSpace.NO_WAIT);

        if (result == null) {
            throw new TestException(
                    "performed write of " + sampleEntry1 + " with "
                    + leaseTime1 + " lease time within the non null"
                    + " transaction, written entry is not available"
                    + " in the space.");
        }
        result = (SimpleEntry) space.readIfExists(sampleEntry2, txn,
          JavaSpace.NO_WAIT);

        if (result == null) {
            throw new TestException(
                    "performed write of " + sampleEntry2 + " with "
                    + leaseTime2 + " lease time within the non null"
                    + " transaction, written entry is not available"
                    + " in the space.");
        }
        logDebugText(sampleEntry1.toString() + " with " + leaseTime1
                + " lease time and " + sampleEntry2 + " with " + leaseTime2
                + " lease time has been successfully written to the space"
                + " within the non null transaction.");

        // sleep to let 1-st lease expires
        logDebugText("Sleeping for " + (leaseTime1 + instantTime) + " ...");
        Thread.sleep(leaseTime1 + instantTime);
        logDebugText("awakening...");

        /*
         * check that 1-st entry is not available in the space
         * within the transaction
         */
        result = (SimpleEntry) space.readIfExists(sampleEntry1, txn,
          JavaSpace.NO_WAIT);

        if (result != null) {
            throw new TestException(
                    "performed write within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime1
                    + " lease time still available in the"
                    + " space after expiration time.");
        }
        logDebugText("Expiration for written " + sampleEntry1 + " with "
                + leaseTime1 + " lease time within the non null transaction"
                + " works as expected.");

        /*
         * check that 2-nd entry is still available in the space
         * within the transaction
         */
        result = (SimpleEntry) space.readIfExists(sampleEntry2, txn,
          JavaSpace.NO_WAIT);

        if (result == null) {
            throw new TestException(
                    "performed write within the non null transaction of "
                    + sampleEntry2 + " with " + leaseTime2
                    + " lease time is not available in the space after "
                    + leaseTime1 + " ms.");
        }

        // sleep to let 2-nd lease expires
        logDebugText("Sleeping for " + (leaseTime2 - leaseTime1) + " ...");
        Thread.sleep(leaseTime2 - leaseTime1);
        logDebugText("awakening...");

        /*
         * check that 2-nd entry is not available in the space
         * within the transaction
         */
        result = (SimpleEntry) space.readIfExists(sampleEntry1, null,
          JavaSpace.NO_WAIT);

        if (result != null) {
            throw new TestException(
                    "performed write within the non null transaction of "
                    + sampleEntry2 + " with " + leaseTime2
                    + " lease time still available in the"
                    + " space after expiration time.");
        }
        logDebugText("Expiration for written " + sampleEntry2 + " with "
                + leaseTime2 + " lease time within the non null transaction"
                + " works as expected.");

        /*
         * write 1-st entry twice with different finite lease times
         * within the non null transaction
         */
        lease1 = space.write(sampleEntry1, txn, leaseTime1);
        lease1 = prepareLease(lease1);
        lease2 = space.write(sampleEntry1, txn, leaseTime2);
        lease2 = prepareLease(lease2);

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed write within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime1
                    + " lease time returned null lease.");
        }

        if (lease2 == null) {
            throw new TestException(
                    "performed write within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime2
                    + " lease time returned null lease.");
        }
        logDebugText(sampleEntry1.toString() + " with " + leaseTime1
                + " and " + leaseTime2 + " lease times within the non null"
                + " transaction have been successfully written"
                + " to the space.");

        // sleep to let 1-st lease expires
        logDebugText("Sleeping for " + (leaseTime1 + instantTime) + " ...");
        Thread.sleep(leaseTime1 + instantTime);
        logDebugText("awakening...");

        /*
         * check that only one of the 1-st entries
         * is available in the space within the transaction
         */
        result = (SimpleEntry) space.takeIfExists(sampleEntry1, txn,
          JavaSpace.NO_WAIT);

        if (result == null) {
            throw new TestException(
                    "performed 2 writes within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime1 + " and "
                    + leaseTime2 + " lease times"
                    + ", there are no entries available in the space"
                    + " after " + leaseTime1 + " ms, while 1 is expected.");
        }
        result = (SimpleEntry) space.takeIfExists(sampleEntry1, txn,
          JavaSpace.NO_WAIT);

        if (result != null) {
            throw new TestException(
                    "performed 2 writes within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime1 + " and "
                    + leaseTime2 + " lease times"
                    + ", there are 2 entries available in the space"
                    + " after " + leaseTime1 + " ms, while 1 is expected.");
        }
        logDebugText("Expiration for written " + sampleEntry1 + " with "
                + leaseTime1 + " lease time within the non null transaction"
                + " works as expected.");

        /*
         * write 1-st entry twice with different finite lease times
         * within the non null transaction again
         */
        lease1 = space.write(sampleEntry1, txn, leaseTime1);
        lease1 = prepareLease(lease1);
        lease2 = space.write(sampleEntry1, txn, leaseTime2);
        lease2 = prepareLease(lease2);

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed write within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime1
                    + " lease time returned null lease.");
        }

        if (lease2 == null) {
            throw new TestException(
                    "performed write within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime2
                    + " lease time returned null lease.");
        }
        logDebugText(sampleEntry1.toString() + " with " + leaseTime1
                + " and " + leaseTime2 + " lease times within the non null"
                + " transaction have been successfully written"
                + " to the space.");

        // sleep to let 2-nd lease expires
        logDebugText("Sleeping for " + (leaseTime2 + instantTime) + " ...");
        Thread.sleep(leaseTime2 + instantTime);
        logDebugText("awakening...");

        /*
         * check that there are no entries available
         * in the space within the transaction
         */
        result = (SimpleEntry) space.readIfExists(sampleEntry1, txn,
          JavaSpace.NO_WAIT);

        if (result != null) {
            throw new TestException(
                    "performed 2 writes within the non null transaction of "
                    + sampleEntry1 + " with " + leaseTime1 + " and "
                    + leaseTime2 + " lease times"
                    + ", there are at lease 1 entry still available in"
                    + " the space after " + leaseTime2
View Full Code Here


         * service(s) for the desired services
         */
        ServiceItem srvcItem = srvcDiscoveryMgr.lookup(template,
                                                       firstStageFilter);
        if(srvcItem == null) {
            throw new TestException(" -- service returned is null");
        } else if(srvcItem.service == null) {
            throw new TestException(" -- service component of "
                              +"returned service is null");
        } else {
            for(int i=0;i<expectedServiceList.size();i++) {
                if((srvcItem.service).equals(expectedServiceList.get(i))) {
              return;//passed
                }//endif
            }//end loop (i)
            displaySrvcInfoOnFailure(srvcItem,expectedServiceList);
            throw new TestException(" -- returned service item "
            +" is not equivalent to any of the "
            +"service(s) registered with lookup");
        }//endif
    }//end applyTestDef
View Full Code Here

  Lease[] leases = set.getLeases();
  if (leases.length != 6) {
      String message = "After set lease expiration, the set " +
    "contains " + leases.length + " leases, but " +
    "is expected to contain exactly 6.";
      throw new TestException(message);
  }

  // assert that they are the leases we expect
  for (int i = 0; i < 3; ++i) {
      int leaseIndex = rstUtil.indexOfLease(exactLease[i], leases);
      if (leaseIndex < 0) {
    String message = "Exact owner lease #" + i +
        " has expired unexpectedly.";
    throw new TestException(message);
      }

      leaseIndex = rstUtil.indexOfLease(longLease[i], leases);
      if (leaseIndex < 0) {
    String message = "Long owner lease #" + i +
        " has expired unexpectedly.";
    throw new TestException(message);
      }
  }
 
  /* assert that all the last renewal request durations made on
     the shortGrantor were for less than the requested amount.
     This is because the membership duration should have run out
     approximately 2/3 of the way through the test. */
  for (int i = 0; i < 3; ++i) { 
      if (shortGrantor[i].durationRequestIsSmallerThan() == false) {
    String message = "The LRS did not respect the " +
        "membership duration value when requesting a client " +
        "lease renewal";
    throw new TestException(message);
      }
  }
 
  /* assert that all the last renewal request durations made
     on the exactGrantor and longGrantor were for exactly
     the requested amount.  This is because the membership
     duration should have run out after the lease of the renewal
     set expires */
  for (int i = 0; i < 3; ++i) { 

      if (exactGrantor[i].hasSpecialState() == true) {
    String message = "The LRS did not request the interval " +
        "as specified by the client.\n" +
        "Detail: " + exactGrantor[i].getStateText();
    throw new TestException(message);
      }

      if (longGrantor[i].hasSpecialState() == true) {
    String message = "The LRS did not request the interval " +
        "as specified by the client.\n" +
        "Detail: " + longGrantor[i].getStateText();
    throw new TestException(message);
      }

  }

  /* If we received any RenewalFailureEvents that would be
     an error */
  RemoteEvent[] events = rrl.getEvents();
  if (events.length != 0) {
      String message = "Listener received " + events.length +
    " events but is required to receive exactly 0.\n" +
    "This indicates that LRS did not respect the renewal" +
    " duration given by the short grantor.";
      throw new TestException(message);
  }
    }
View Full Code Here

        Lease lease2 = null;
        Transaction txn;

        // 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 an entry with Lease.ANY lease time within the transaction
        try {
            lease1 = space.write(sampleEntry1, txn, Lease.ANY);
        } catch (IllegalArgumentException iae) {
            throw new TestException(
                    "IllegalArgumentException was thrown while trying to"
                    + " write " + sampleEntry1 + " with Lease.ANY value for"
                    + " lease time within the transaction.");
        }
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();

        /*
         * check that returned lease is not equal to null,
         * expiration time is not less then current time
         */
        if (lease1 == null) {
            throw new TestException(
                    "performed write with Lease.ANY lease time within the"
                    + " non null transaction, expected result is non null"
                    + " lease but null has been returned.");
        }
        expirTime1 = lease1.getExpiration();

        if (expirTime1 < curTime1) {
            throw new TestException(
                    "performed write of " + sampleEntry1
                    + " with Lease.ANY lease time within the non null"
                    + " transaction, expected"
                    + " expiration time is greater then current time "
                    + curTime1 + " but returned value is " + expirTime1);
        }
        logDebugText("Write operation of " + sampleEntry1
                + " with Lease.ANY value for lease time within the"
                + " transaction works as expected.");

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

        /*
         * write an entry with Lease.FOREVER lease time
         * within the transaction
         */
        try {
            lease1 = space.write(sampleEntry1, txn, Lease.FOREVER);
        } catch (IllegalArgumentException iae) {
            throw new TestException(
                    "IllegalArgumentException was thrown while trying to"
                    + " write " + sampleEntry1
                    + " within the non null transaction with Lease.FOREVER"
                    + " value for lease time.");
        }
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();

        /*
         * check that returned lease is not equal to null,
         * expiration time is not less then current time
         */
        if (lease1 == null) {
            throw new TestException(
                    "performed write with Lease.FOREVER lease time within"
                    + " the non null transaction, expected result is non"
                    + " null lease but null has been returned.");
        }
        expirTime1 = lease1.getExpiration();

        if (expirTime1 < curTime1) {
            throw new TestException(
                    "performed write of " + sampleEntry1
                    + " with Lease.FOREVER lease time within the non null"
                    + " transaction, expected"
                    + " expiration time is greater then current time "
                    + curTime1 + " but returned value is " + expirTime1);
        }
        logDebugText("Write operation of " + sampleEntry1
                + " with Lease.FOREVER value for lease time within the non"
                + " null transaction works as expected.");

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

        /*
         * write two sample entries with different
         * finite lease times into the space within the transaction.
         */
        lease1 = space.write(sampleEntry1, txn, leaseTime1);
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();
        expirTime1 = lease1.getExpiration();
        lease2 = space.write(sampleEntry2, txn, leaseTime2);
  lease2 = prepareLease(lease2);
        curTime2 = System.currentTimeMillis();
        expirTime2 = lease2.getExpiration();

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed write of " + sampleEntry1 + " with "
                    + leaseTime1 + " lease time within the non null"
                    + " transaction returned null lease.");
        }

        if (lease2 == null) {
            throw new TestException(
                    "performed write of " + sampleEntry2 + " with "
                    + leaseTime2 + " lease time within the non null"
                    + " transaction returned null lease.");
        }

        // check that write operations return required expiration times
        if (((expirTime1 - curTime1) > leaseTime1)
                || (expirTime1 - curTime1) < (leaseTime1 - instantTime)) {
            throw new TestException(
                    "performed write of " + sampleEntry1 + " with "
                    + leaseTime1 + " lease time within the non null "
                    + "transaction. Expected conditions are not satisfied: "
                    + leaseTime1 + "(specified lease time) <= ("
                    + expirTime1 + "(returned expiration time) - "
                    + curTime1 + "(current time)) >= (" + leaseTime1
                    + "(specified lease time) + " + instantTime + ").");
        }

        if (((expirTime2 - curTime2) > leaseTime2)
                || (expirTime2 - curTime2) < (leaseTime2 - instantTime)) {
            throw new TestException(
                    "performed write of " + sampleEntry2 + " with "
                    + leaseTime2 + " lease time within the non null "
                    + "transaction. Expected conditions are not satisfied: "
                    + leaseTime2 + "(specified lease time) <= ("
                    + expirTime2 + "(returned expiration time) - "
                    + curTime2 + "(current time)) >= (" + leaseTime2
                    + "(specified lease time) + " + instantTime + ").");
        }
        logDebugText("Write operations within the non null tranasction of "
                + sampleEntry1 + " with " + leaseTime1 + " lease time and\n"
                + sampleEntry2 + " with " + leaseTime2
                + " lease time work as expected.");

        /*
         * write 1-st sample entry with another finite lease time
         * to the space within the transaction again
         */
        lease1 = space.write(sampleEntry1, txn, leaseTime3);
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();
        expirTime1 = lease1.getExpiration();

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed 2-nd write of " + sampleEntry1 + " with "
                    + leaseTime3 + " lease time within the non null"
                    + " tranasaction returned null result.");
        }

        // check that write operations return required expiration times
        if (((expirTime1 - curTime1) > leaseTime3)
                || (expirTime1 - curTime1) < (leaseTime3 - instantTime)) {
            throw new TestException(
                    "performed 2-nd write of " + sampleEntry1 + " with "
                    + leaseTime3 + " lease time within the non null "
                    + "transaction. Expected conditions are not satisfied: "
                    + leaseTime3 + "(specified lease time) <= ("
                    + expirTime1 + "(returned expiration time) - "
                    + curTime1 + "(current time)) >= (" + leaseTime3
                    + "(specified lease time) + " + instantTime + ").");
        }
        logDebugText("2-nd write operation of " + sampleEntry1 + " with "
                + leaseTime3 + " lease time within the non null transaction"
                + " works as expected.");

        /*
         * write 2-nd sample entry with Lease.ANY value for lease time
         * to the space within the transaction again
         */
        lease2 = space.write(sampleEntry2, txn, Lease.ANY);
  lease2 = prepareLease(lease2);
        curTime2 = System.currentTimeMillis();
        expirTime2 = lease2.getExpiration();

        // check that returned leases are not equal to null
        if (lease2 == null) {
            throw new TestException(
                    "performed 2-nd write of " + sampleEntry2
                    + " with Lease.ANY value for lease time within the non"
                    + " null transaction returned null lease.");
        }

        // check that expiration time is not less then current time
        if (expirTime2 < curTime2) {
            throw new TestException(
                    "performed 2-nd write of " + sampleEntry2
                    + " with Lease.ANY lease time within the non null"
                    + " transaction, expected"
                    + " expiration time is greater then current time "
                    + curTime2 + " but returned value is " + expirTime2);
        }
        logDebugText("2-nd write operation of " + sampleEntry2
                + " with Lease.ANY value for lease time within the non null"
                + " transaction works as expected.");

        /*
         * write 1-st sample entry with Lease.FOREVER value for lease time
         * to the space within the transaction again
         */
        lease1 = space.write(sampleEntry1, txn, Lease.FOREVER);
  lease1 = prepareLease(lease1);
        curTime1 = System.currentTimeMillis();
        expirTime1 = lease1.getExpiration();

        // check that returned leases are not equal to null
        if (lease1 == null) {
            throw new TestException(
                    "performed 3-rd write of " + sampleEntry1
                    + " with Lease.FOREVER value for lease time within the"
                    + " non null transaction returned null lease.");
        }

        // check that expiration time is not less then current time
        if (expirTime1 < curTime1) {
            throw new TestException(
                    "performed 3-rd write of " + sampleEntry1
                    + " with Lease.FOREVER lease time within the non null"
                    + " transaction, expected"
                    + " expiration time is greater then current time "
                    + curTime1 + " but returned value is " + expirTime1);
View Full Code Here

            long actualBlockTime = endTime-startTime;
            long waitError = (actualBlockTime-waitDur)/1000;
            if(expectedService == null) {//block full amount and return null
                /* Blocking time should be within epsilon of full amount */
                if(waitError<-3) {
                   throw new TestException(" -- failed to block requested "
                                     +"time -- requested block = "
                                     +waitDurSecs+" second(s), actual "
                                     +"block = "+(actualBlockTime/1000)
                                     +" second(s)");
                } else if(waitError>30) {
                    throw new TestException(" -- exceeded requested block "
                                      +"time -- requested block = "
                                      +waitDurSecs+" second(s), actual "
                                      +"block = "+(actualBlockTime/1000)
                                      +" second(s)");
                }//endif
                /* ServiceItem should be null since rejected by filter */
                if(srvcItem != null) {
                    throw new TestException(" -- unexpected non-null service item"
                                     +"returned on lookup of test service "+i);
                } else {
                    logger.log(Level.FINE, "  OK -- both null as expected");
                }
            } else { //(expectedService != null) -- block less than full amount
                /* Blocking time should be less than the full amount */
                if(waitError >= 0) {
                    throw new TestException(" -- blocked longer than expected "
                                      +"-- requested block = "
                                      +waitDurSecs+" second(s), actual "
                                      +"block = "+(actualBlockTime/1000)
                                      +" second(s)");
                }
                /* Correct non-null ServiceItem should have been returned */
                if(srvcItem == null) {
                    throw new TestException(" -- unexpected null service item "
                                      +"returned on lookup of test service");
                } else if(srvcItem.service == null) {
                    throw new TestException(" -- null service component returned "
                                      +"on lookup of test service ");
                } else {
                    if(nAttrs > 0) {
                        /* less restrictive tmpl could return any service */
                        for(int j=0;j<expectedServiceList.size();j++) {
                            if((srvcItem.service).equals
                                                (expectedServiceList.get(j)))
                            {
                                logger.log(Level.FINE, "expected "
                                              +"service found -- requested "
                                              +"block = "+waitDurSecs
                                              +" second(s), actual block = "
                                              +(actualBlockTime/1000)
                                              +" second(s)");
                          return;// passed
                            }//endif
                        }//end loop (i)
                    } else {//(nAttrs<=0 )
                        /* more restrictive tmpl returns particular service */
                        if( !(srvcItem.service).equals(expectedService) ) {
                            logger.log(Level.FINE, "  FAILURE -- "
                                +"expectedService.i = "+expectedService.i+", "
                                +"(srvcItem.service).i = "
                                +((TestService)(srvcItem.service)).i);
                            throw new TestException(" -- filter failed -- service "
                                          +"returned from lookup not "
                                          +"equivalent to expected test "
                                          +"service "+i);
                        } else {
                            logger.log(Level.FINE, "  OK -- "
View Full Code Here

                   waitDur);
  long endTime = System.currentTimeMillis();
  long actualBlockTime = endTime-startTime;
  long waitError = (actualBlockTime-waitDur)/1000;
  if(srvcItem == null) {
      throw new TestException(" -- service returned is null");
  } else if(srvcItem.service == null) {
      throw new TestException(" -- service component of "
            +"returned service is null");
  } else {
      boolean srvcOK = false;
      for(int i=0;i<expectedServiceList.size();i++) {
    if((srvcItem.service).equals(expectedServiceList.get(i))) {
        srvcOK = true;
        break;
    }//endif
      }//end loop (i)
      if(!srvcOK) {
    displaySrvcInfoOnFailure(srvcItem,expectedServiceList);
    throw new TestException(" -- returned service item is not "
          +"equivalent to any expected service");
      }//endif
  }//endif
  /* Test that the call did not block */
  if(actualBlockTime > maxActualBlock) {
      throw new TestException
    (" -- blocked longer than expected (ideal = 0) "
     + "-- requested block = " + waitDur/1000 + ", max block = "
     + maxActualBlock/1000 +" second(s), actual "
     + "block = "+ (actualBlockTime/1000)
     + " second(s)");
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);

        /*
         * takeIfExists 1-st entry twice from the space using
         * 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,
                    true);

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

        /*
         * TakeIfExists entry from the space using 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, true);

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

        /*
         * TakeIfExists entry from the space using 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,
                    true);

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

        /*
         * TakeIfExists entry from the space using 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,
                    true);

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

        /*
         * TakeIfExists entry from the space using 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,
                    true);

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

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

         */
        ServiceItem[] srvcItems = srvcDiscoveryMgr.lookup(template,
                                                          nServices,
                                                          firstStageFilter);
        if(srvcItems == null) {
            throw new TestException
    (" -- array of service items returned is null");
        } else if( srvcItems.length != expectedServiceList.size() ) {
            logger.log(Level.FINE, "number of service items "
                              +"returned ("+srvcItems.length+") != "
                              +"expected number of service items ("
                              +expectedServiceList.size()+")");
            for(int i=0;i<srvcItems.length;i++) {
                logger.log(Level.FINE, "  service["+i+"] = "
                                  +srvcItems[i].service);
            }//end loop
            throw new TestException(" -- number of service items returned ("
            +srvcItems.length+") != expected number "
            +"of service items ("
            +expectedServiceList.size()+")");
        } else {/* Compare the returned array to set of expected services */
      label_i:
            for(int i=0;i<srvcItems.length;i++) {
                logger.log(Level.FINE, "comparing sevice item "+i);
                if( srvcItems[i] == null ) {
                    throw new TestException(" -- returned service item "+i
              +" is null");
                } else if(srvcItems[i].service == null) {
                    throw new TestException(" -- service component of "
              +"returned service item "+i
              +" is null");
                } else {
                    for(int j=0;j<expectedServiceList.size();j++) {
                        if( (srvcItems[i].service).equals
                                               (expectedServiceList.get(j)) )
                        {
                            continue label_i; // next srvcItems[i]
                        }//endif
                    }//end loop (j)
                    throw new TestException(" -- returned service item "+i
              +" is not contained in the "
              +" expected set of services");
                }//endif
            }//end loop (i)
        }//endif
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 the non null transaction
        txn = getTransaction();

        /*
         * write 1-st entry with Lease.FOREVER lease time to the space
         * within the transaction
         */
        space.write(sampleEntry1, 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 "
                    + 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 within the non null transaction.");

        /*
         * write 2-nd entry with Lease.ANY value for lease time
         * to the space within the transaction
         */
        space.write(sampleEntry2, 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 "
                    + 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 within the non null transaction.");

        /*
         * write 1-st and 2-nd entries to the space within the
         * transaction again with finite lease times
         */
        space.write(sampleEntry1, txn, leaseTime1);
        logDebugText(sampleEntry1.toString() + " with " + leaseTime1
                + " has been successfully written again to the space"
                + " within the non null transaction.");
        space.write(sampleEntry2, txn, leaseTime2);
        logDebugText(sampleEntry2.toString() + " with " + leaseTime2
                + " has been successfully written again to the space"
                + " 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

        Transaction txn;
        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, Lease.FOREVER,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, Lease.FOREVER,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, Lease.FOREVER,
                space);

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

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

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

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

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

        // init counter with null entry as a template and it's snapshot
        snsh_ncs[8] = new SnapshotNotifyCounter(null, Lease.FOREVER, 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.FOREVER,
                space);

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

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // now register all counters within the transaction
        for (i = 0; i < 12; i++) {
            snsh_ers[i] = space.notify(snsh_ncs[i].getTemplate(), 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.FOREVER);
        ncs[1] = new NotifyCounter(sampleEntry2, Lease.FOREVER);
        ncs[2] = new NotifyCounter(sampleEntry3, Lease.FOREVER);
        snsh_ncs[0] = new SnapshotNotifyCounter(sampleEntry1, Lease.FOREVER,
                space);
        snsh_ncs[1] = new SnapshotNotifyCounter(sampleEntry2, Lease.FOREVER,
                space);
        snsh_ncs[2] = new SnapshotNotifyCounter(sampleEntry3, Lease.FOREVER,
                space);

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

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

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

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

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

        // init counter with null entry as a template and it's snapshot
        ncs[8] = new NotifyCounter(null, Lease.FOREVER);
        snsh_ncs[8] = new SnapshotNotifyCounter(null, Lease.FOREVER, 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.FOREVER);
        snsh_ncs[9] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

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

        // 3-rd template and it's snapshot
        template = new SimpleEntry(null, null);
        ncs[11] = new NotifyCounter(template, Lease.FOREVER);
        snsh_ncs[11] = new SnapshotNotifyCounter(template, Lease.FOREVER,
                space);

        // now register all counters within the transaction
        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].getTemplate(), 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

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.