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 se...@apache.org on 2003/12/10 00:17:39 UTC

cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/reporters ResultAction.java

sebb        2003/12/09 15:17:39

  Added:       src/core/org/apache/jmeter/reporters/gui
                        ResultActionGui.java
               src/core/org/apache/jmeter/testelement
                        OnErrorTestElement.java
               src/core/org/apache/jmeter/gui OnErrorPanel.java
               src/core/org/apache/jmeter/reporters ResultAction.java
  Log:
  Simple OnError Test Element
  
  Revision  Changes    Path
  1.1                  jakarta-jmeter/src/core/org/apache/jmeter/reporters/gui/ResultActionGui.java
  
  Index: ResultActionGui.java
  ===================================================================
  package org.apache.jmeter.reporters.gui;
  
  import java.awt.BorderLayout;
  
  import javax.swing.Box;
  
  import org.apache.jmeter.reporters.ResultAction;
  import org.apache.jmeter.gui.OnErrorPanel;
  import org.apache.jmeter.processor.gui.AbstractPostProcessorGui;
  import org.apache.jmeter.testelement.OnErrorTestElement;
  import org.apache.jmeter.testelement.TestElement;
  import org.apache.jmeter.util.JMeterUtils;
  
  /**
   * Create a Result Action Test Element
   * 
   * @author sebb AT apache DOT org
   * @version $Revision: 1.1 $ Last updated: $Date: 2003/12/09 23:17:39 $
   */
  public class ResultActionGui extends AbstractPostProcessorGui
  {
  	
  	private OnErrorPanel errorPanel;
     
  	public ResultActionGui()
      {
          super();
          init();
      }
  
      /**
       * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
       */
      public String getStaticLabel()
      {
          return JMeterUtils.getResString("resultaction_title");
      }
      
  	/**
  	 * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
  	 */
      public void configure(TestElement el)
      {
          super.configure(el);
          errorPanel.configure(((OnErrorTestElement)el).getErrorAction());
      }
  
      /**
       * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
       */
      public TestElement createTestElement()
      {
          ResultAction resultAction = new ResultAction();
          modifyTestElement(resultAction);
          return resultAction;
      }
  
      /**
       * Modifies a given TestElement to mirror the data in the gui components.
       * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
       */
      public void modifyTestElement(TestElement te)
      {
          super.configureTestElement(te);
          ((OnErrorTestElement) te).setErrorAction(errorPanel.getOnErrorSetting());
      }
      
      private void init()
      {
          setLayout(new BorderLayout());
          setBorder(makeBorder());
  		Box box = Box.createVerticalBox();
  		box.add(makeTitlePanel());
  		errorPanel = new OnErrorPanel(); 
  		box.add(errorPanel);
  		add(box,BorderLayout.NORTH);
      }
  }
  
  
  
  1.1                  jakarta-jmeter/src/core/org/apache/jmeter/testelement/OnErrorTestElement.java
  
  Index: OnErrorTestElement.java
  ===================================================================
  /*
   * Created on Dec 9, 2003
   *
   */
  package org.apache.jmeter.testelement;
  
  import org.apache.jmeter.testelement.property.IntegerProperty;
  
  /**
   * @author sebb at apache dot org
   * @version $revision$ $date$
   */
  public abstract class OnErrorTestElement extends AbstractTestElement
  {
  	/* Action to be taken when a Sampler error occurs*/
  	public final static int ON_ERROR_CONTINUE = 0;
  	public final static int ON_ERROR_STOPTHREAD = 1;
  	public final static int ON_ERROR_STOPTEST = 2;
  
  	/* Property name */
  	public final static String ON_ERROR_ACTION = "OnError.action";
  
      protected OnErrorTestElement()
      {
          super();
      }
      
  	public void setErrorAction(int value)
  	{
  		setProperty(new IntegerProperty(ON_ERROR_ACTION, value));
  	}
  
  	public int getErrorAction()
  	{
  		int value = getPropertyAsInt(ON_ERROR_ACTION);
  		return value;
  	}
     
      public boolean isContinue()
      {
  		int value = getErrorAction();
  		return value == ON_ERROR_CONTINUE;
      }
  
  	public boolean isStopThread()
  	{	
  		int value = getErrorAction();
  		return value == ON_ERROR_STOPTHREAD;
  	}
  	
  	public boolean isStopTest()
  	{
  		int value = getErrorAction();
  		return value == ON_ERROR_STOPTEST;
  	}
  }
  
  
  
  1.1                  jakarta-jmeter/src/core/org/apache/jmeter/gui/OnErrorPanel.java
  
  Index: OnErrorPanel.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002,2003 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 apache@apache.org.
   *
   * 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.gui;
  import java.awt.BorderLayout;
  
  import javax.swing.BorderFactory;
  import javax.swing.ButtonGroup;
  import javax.swing.JPanel;
  import javax.swing.JRadioButton;
  
  import org.apache.jmeter.testelement.OnErrorTestElement;
  import org.apache.jmeter.util.JMeterUtils;
  
  public class OnErrorPanel extends JPanel 
  {
  	// Sampler error action buttons
  	private JRadioButton continueBox;
  	private JRadioButton stopThrdBox;
  	private JRadioButton stopTestBox;
  
  	private JPanel createOnErrorPanel()
  	{
  		JPanel panel = new JPanel();
  		panel.setBorder(
  			BorderFactory.createTitledBorder(
  				JMeterUtils.getResString("sampler_on_error_action")));
  
  		ButtonGroup group = new ButtonGroup();
  
  		continueBox =
  			new JRadioButton(JMeterUtils.getResString("sampler_on_error_continue"));
  		group.add(continueBox);
  		continueBox.setSelected(true);
  		panel.add(continueBox);
  
  		stopThrdBox =
  			new JRadioButton(JMeterUtils.getResString("sampler_on_error_stop_thread"));
  		group.add(stopThrdBox);
  		panel.add(stopThrdBox);
  
  		stopTestBox =
  			new JRadioButton(JMeterUtils.getResString("sampler_on_error_stop_test"));
  		group.add(stopTestBox);
  		panel.add(stopTestBox);
  
  		return panel;
  	}
      /**
       * Create a new NamePanel with the default name.
       */
      public OnErrorPanel()
      {
          init();
      }
  
      /**
       * Initialize the GUI components and layout.
       */
      private void init()
      {
          setLayout(new BorderLayout(5, 0));
          add(createOnErrorPanel());
      }
      public void configure(int errorAction)
      {
  		stopTestBox.setSelected(errorAction == OnErrorTestElement.ON_ERROR_STOPTEST);
  		stopThrdBox.setSelected(errorAction == OnErrorTestElement.ON_ERROR_STOPTHREAD);
  		//continueBox.setSelected(etc);// no need to set the remaining Radio Button
      }
      
      public int getOnErrorSetting()
      {
  		if (stopTestBox.isSelected()) return OnErrorTestElement.ON_ERROR_STOPTEST;
  		if (stopThrdBox.isSelected()) return OnErrorTestElement.ON_ERROR_STOPTHREAD;
  
  		// Defaults to continue
  		return OnErrorTestElement.ON_ERROR_CONTINUE;
      }
  }
  
  
  
  1.1                  jakarta-jmeter/src/core/org/apache/jmeter/reporters/ResultAction.java
  
  Index: ResultAction.java
  ===================================================================
  package org.apache.jmeter.reporters;
  
  import java.io.Serializable;
  
  import org.apache.jmeter.samplers.Clearable;
  import org.apache.jmeter.samplers.SampleEvent;
  import org.apache.jmeter.samplers.SampleListener;
  import org.apache.jmeter.samplers.SampleResult;
  import org.apache.jmeter.testelement.OnErrorTestElement;
  import org.apache.jorphan.logging.LoggingManager;
  import org.apache.log.Logger;
  
  /**
   * ResultAction - take action based on the status of the last Result
   *  
   * @author sebb AT apache DOT org
   * @version $Revision: 1.1 $ Last updated: $Date: 2003/12/09 23:17:39 $
   */
  public class ResultAction
      extends OnErrorTestElement
      implements Serializable,
      SampleListener,
      Clearable
  {
  	private static final Logger log = LoggingManager.getLoggerForClass();
      
      /*
       * Constructor is initially called once for each occurrence in the test plan
       * For GUI, several more instances are created
       * Then clear is called at start of test
       * Called several times during test startup
       * The name will not necessarily have been set at this point.
       */
  	public ResultAction(){
  		super();
  		//log.debug(Thread.currentThread().getName());
  		//System.out.println(">> "+me+"        "+this.getName()+" "+Thread.currentThread().getName());		
  	}
  
      /*
       * This is called once for each occurrence in the test plan, before the start of the test.
       * The super.clear() method clears the name (and all other properties),
       * so it is called last.
       */
  	public void clear()
  	{
  		//System.out.println("-- "+me+this.getName()+" "+Thread.currentThread().getName());
  		super.clear();
  	}
  	
  	/**
  	 * Examine the sample(s) and take appropriate action 
  	 * 
  	 * @see org.apache.jmeter.samplers.SampleListener#sampleOccurred(org.apache.jmeter.samplers.SampleEvent)
  	 */
  	public void sampleOccurred(SampleEvent e) {
  		SampleResult s = e.getResult();
  		log.debug(s.getSampleLabel()+" OK? "+s.isSuccessful());
  		if (!s.isSuccessful()) {
  			if (isStopTest()) {
  				s.setStopTest(true);
  			}
  			if (isStopThread()) {
  				s.setStopThread(true);
  			}
  		}
      }
  
      /* (non-Javadoc)
  	 * @see org.apache.jmeter.samplers.SampleListener#sampleStarted(org.apache.jmeter.samplers.SampleEvent)
  	 */
  	public void sampleStarted(SampleEvent e) 
  	{
  		// not used
  	}
  
  	/* (non-Javadoc)
  	 * @see org.apache.jmeter.samplers.SampleListener#sampleStopped(org.apache.jmeter.samplers.SampleEvent)
  	 */
  	public void sampleStopped(SampleEvent e)
  	{
  		// not used
  	}
  }
  
  
  

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