You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by ms...@apache.org on 2003/05/14 14:49:43 UTC

cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/util JMeterUtils.java

mstover1    2003/05/14 05:49:42

  Modified:    .        build.xml
               bin      jmeter.properties
               src/core/org/apache/jmeter/engine StandardJMeterEngine.java
               src/core/org/apache/jmeter/util JMeterUtils.java
  Removed:     lib      util.jar
  Log:
  Fixing stopping a test
  removing util.jar which is an LPGL library
  updating version number in build.xml
  
  Revision  Changes    Path
  1.95      +1 -1      jakarta-jmeter/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/build.xml,v
  retrieving revision 1.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- build.xml	6 May 2003 20:02:14 -0000	1.94
  +++ build.xml	14 May 2003 12:49:41 -0000	1.95
  @@ -13,7 +13,7 @@
     </description>
   
     <!-- JMeter version -->
  -  <property name="version" value="1.8.1"/>
  +  <property name="version" value="1.9-RC1"/>
   
     <!-- Where the Sources live -->
     <property name="src.dir" value="src"/>
  
  
  
  1.73      +1 -1      jakarta-jmeter/bin/jmeter.properties
  
  Index: jmeter.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/bin/jmeter.properties,v
  retrieving revision 1.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- jmeter.properties	8 May 2003 18:29:13 -0000	1.72
  +++ jmeter.properties	14 May 2003 12:49:41 -0000	1.73
  @@ -72,7 +72,7 @@
   #Logging levels for the logging categories in JMeter.  Correct values are FATAL_ERROR, ERROR, WARN, INFO, and DEBUG
   log_level.jmeter=WARN
   log_level.jmeter.engine=WARN
  -log_level.jmeter.gui=DEBUG
  +log_level.jmeter.gui=WARN
   log_level.jmeter.elements=WARN
   log_level.jmeter.util=WARN
   log_level.jmeter.util.classfinder=WARN
  
  
  
  1.23      +291 -285  jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
  
  Index: StandardJMeterEngine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- StandardJMeterEngine.java	13 May 2003 17:42:56 -0000	1.22
  +++ StandardJMeterEngine.java	14 May 2003 12:49:42 -0000	1.23
  @@ -87,288 +87,294 @@
    *@created    $Date$
    *@version    $Revision$
    ***********************************************************/
  -public class StandardJMeterEngine implements JMeterEngine,JMeterThreadMonitor,
  -		Runnable,Serializable
  +public class StandardJMeterEngine implements JMeterEngine, JMeterThreadMonitor, Runnable, Serializable
   {
  -	transient private static Logger log = Hierarchy.getDefaultHierarchy().getLoggerFor(
  -			"jmeter.engine");
  -	private Thread runningThread;
  -	private static long WAIT_TO_DIE = 5 * 1000; //5 seconds
  -	Map allThreads;
  -	boolean running = false;
  -	boolean serialized = false;
  -	HashTree test;
  -	SearchByClass testListeners;
  -	String host = null;
  -	ListenerNotifier notifier;
  -
  -	/************************************************************
  -	 *  !ToDo (Constructor description)
  -	 ***********************************************************/
  -	public StandardJMeterEngine()
  -	{
  -		allThreads = new HashMap();
  -	}
  -
  -	public StandardJMeterEngine(String host)
  -	{
  -		this();
  -		this.host = host;
  -	}
  -
  -	public void configure(HashTree testTree)
  -	{
  -		test = testTree;
  -	}
  -	
  -	public void setHost(String host)
  -	{
  -		this.host = host;
  -	}
  -
  -	protected HashTree getTestTree()
  -	{
  -		return test;
  -	}
  -	
  -	protected void compileTree()
  -	{
  -		PreCompiler compiler = new PreCompiler();
  -		getTestTree().traverse(compiler);
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 ***********************************************************/
  -	public void runTest() throws JMeterEngineException
  -	{
  -		try
  -		{
  -			runningThread = new Thread(this);
  -			runningThread.start();
  -		}
  -		catch(Exception err)
  -		{
  -			stopTest();
  -			StringWriter string = new StringWriter();
  -			PrintWriter writer = new PrintWriter(string);
  -			err.printStackTrace(writer);
  -			throw new JMeterEngineException(string.toString());
  -		}
  -	}
  -	
  -	private void removeThreadGroups(List elements)
  -	{
  -		Iterator iter = elements.iterator();
  -		while(iter.hasNext())
  -		{
  -			Object item = iter.next();
  -			if(item instanceof ThreadGroup)
  -			{
  -				iter.remove();
  -			}
  -			else if(!(item instanceof TestElement))
  -			{
  -				iter.remove();
  -			}
  -		}
  -	}
  -	
  -	protected void setMode()
  -	{
  -		SearchByClass testPlan = new SearchByClass(TestPlan.class);
  -		getTestTree().traverse(testPlan);
  -		Object[] plan = testPlan.getSearchResults().toArray();
  -		ResultCollector.enableFunctionalMode(((TestPlan)plan[0]).isFunctionalMode());
  -	}
  -
  -	protected void notifyTestListenersOfStart()
  -	{
  -		Iterator iter = testListeners.getSearchResults().iterator();
  -		while(iter.hasNext())
  -		{
  -			if(host == null)
  -			{
  -				((TestListener)iter.next()).testStarted();
  -			}
  -			else
  -			{
  -				((TestListener)iter.next()).testStarted(host);
  -			}
  -		}
  -	}
  -
  -
  -	protected void notifyTestListenersOfEnd()
  -	{
  -		Iterator iter = testListeners.getSearchResults().iterator();
  -		while(iter.hasNext())
  -		{
  -			if(host == null)
  -			{
  -				((TestListener)iter.next()).testEnded();
  -			}
  -			else
  -			{
  -				((TestListener)iter.next()).testEnded(host);
  -			}
  -		}
  -	}
  -
  -	private ListedHashTree cloneTree(ListedHashTree tree)
  -	{
  -		TreeCloner cloner = new TreeCloner(true);
  -		tree.traverse(cloner);
  -		return cloner.getClonedTree();
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 ***********************************************************/
  -	public void reset()
  -	{
  -		if(running)
  -		{
  -			stopTest();
  -		}
  -	}
  -
  -	public synchronized void threadFinished(JMeterThread thread)
  -	{
  -		allThreads.remove(thread);
  -		if(!serialized && allThreads.size() == 0)
  -		{
  -			stopTest();
  -		}
  -	}
  -
  -	/************************************************************
  -	 *  !ToDo (Method description)
  -	 ***********************************************************/
  -	public synchronized void stopTest()
  -	{
  -		if(running)
  -		{
  -			running = false;
  -			tellThreadsToStop();
  -			try
  -			{
  -				Thread.sleep(10 * allThreads.size());
  -			}
  -			catch (InterruptedException e)
  -			{
  -			}
  -			verifyThreadsStopped();
  -			notifyTestListenersOfEnd();	
  -		}
  -	}
  -	
  -	public void run()
  -	{
  -		log.info("Running the test!");
  -		running = true;
  -			
  -		SearchByClass testPlan = new SearchByClass(TestPlan.class);
  -		getTestTree().traverse(testPlan);
  -		Object[] plan = testPlan.getSearchResults().toArray();
  -		if(((TestPlan)plan[0]).isSerialized())
  -			serialized = true;			
  -		compileTree();
  -		List testLevelElements = new LinkedList(getTestTree().list(getTestTree().getArray()[0]));
  -		removeThreadGroups(testLevelElements);
  -		SearchByClass searcher = new SearchByClass(ThreadGroup.class);
  -		testListeners = new SearchByClass(TestListener.class);
  -		setMode();
  -		getTestTree().traverse(testListeners);
  -		getTestTree().traverse(searcher);
  -		TestCompiler.initialize();
  -		//for each thread group, generate threads
  -		// hand each thread the sampler controller
  -		// and the listeners, and the timer
  -		JMeterThread[] threads;
  -		Iterator iter = searcher.getSearchResults().iterator();
  -		if(iter.hasNext())
  -		{
  -			notifyTestListenersOfStart();
  -		}
  -		notifier = new ListenerNotifier();
  -		while(iter.hasNext())
  -		{
  -			ThreadGroup group = (ThreadGroup)iter.next();
  -			threads = new JMeterThread[group.getNumThreads()];
  -			for(int i = 0;running && i < threads.length; i++)
  -			{
  -				ListedHashTree threadGroupTree = (ListedHashTree)searcher.getSubTree(group);
  -				threadGroupTree.add(group,testLevelElements);
  -				threads[i] = new JMeterThread(cloneTree(threadGroupTree),this,notifier);
  -				threads[i].setThreadNum(i);
  -				threads[i].setInitialContext(JMeterContextService.getContext());
  -				threads[i].setInitialDelay((int)(((float)(group.getRampUp() * 1000) /
  -						(float)group.getNumThreads()) * (float)i));
  -				threads[i].setThreadName(group.getName()+"-"+(i+1));
  -				Thread newThread = new Thread(threads[i]);
  -				newThread.setName(group.getName()+"-"+(i+1));
  -				allThreads.put(threads[i],newThread);
  -				if (serialized && !iter.hasNext() && i==threads.length-1) //last thread
  -				{
  -					serialized = false;
  -				}
  -				newThread.start();
  -			}
  -			if (serialized)
  -			{
  -				while(running && allThreads.size()>0)
  -				{
  -					try {
  -						Thread.sleep(1000);
  -					} catch (InterruptedException e) {}
  -				}
  -			}
  -		}
  -	}
  -
  -	private void verifyThreadsStopped()
  -	{
  -		Iterator iter = new HashSet(allThreads.keySet()).iterator();
  -		while(iter.hasNext())
  -		{
  -			Thread t = (Thread)allThreads.get(iter.next());
  -			if(t != null && t.isAlive())
  -			{
  -				try
  -				{
  -					t.join(WAIT_TO_DIE);
  -				}
  -				catch (InterruptedException e)
  -				{
  -				}
  -				if(t.isAlive())
  -				{
  -					log.info("Thread won't die: "+t.getName());
  -				}
  -			}
  -			log.debug("finished thread");
  -		}
  -	}
  -
  -	private void tellThreadsToStop()
  -	{
  -		Iterator iter = new HashSet(allThreads.keySet()).iterator();
  -		while(iter.hasNext())
  -		{
  -			JMeterThread item = (JMeterThread)iter.next();
  -			item.stop();
  -			Thread t = (Thread)allThreads.get(item);
  -			if(t != null)
  -			{
  -				t.interrupt();
  -			}
  -			else
  -			{
  -				log.warn("Lost thread: "+item.getThreadName());
  -				allThreads.remove(item);
  -			}
  -		}
  -	}
  +    transient private static Logger log = Hierarchy.getDefaultHierarchy().getLoggerFor("jmeter.engine");
  +    private Thread runningThread;
  +    private static long WAIT_TO_DIE = 5 * 1000; //5 seconds
  +    Map allThreads;
  +    boolean running = false;
  +    boolean serialized = false;
  +    HashTree test;
  +    SearchByClass testListeners;
  +    String host = null;
  +    ListenerNotifier notifier;
  +
  +    /************************************************************
  +     *  !ToDo (Constructor description)
  +     ***********************************************************/
  +    public StandardJMeterEngine()
  +    {
  +        allThreads = new HashMap();
  +    }
  +
  +    public StandardJMeterEngine(String host)
  +    {
  +        this();
  +        this.host = host;
  +    }
  +
  +    public void configure(HashTree testTree)
  +    {
  +        test = testTree;
  +    }
  +
  +    public void setHost(String host)
  +    {
  +        this.host = host;
  +    }
  +
  +    protected HashTree getTestTree()
  +    {
  +        return test;
  +    }
  +
  +    protected void compileTree()
  +    {
  +        PreCompiler compiler = new PreCompiler();
  +        getTestTree().traverse(compiler);
  +    }
  +
  +    /************************************************************
  +     *  !ToDo (Method description)
  +     ***********************************************************/
  +    public void runTest() throws JMeterEngineException
  +    {
  +        try
  +        {
  +            runningThread = new Thread(this);
  +            runningThread.start();
  +        }
  +        catch (Exception err)
  +        {
  +            stopTest();
  +            StringWriter string = new StringWriter();
  +            PrintWriter writer = new PrintWriter(string);
  +            err.printStackTrace(writer);
  +            throw new JMeterEngineException(string.toString());
  +        }
  +    }
  +
  +    private void removeThreadGroups(List elements)
  +    {
  +        Iterator iter = elements.iterator();
  +        while (iter.hasNext())
  +        {
  +            Object item = iter.next();
  +            if (item instanceof ThreadGroup)
  +            {
  +                iter.remove();
  +            }
  +            else if (!(item instanceof TestElement))
  +            {
  +                iter.remove();
  +            }
  +        }
  +    }
  +
  +    protected void setMode()
  +    {
  +        SearchByClass testPlan = new SearchByClass(TestPlan.class);
  +        getTestTree().traverse(testPlan);
  +        Object[] plan = testPlan.getSearchResults().toArray();
  +        ResultCollector.enableFunctionalMode(((TestPlan) plan[0]).isFunctionalMode());
  +    }
  +
  +    protected void notifyTestListenersOfStart()
  +    {
  +        Iterator iter = testListeners.getSearchResults().iterator();
  +        while (iter.hasNext())
  +        {
  +            if (host == null)
  +            {
  +                ((TestListener) iter.next()).testStarted();
  +            }
  +            else
  +            {
  +                ((TestListener) iter.next()).testStarted(host);
  +            }
  +        }
  +    }
  +
  +    protected void notifyTestListenersOfEnd()
  +    {
  +        Iterator iter = testListeners.getSearchResults().iterator();
  +        while (iter.hasNext())
  +        {
  +            if (host == null)
  +            {
  +                ((TestListener) iter.next()).testEnded();
  +            }
  +            else
  +            {
  +                ((TestListener) iter.next()).testEnded(host);
  +            }
  +        }
  +    }
  +
  +    private ListedHashTree cloneTree(ListedHashTree tree)
  +    {
  +        TreeCloner cloner = new TreeCloner(true);
  +        tree.traverse(cloner);
  +        return cloner.getClonedTree();
  +    }
  +
  +    /************************************************************
  +     *  !ToDo (Method description)
  +     ***********************************************************/
  +    public void reset()
  +    {
  +        if (running)
  +        {
  +            stopTest();
  +        }
  +    }
  +
  +    public synchronized void threadFinished(JMeterThread thread)
  +    {
  +        allThreads.remove(thread);
  +        if (!serialized && allThreads.size() == 0)
  +        {
  +            stopTest();
  +        }
  +    }
  +
  +    /************************************************************
  +     *  !ToDo (Method description)
  +     ***********************************************************/
  +    public synchronized void stopTest()
  +    {
  +        Thread stopThread = new Thread(new StopTest());
  +        stopThread.start();
  +    }
  +
  +    private class StopTest implements Runnable
  +    {
  +        public void run()
  +        {
  +            if (running)
  +            {
  +                running = false;
  +                tellThreadsToStop();
  +                try
  +                {
  +                    Thread.sleep(10 * allThreads.size());
  +                }
  +                catch (InterruptedException e)
  +                {}
  +                verifyThreadsStopped();
  +                notifyTestListenersOfEnd();
  +            }
  +        }
  +    }
  +
  +    public void run()
  +    {
  +        log.info("Running the test!");
  +        running = true;
  +
  +        SearchByClass testPlan = new SearchByClass(TestPlan.class);
  +        getTestTree().traverse(testPlan);
  +        Object[] plan = testPlan.getSearchResults().toArray();
  +        if (((TestPlan) plan[0]).isSerialized())
  +            serialized = true;
  +        compileTree();
  +        List testLevelElements = new LinkedList(getTestTree().list(getTestTree().getArray()[0]));
  +        removeThreadGroups(testLevelElements);
  +        SearchByClass searcher = new SearchByClass(ThreadGroup.class);
  +        testListeners = new SearchByClass(TestListener.class);
  +        setMode();
  +        getTestTree().traverse(testListeners);
  +        getTestTree().traverse(searcher);
  +        TestCompiler.initialize();
  +        //for each thread group, generate threads
  +        // hand each thread the sampler controller
  +        // and the listeners, and the timer
  +        JMeterThread[] threads;
  +        Iterator iter = searcher.getSearchResults().iterator();
  +        if (iter.hasNext())
  +        {
  +            notifyTestListenersOfStart();
  +        }
  +        notifier = new ListenerNotifier();
  +        while (iter.hasNext())
  +        {
  +            ThreadGroup group = (ThreadGroup) iter.next();
  +            threads = new JMeterThread[group.getNumThreads()];
  +            for (int i = 0; running && i < threads.length; i++)
  +            {
  +                ListedHashTree threadGroupTree = (ListedHashTree) searcher.getSubTree(group);
  +                threadGroupTree.add(group, testLevelElements);
  +                threads[i] = new JMeterThread(cloneTree(threadGroupTree), this, notifier);
  +                threads[i].setThreadNum(i);
  +                threads[i].setInitialContext(JMeterContextService.getContext());
  +                threads[i].setInitialDelay((int) (((float) (group.getRampUp() * 1000) / (float) group.getNumThreads()) * (float) i));
  +                threads[i].setThreadName(group.getName() + "-" + (i + 1));
  +                Thread newThread = new Thread(threads[i]);
  +                newThread.setName(group.getName() + "-" + (i + 1));
  +                allThreads.put(threads[i], newThread);
  +                if (serialized && !iter.hasNext() && i == threads.length - 1) //last thread
  +                {
  +                    serialized = false;
  +                }
  +                newThread.start();
  +            }
  +            if (serialized)
  +            {
  +                while (running && allThreads.size() > 0)
  +                {
  +                    try
  +                    {
  +                        Thread.sleep(1000);
  +                    }
  +                    catch (InterruptedException e)
  +                    {}
  +                }
  +            }
  +        }
  +    }
  +
  +    private void verifyThreadsStopped()
  +    {
  +        Iterator iter = new HashSet(allThreads.keySet()).iterator();
  +        while (iter.hasNext())
  +        {
  +            Thread t = (Thread) allThreads.get(iter.next());
  +            if (t != null && t.isAlive())
  +            {
  +                try
  +                {
  +                    t.join(WAIT_TO_DIE);
  +                }
  +                catch (InterruptedException e)
  +                {}
  +                if (t.isAlive())
  +                {
  +                    log.info("Thread won't die: " + t.getName());
  +                }
  +            }
  +            log.debug("finished thread");
  +        }
  +    }
  +
  +    private void tellThreadsToStop()
  +    {
  +        Iterator iter = new HashSet(allThreads.keySet()).iterator();
  +        while (iter.hasNext())
  +        {
  +            JMeterThread item = (JMeterThread) iter.next();
  +            item.stop();
  +            Thread t = (Thread) allThreads.get(item);
  +            if (t != null)
  +            {
  +                t.interrupt();
  +            }
  +            else
  +            {
  +                log.warn("Lost thread: " + item.getThreadName());
  +                allThreads.remove(item);
  +            }
  +        }
  +    }
   
   }
  
  
  
  1.21      +3 -2      jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java
  
  Index: JMeterUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- JMeterUtils.java	16 Apr 2003 20:35:27 -0000	1.20
  +++ JMeterUtils.java	14 May 2003 12:49:42 -0000	1.21
  @@ -97,7 +97,7 @@
    */
   public class JMeterUtils implements UnitTestManager
   {
  -        private static final String VERSION="1.8.1";
  +        private static final String VERSION="1.9-RC1";
           private static PatternCacheLRU patternCache = new PatternCacheLRU(1000,new Perl5Compiler());
   
   	transient private static Logger log =
  @@ -977,4 +977,5 @@
   		return VERSION;
   	}
   }
  +
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/util JMeterUtils.java

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
On Wed, 14 May 2003 10:49 pm, mstover1@apache.org wrote:
>   removing util.jar which is an LPGL library

Thanks Mike.

Conor



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org