You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by pg...@apache.org on 2002/10/14 08:44:22 UTC

cvs commit: jakarta-james/src/java/org/apache/james/testing BaseTest.java EndToEnd.java Main.java MultiThreadDeliveryPounder.java POP3Hammering.java POP3Test.java SMTPDeliveryWorker.java TestMethod.java

pgoldstein    2002/10/13 23:44:22

  Modified:    src/java/org/apache/james/testing BaseTest.java
                        EndToEnd.java Main.java
                        MultiThreadDeliveryPounder.java POP3Hammering.java
                        POP3Test.java SMTPDeliveryWorker.java
                        TestMethod.java
  Log:
  Added a number of comments.
  Corrected a minor bug in the TestMethod code where the time taken was not summed over all attemtps.
  
  Revision  Changes    Path
  1.2       +31 -6     jakarta-james/src/java/org/apache/james/testing/BaseTest.java
  
  Index: BaseTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/BaseTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseTest.java	12 Oct 2002 19:35:18 -0000	1.1
  +++ BaseTest.java	14 Oct 2002 06:44:22 -0000	1.2
  @@ -13,38 +13,63 @@
   import org.apache.avalon.framework.configuration.ConfigurationException;
   
   /**
  - * Base Test class. Can run a set of tests.
  + * Base Test class. Can run a set of method tests.
    */
   public class BaseTest extends TestCase implements Configurable {
   
  +    /**
  +     * The method level test cases to be invoked by this test.
  +     */
       private TestMethod[] testMethod;
  +
  +    /**
  +     * Whether the statistics for each test should be printed.
  +     */
       private boolean showStat;
   
  +    /**
  +     * Sole constructor for the method.
  +     *
  +     * @param name the name of the test case.
  +     */
       public BaseTest(String name) {
           super(name);
       }
   
  +    /**
  +     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
  +     */
       public void configure(Configuration configuration) 
  -        throws ConfigurationException 
  -    {
  +        throws ConfigurationException {
           // list of test methods
           Configuration testseq = configuration.getChild("testsequence");
  -        showStat = testseq.getAttributeAsBoolean("showStat");
  +        showStat = testseq.getAttributeAsBoolean("showStat", true);
           Configuration[] testconf = testseq.getChildren("testmethod");
           testMethod = new TestMethod[testconf.length];
  -        for ( int i = 0 ; i < testMethod.length ; i++ )
  +        for ( int i = 0 ; i < testMethod.length ; i++ ) {
               testMethod[i] = new TestMethod(testconf[i].getValue());
  +        }
       }
   
  +    /**
  +     * Lists the number of test cases to be invoked by this test
  +     *
  +     * @return the number of test cases
  +     */
       public final int countTestCases() {
           return testMethod.length;
       }
   
  +    /**
  +     * Runs the test, invoking each element of the TestMethod array once.
  +     * Displays statistics if the showStat configuration param was true.
  +     */
       protected final void runTest() throws Throwable {
           for ( int i = 0 ; i < testMethod.length ; i++ ) {
               testMethod[i].invoke(this);
  -            if ( showStat )
  +            if ( showStat ) {
                   System.out.println("stat: "+getName()+", "+testMethod[i]);
  +            }
           }
       }
   }
  
  
  
  1.2       +89 -13    jakarta-james/src/java/org/apache/james/testing/EndToEnd.java
  
  Index: EndToEnd.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/EndToEnd.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EndToEnd.java	13 Oct 2002 08:17:03 -0000	1.1
  +++ EndToEnd.java	14 Oct 2002 06:44:22 -0000	1.2
  @@ -25,31 +25,79 @@
   import org.apache.commons.net.telnet.TelnetClient;
   import examples.IOUtil;
   /**
  + * A class to do end to end load SMTP testing on James.
  + *
    * @author <A href="mailto:danny@apache.org">Danny Angus</a>
    * 
    * $Id$
    */
   public class EndToEnd extends TestCase {
  +
       /**
  -     * Constructor for RemoteManagerEndToEnd.
  -     * @param arg0
  +     * The number of worker threads this test invokes
  +     */
  +    private int numWorkers = 10;
  +
  +    /**
  +     * The size of messages generated by this test case.
  +     */
  +    private int messageSize =  1024*10;
  +
  +    /**
  +     * The number of still-active worker threads.
  +     */
  +    private int workingWorkers;
  +
  +    /**
  +     * The start time for this test case.
        */
  -    private int numworkers = 10;
  -    private int messagesize =  1024*10;
  -    private int workingworkers;
       private Date start;
  +
  +    /**
  +     * A set of commands to issue to the James RemoteManager interface
  +     * to begin the test.
  +     */
       private String[] script1 =
           { "root", "root", "help", "adduser test test", "listusers", "quit" };
  +
  +    /**
  +     * A set of commands to issue to the James RemoteManager interface
  +     * to clean up after the test.
  +     */
       private String[] script2 =
           { "root", "root", "listusers", "deluser test", "listusers", "quit" };
  +
  +    /**
  +     * Whether all the worker threads have finished.
  +     */
       private boolean finished = false;
  +
  +    /**
  +     * The number of emails delivered as part of this EndToEnd test case.
  +     */
       private int delivered = 0;
  +
  +    /**
  +     * Constructor for RemoteManagerEndToEnd.
  +     * @param arg0
  +     */
       public EndToEnd(String arg0) {
           super(arg0);
       }
  +
  +    /**
  +     * Main method used to invoke this test case..
  +     *
  +     * @param args Ignored
  +     */
       public static void main(String[] args) {
           junit.textui.TestRunner.run(EndToEnd.class);
       }
  +
  +    /**
  +     * Run the full end to end test, doing the James setup and teardown
  +     * as well as the mail transmission.
  +     */
       public void testEndToEnd() {
           TelnetClient client = new TelnetClient();
           BufferedReader in;
  @@ -77,8 +125,17 @@
               assertTrue(false);
           }
       }
  +
       private void echo(OutputStreamWriter out) {
       }
  +
  +    /**
  +     * Helper method to print data from the input reader into a
  +     * String.
  +     *
  +     * @param in the Reader that serves as the source of data
  +     * @param output This param is unused.  Why is it here?
  +     */
       private String print(BufferedReader in, OutputStream output) {
           String outString = "";
           try {
  @@ -94,16 +151,21 @@
           System.out.println(outString);
           return outString + "==";
       }
  +
  +    /**
  +     * Carries out the "mail" aspects of the tests, spawning the appropriate
  +     * worker threads.
  +     */
       private void mailTest() {
           start = new Date();
           StringBuffer mail1 = new StringBuffer();
           mail1.append(
               "Subject: test\nFrom: postmaster@localhost\nTo: test@localhost\n\nTHIS IS A TEST");
  -        for (int kb = 0; kb < messagesize; kb++) {
  +        for (int kb = 0; kb < messageSize; kb++) {
               mail1.append("m");
           }
           String mail = mail1.toString();
  -        SMTPDeliveryWorker[] workers = new SMTPDeliveryWorker[numworkers];
  +        SMTPDeliveryWorker[] workers = new SMTPDeliveryWorker[numWorkers];
           Thread[] threads = new Thread[workers.length];
           for (int i = 0; i < workers.length; i++) {
               workers[i] = new SMTPDeliveryWorker(new SMTPClient(), mail, this);
  @@ -113,9 +175,11 @@
           for (int i = 0; i < workers.length; i++) {
               System.out.println("starting worker:" + i);
               ((Thread) threads[i]).start();
  -            workingworkers++;
  +            workingWorkers++;
           }
           while (!finished) {
  +            // TODO: Shouldn't this busy loop be replaced with an
  +            //       appropriate timed wait?
           }
           try {
               POP3Client pclient = new POP3Client();
  @@ -129,22 +193,34 @@
               pclient.disconnect();
               System.out.println(pclient.getReplyString());
           } catch (SocketException e) {
  +            //TODO: This should be recorded
           } catch (IOException e) {
  +            //TODO: This should be recorded
           }
           long time = (new Date()).getTime() - start.getTime();
           System.err.println("time total " + (int) time);
       }
  +
  +    /**
  +     * Record that a particular worker thread has finished.
  +     *
  +     * @param workerid the id number of the thread that has finished.
  +     */
       public void finished(int workerid) {
  -        workingworkers--;
  -        System.out.println("workers still working.." + workingworkers);
  -        if (workingworkers == 0) {
  +        workingWorkers--;
  +        System.out.println("workers still working.." + workingWorkers);
  +        if (workingWorkers == 0) {
               long time = (new Date()).getTime() - start.getTime();
               System.err.println("time to deliver set " + (int) (time/1000));
               //System.err.println("messages per second " + (int)(1000/(time/1000)));
  -            //System.err.println("data rate="+((messagesize*1000)/(time/1000)));
  +            //System.err.println("data rate="+((messageSize*1000)/(time/1000)));
               finished = true;
           }
       }
  +
  +    /**
  +     * Prints out the number of delivered emails.
  +     */
       public void delivered() {
           System.out.println("-" + (++delivered));
       }
  
  
  
  1.2       +12 -2     jakarta-james/src/java/org/apache/james/testing/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/Main.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Main.java	12 Oct 2002 19:35:18 -0000	1.1
  +++ Main.java	14 Oct 2002 06:44:22 -0000	1.2
  @@ -20,6 +20,14 @@
    * - initiates tests, reports result.
    */
   public class Main {
  +
  +    /**
  +     * Main method used to invoke tests.  Sole argument should be
  +     * a configuration file with test suite configuration.
  +     *
  +     * @param args Sole argument should be a configuration file
  +     *             with test suite configuration
  +     */
       public static void main(String[] args) throws Exception {
           System.out.println("Usage java org.apache.james.testing.Main <testconfigfile>");
   
  @@ -38,11 +46,13 @@
               Class clazz = Class.forName(clsname);
               Constructor cstr = clazz.getConstructor(new Class[] { String.class });
               Test test = (Test)cstr.newInstance(new Object[] {name});
  -            if ( test instanceof Configurable )
  +            if ( test instanceof Configurable ) {
                   ((Configurable)test).configure(conf);
  +            }
   
  -            if (repetition > 1)
  +            if (repetition > 1) {
                   test = new RepeatedTest(test,repetition);
  +            }
   
               if ( async ) {
                   TestSuite ts = new ActiveTestSuite();
  
  
  
  1.5       +31 -1     jakarta-james/src/java/org/apache/james/testing/MultiThreadDeliveryPounder.java
  
  Index: MultiThreadDeliveryPounder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/MultiThreadDeliveryPounder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MultiThreadDeliveryPounder.java	7 Aug 2002 23:27:42 -0000	1.4
  +++ MultiThreadDeliveryPounder.java	14 Oct 2002 06:44:22 -0000	1.5
  @@ -23,11 +23,29 @@
    * @author Serge Knystautas <se...@lokitech.com>
    */
   public class MultiThreadDeliveryPounder extends Thread {
  +
  +    /**
  +     * The number of loops to be executed by the thread.
  +     */
       int loops = 0;
  +
  +    /**
  +     * The user to whom emails will be sent.
  +     */
       String user = null;
  -    Properties prop = new Properties();
  +
  +    /**
  +     * The prefix for the test message body.  The body will correspond
  +     * to this string with a number appended.
  +     */
       private static final String body = "Test message number: ";
   
  +    /**
  +     * Sole constructor for this class.
  +     *
  +     * @param loops the number of loops the thread should execute.
  +     * @param user the user to whom the emails will be sent.
  +     */
       public MultiThreadDeliveryPounder(int loops, String user) {
           this.loops = loops;
           this.user = user;
  @@ -35,8 +53,12 @@
           start();
       }
   
  +    /**
  +     * Executes a fixed number of loops, emailing the user each loop.
  +     */
       public void run() {
           try {
  +            Properties prop = new Properties();
               Session session = Session.getDefaultInstance(prop, null);
               // Transport transport = session.getTransport("smtp");
   
  @@ -62,6 +84,14 @@
           }
       }
   
  +    /**
  +     * Executes the test, creating a number of worker threads, each of whom 
  +     * will loop a fixed number of times, sending emails to the specified user
  +     * on each loop.
  +     *
  +     * @param args the number of threads, the number of loops to execute,
  +     *             the user to whom to send.
  +     */
       public static void main(String[] args) throws Throwable {
           if (args.length != 3) {
               System.err.println("Usage: ");
  
  
  
  1.4       +49 -6     jakarta-james/src/java/org/apache/james/testing/POP3Hammering.java
  
  Index: POP3Hammering.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/POP3Hammering.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- POP3Hammering.java	8 Aug 2002 00:43:53 -0000	1.3
  +++ POP3Hammering.java	14 Oct 2002 06:44:22 -0000	1.4
  @@ -20,31 +20,61 @@
    */
   public class POP3Hammering {
   
  +    /**
  +     * The POP3 host to be tested.
  +     */
       private String mailHost;
  +
  +    /**
  +     * The name of the user account being used to send and receive
  +     * the test emails.
  +     */
       private String user;
  +
  +    /**
  +     * The password of the user account being used to send the test emails.
  +     */
       private String password;
  -    private Properties prop = new Properties();
   
  -    private static final String body = "Test message number: ";
   
  -    private int iter;
  +    /**
  +     * The prefix for the test message body.  The body will correspond
  +     * to this string with a number appended.
  +     */
  +    private static final String body = "Test message number: ";
   
  +    /**
  +     * The number of the current test mail.
  +     */
  +    private int mailNumber;
  +
  +    /**
  +     * The sole constructor for this class.
  +     *
  +     * @param host the name of the mail host
  +     * @param user the user name that will be both the sender and recipient of the mails.
  +     * @param password the user password
  +     */
       public POP3Hammering(String host, String user, String password) {
           this.mailHost = host;
           this.user = user;
           this.password = password;
  -        iter = 0;
  -        prop.put("java.smtp.host", mailHost);
  +        mailNumber = 0;
       }
   
  +    /**
  +     * Sends a test mail to the user account.
  +     */
       void sendMail() {
           try {
  +            Properties prop = new Properties();
  +            prop.put("java.smtp.host", mailHost);
               Session session = Session.getDefaultInstance(prop, null);
               // Transport transport = session.getTransport("smtp");
               MimeMessage msg = new MimeMessage(session);
               msg.setFrom(new InternetAddress(user + "@localhost"));
               msg.addRecipient(Message.RecipientType.TO, new InternetAddress(user + "@localhost"));
  -            msg.setContent(body + ++iter, "text/plain");
  +            msg.setContent(body + ++mailNumber, "text/plain");
               Transport.send(msg);
               // transport.close();
               System.out.println("Sent message : " + msg.getContent() +
  @@ -56,10 +86,17 @@
           }
       }
   
  +    /**
  +     * Checks to see if an email has been received.
  +     *
  +     * @param delete whether the email is to be deleted.
  +     */
       void receiveMail(boolean delete) {
           Store store = null;
           Folder folder = null;
           try {
  +            Properties prop = new Properties();
  +            prop.put("java.smtp.host", mailHost);
               Session session = Session.getDefaultInstance(prop, null);
               store = session.getStore("pop3");
               store.connect(mailHost, user, password);
  @@ -109,6 +146,12 @@
           }
       }
   
  +    /**
  +     * Executes the body of the test, sending two mails and checking
  +     * the destination inbox to confirm that the mails were received.
  +     *
  +     * @param args the host name, user id, and password
  +     */
       public static void main(String[] args) throws Throwable {
           POP3Hammering tester = new POP3Hammering(args[0], args[1], args[2]);
           tester.sendMail();
  
  
  
  1.2       +77 -7     jakarta-james/src/java/org/apache/james/testing/POP3Test.java
  
  Index: POP3Test.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/POP3Test.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- POP3Test.java	12 Oct 2002 19:35:18 -0000	1.1
  +++ POP3Test.java	14 Oct 2002 06:44:22 -0000	1.2
  @@ -21,66 +21,136 @@
   import org.apache.james.fetchpop.ReaderInputStream;
   
   /**
  - * Fetch mail. Can be configured and extended to test specific pop3
  + * Fetch mail. Can be configured and extended to test specific POP3
    * operations.
    */
   public class POP3Test extends BaseTest {
  -    private String host, username, password;
   
  +    /**
  +     * The POP3 host to be tested.
  +     */
  +    private String host;
  +
  +    /**
  +     * The name of the user account being used to send the test emails.
  +     */
  +    private String username;
  +
  +    /**
  +     * The password of the user account being used to send the test emails.
  +     */
  +    private String password;
  +
  +    /**
  +     * Sole constructor for the test case.
  +     *
  +     * @param name the name of the test case
  +     */
       public POP3Test(String name) {
           super(name);
       }
   
  +    /**
  +     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
  +     */
       public void configure(Configuration configuration) 
  -        throws ConfigurationException 
  -    {
  +        throws ConfigurationException {
           this.host = configuration.getChild("host").getValue();
           this.username = configuration.getChild("username").getValue();
           this.password = configuration.getChild("password").getValue();
           super.configure(configuration);
       }
   
  +    /**
  +     * POP3 client that provides a simple interface to the POP3 interaction
  +     * from the client side.
  +     */
       private POP3Client client;
   
  +    /**
  +     * Sets up the test case by creating the POP3 client and connecting
  +     * to the host.
  +     */
       protected void setUp() throws Exception {
           client = new POP3Client();
           client.connect(host);
       }
   
  +    /**
  +     * Tears down the test case by disconnecting.
  +     */
       protected void tearDown() throws Exception {
           client.disconnect();
       }
   
       // ----------- pop3 operations ------------
   
  +    /**
  +     * The list of messages on the server.
  +     */
       private POP3MessageInfo[] msg;
  +
  +    /**
  +     * The number of messages retrieved
  +     */
       private static int saveMsgCounter;
   
  +    /**
  +     * Login to the POP3 server.
  +     */
       public void login() throws Exception {
           client.login(username, password);
       }
  +
  +    /**
  +     * Logout of the POP3 server.
  +     */
       public void logout() throws Exception {
           client.logout();
       }
  +
  +    /**
  +     * Fetches the list of messages from the POP3 server.
  +     */
       public void fetchMsgsInfo() throws Exception {
           msg = client.listMessages();
       }
   
  +    /**
  +     * Fetches all messages from the POP3 server.
  +     */
       public void fetchMsgs() throws Exception {
  -        for ( int i = 0 ; i < msg.length ; i++ )
  +        for ( int i = 0 ; i < msg.length ; i++ ) {
               fetchMsg(msg[i],false);
  +        }
       }
   
  +    /**
  +     * Fetches all messages from the POP3 server and saves them
  +     * to disk.
  +     */
       public void fetchAndSaveMsgs() throws Exception {
  -        for ( int i = 0 ; i < msg.length ; i++ )
  +        for ( int i = 0 ; i < msg.length ; i++ ) {
               fetchMsg(msg[i],true);
  +        }
       }
   
  +    /**
  +     * Deletes all the messages from the server.
  +     */
       public void deleteMsgs() throws Exception {
  -        for ( int i = 0 ; i < msg.length ; i++ )
  +        for ( int i = 0 ; i < msg.length ; i++ ) {
               client.deleteMessage(msg[i].number);
  +        }
       }
   
  +    /**
  +     * Fetches a message from the POP3 server and potentially saves it
  +     * to disk.
  +     *
  +     * @param msg the information for the particular message to retrieve
  +     * @param save whether the message is saved to a file.
  +     */
       private void fetchMsg(POP3MessageInfo msg,boolean save) throws Exception {
           InputStream in = new ReaderInputStream(client.retrieveMessage(msg.number));
           try {
  
  
  
  1.2       +35 -7     jakarta-james/src/java/org/apache/james/testing/SMTPDeliveryWorker.java
  
  Index: SMTPDeliveryWorker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/SMTPDeliveryWorker.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SMTPDeliveryWorker.java	13 Oct 2002 08:17:04 -0000	1.1
  +++ SMTPDeliveryWorker.java	14 Oct 2002 06:44:22 -0000	1.2
  @@ -1,30 +1,46 @@
   /**
  - * SMTPDeliveryWorker.java
  - * 
    * Copyright (C) 11-Oct-2002 The Apache Software Foundation. All rights reserved.
    *
    * This software is published under the terms of the Apache Software License
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file. 
  - *
  - * Danny Angus
    */
   package org.apache.james.testing;
   import java.io.IOException;
   import org.apache.commons.net.smtp.SMTPClient;
   /**
  + * SMTPDeliveryWorker.java
  + *
  + * A worker thread that is part of the SMTP delivery end to end testing.
  + *
    * @author <A href="mailto:danny@apache.org">Danny Angus</a>
    * 
    * $Id$
    */
   public class SMTPDeliveryWorker implements Runnable {
  +    private SMTPClient client;
  +
       /**
  -     * Constructor for SMTPDeliveryWorker.
  +     * The test of the mail message to send.
        */
  -    private SMTPClient client;
       private String mail;
  +
  +    /**
  +     * The worker id.  Primarily used for identification by the class
  +     * managing the threads.
  +     */
       private int workerid;
  +
  +    /**
  +     * The EndToEnd test case that spawned this thread.
  +     */
       EndToEnd boss;
  +
  +    /**
  +     * Constructor for SMTPDeliveryWorker.
  +     *
  +     * @param client the SMTP client being used by this test to 
  +     */
       public SMTPDeliveryWorker(SMTPClient client, String mail, EndToEnd boss) {
           this.boss = boss;
           this.client = client;
  @@ -53,9 +69,21 @@
           }
           boss.finished(workerid);
       }
  +
  +    /**
  +     * Set the worker id for this worker thread.
  +     *
  +     * @param workerid the worker thread id
  +     */
       public void setWorkerid(int workerid) {
           this.workerid = workerid;
       }
  +
  +    /**
  +     * Get the worker id for this worker thread.
  +     *
  +     * @return the worker thread id
  +     */
       public int getWorkerid() {
           return workerid;
       }
  
  
  
  1.2       +55 -7     jakarta-james/src/java/org/apache/james/testing/TestMethod.java
  
  Index: TestMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/testing/TestMethod.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestMethod.java	12 Oct 2002 19:35:18 -0000	1.1
  +++ TestMethod.java	14 Oct 2002 06:44:22 -0000	1.2
  @@ -9,18 +9,51 @@
   
   import java.lang.reflect.Method;
   
  +/**
  + * A test class to test a single method call.
  + */
   class TestMethod {
  -    // stats
  +
  +    // Statistics
  +
  +    /**
  +     * The total time taken by the test.
  +     */
       private int timeTaken;
  +
  +    /**
  +     * The total number of method calls.
  +     */
       private int attempts;
  +
  +    /**
  +     * The number of successful (that is, executed without generating an
  +     * exception) method calls.
  +     */
       private int success;
  -    
  +
  +    /**
  +     * The name of the method being invoked.
  +     */
       final String name;
  +
  +    /**
  +     * Constructor for the test.
  +     *
  +     * @param name the method to be invoked.
  +     */
       TestMethod(String name) {
           this.name = name;
       }
  -    
  -    // invoke test
  +
  +    /**
  +     * Invokes the test, registering an additional attempt and an
  +     * additional success if appropriate.  The total time taken is
  +     * recorded.
  +     *
  +     * @param obj An object of the class on which the method
  +     *            to be tested should be invoked.
  +     */
       void invoke(Object obj) throws Exception {
           Method m = obj.getClass().getMethod(name,new Class[0]);
           attempts++;
  @@ -29,11 +62,26 @@
               m.invoke(obj,new Object[0]);
               success++;
           } finally {
  -            timeTaken = (int)(System.currentTimeMillis() - st);
  +            timeTaken += (int)(System.currentTimeMillis() - st);
           }
       }
  -    // print report.
  +
  +    /**
  +     * Returns a representation of this object as a String.  The specific
  +     * representation is a report including the name of the called method,
  +     * the number of attempts, the number of successes, and the total time
  +     * taken.
  +     */
       public String toString() {
  -        return name+", "+timeTaken+", "+success+", "+attempts;
  +        StringBuffer theStringBuffer =
  +            new StringBuffer(128)
  +                    .append(name)
  +                    .append(", ")
  +                    .append(timeTaken)
  +                    .append(", ")
  +                    .append(success)
  +                    .append(", ")
  +                    .append(attempts);
  +        return theStringBuffer.toString();
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-james/src/java/org/apache/james/testing BaseTest.java EndToEnd.java Main.java MultiThreadDeliveryPounder.java POP3Hammering.java POP3Test.java SMTPDeliveryWorker.java TestMethod.java

Posted by Harmeet Bedi <ha...@kodemuse.com>.
----- Original Message -----
From: <pg...@apache.org>
To: <ja...@apache.org>
Sent: Sunday, October 13, 2002 11:44 PM
Subject: cvs commit: jakarta-james/src/java/org/apache/james/testing
BaseTest.java EndToEnd.java Main.java MultiThreadDeliveryPounder.java
POP3Hammering.java POP3Test.java SMTPDeliveryWorker.java TestMethod.java


> pgoldstein    2002/10/13 23:44:22
>
>   Modified:    src/java/org/apache/james/testing BaseTest.java
>                         EndToEnd.java Main.java
>                         MultiThreadDeliveryPounder.java POP3Hammering.java
>                         POP3Test.java SMTPDeliveryWorker.java
>                         TestMethod.java
>   Log:
>   Added a number of comments.
>
>   Corrected a minor bug in the TestMethod code where the time taken was
not summed over all attemtps.
>
>


Thanks Peter, wasn't really looking forward to doing the javadocs. You took
a load off me.

Harmeet


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>