neth        01/08/29 04:41:34

  Added:       src/org/apache/jmeter/engine IncrementalJMeterEngine.java
  Log:
  Increases the number of threads performing sampling for each iteration.
  
  Revision  Changes    Path
  1.1                  
jakarta-jmeter/src/org/apache/jmeter/engine/IncrementalJMeterEngine.java
  
  Index: IncrementalJMeterEngine.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.jmeter.engine;
  
  import java.util.*;
  import org.apache.jmeter.samplers.SampleListener;
  import org.apache.jmeter.threads.JMeterThread;
  import org.apache.jmeter.threads.ThreadGroup;
  import org.apache.jmeter.timers.Timer;
  
  import org.apache.log4j.*;
  
  /**
   * This engine automatically increments the threads used for sampling
   * until selected threshold is reached.
   *
   * @author            Khor Soon HIn
   * @created           2001/08/26
   * @version           1.0
   */
  public class IncrementalJMeterEngine extends StandardJMeterEngine
  {
    private static Category catClass = 
      Category.getInstance(IncrementalJMeterEngine.class.getName());
  
    protected int threadStartCount = 0;
    protected int threadEndCount = 3;
  
    /**
     * Constructor
     **/
    public IncrementalJMeterEngine()
    {
      super();
      catClass.debug("Start : IncrementalJMeterEngine1");
      catClass.debug("End : IncrementalJMeterEngine1");
    }
  
    /**
     * Get the number of threads to start
     *
     * @return  number of threads to start sampling with
     */
    public int getThreadStartCount()
    {
      return threadStartCount;
    }
  
    /**
     * Set the number of threads to start
     *
     * @param           number of threads to start sampling with
     */
    public void setThreadStartCount(int number)
    {
      threadStartCount = number;
    }
  
    /**
     * Get the number of threads to sample until
     *
     * @return  number of threads to sample until
     */
    public int getThreadEndCount()
    {
      return threadEndCount;
    }
  
    /**
     * Set the number of threads to sample until
     *
     * @param           number of threads to sample until
     */
    public void setThreadEndCount(int number)
    {
      threadEndCount = number;
    }
  
    /**
     * Run the engine
     **/
    public void runTest()
    {
      catClass.debug("Start : runTest1");
      running = true;
      int threadCount = 0;
      if(catClass.isDebugEnabled())
      {
        catClass.debug("runTest1 : Threads at start - " + threadStartCount);
        catClass.debug("runTest1 : Threads at end - " + threadEndCount);
      }
      // for each thread group, generate threads
      // hand each thread the sampler controller
      // and the listeners, and the timer
      JMeterThread[] threads;
      // keep track of all the threads generated
      Thread[] threadList;
      Iterator iter = threadGroups.iterator();
      while(iter.hasNext())
      {
        ThreadGroup group = (ThreadGroup)iter.next();
        threadCount = threadStartCount;
        while(threadCount <= threadEndCount)
        {
          if(catClass.isDebugEnabled())
          {
            catClass.debug("runTest1 : Current thread being generate - " + 
threadCount);
          }
          threads = new JMeterThread[threadCount];
          threadList = new Thread[threadCount];
          for(int i = 0; i < threads.length; i++)
          {
            threads[i] = new JMeterThread(group);
            threadList[i] = new Thread(threads[i], 
              "Total Thread : " + threadCount + " ; Thead No. : " + i);
            allThreads.add(threads[i]);
            threadList[i].start();
          }
  
         // wait for all threads to finish before starting the next batch
         for(int i = 0; i < threadCount; i++)
         {
            try
            {
              threadList[i].join();
            }
            catch(InterruptedException e)
            {
              // carry on
            }
          }
          threadCount++;
        }
      }
      catClass.debug("End : runTest1");
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to