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 2005/11/16 21:18:41 UTC

svn commit: r345098 - in /jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions: DurationAssertion.java gui/DurationAssertionGui.java

Author: sebb
Date: Wed Nov 16 12:18:28 2005
New Revision: 345098

URL: http://svn.apache.org/viewcvs?rev=345098&view=rev
Log:
Bug 37490 - Allow UDV as delay in Duration Assertion

Modified:
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/DurationAssertion.java
    jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/gui/DurationAssertionGui.java

Modified: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/DurationAssertion.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/DurationAssertion.java?rev=345098&r1=345097&r2=345098&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/DurationAssertion.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/DurationAssertion.java Wed Nov 16 12:18:28 2005
@@ -1,6 +1,5 @@
-// $Header$
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,19 +22,18 @@
 
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.AbstractTestElement;
-import org.apache.jmeter.testelement.property.LongProperty;
 import org.apache.jmeter.util.JMeterUtils;
 
 /**
  * Checks if an Sample is sampled within a specified time-frame. If the duration
  * is larger than the timeframe the Assertion is considered a failure.
  * 
- * @author <a href="mailto:wolfram.rittmeyer@web.de">Wolfram Rittmeyer</a>
+ * author <a href="mailto:wolfram.rittmeyer@web.de">Wolfram Rittmeyer</a>
  * @version $Revision$, $Date$
  */
 public class DurationAssertion extends AbstractTestElement implements Serializable, Assertion {
 	/** Key for storing assertion-informations in the jmx-file. */
-	private static final String DURATION_KEY = "DurationAssertion.duration";
+	public static final String DURATION_KEY = "DurationAssertion.duration"; // $NON-NLS-1$
 
 	/**
 	 * Returns the result of the Assertion. Here it checks wether the Sample
@@ -46,12 +44,18 @@
 	public AssertionResult getResult(SampleResult response) {
 		AssertionResult result = new AssertionResult();
 		result.setFailure(false);
-		// has the Sample lasted to long?
-		if (((response.getTime() > getAllowedDuration()) && (getAllowedDuration() > 0))) {
-			result.setFailure(true);
-			Object[] arguments = { new Long(response.getTime()), new Long(getAllowedDuration()) };
-			String message = MessageFormat.format(JMeterUtils.getResString("duration_assertion_failure"), arguments);
-			result.setFailureMessage(message);
+		long duration=getAllowedDuration();
+		if (duration > 0) {
+			long responseTime=response.getTime();
+		// has the Sample lasted too long?
+			if ( responseTime > duration) {
+				result.setFailure(true);
+				Object[] arguments = { new Long(responseTime), new Long(duration) };
+				String message = MessageFormat.format(
+						JMeterUtils.getResString("duration_assertion_failure") // $NON-NLS-1$
+						, arguments);
+				result.setFailureMessage(message);
+			}
 		}
 		return result;
 	}
@@ -60,29 +64,8 @@
 	 * Returns the duration to be asserted. A duration of 0 indicates this
 	 * assertion is to be ignored.
 	 */
-	public long getAllowedDuration() {
+	private long getAllowedDuration() {
 		return getPropertyAsLong(DURATION_KEY);
 	}
 
-	/**
-	 * Set the duration that shall be asserted.
-	 * 
-	 * @param duration
-	 *            a period of time in milliseconds. Is not allowed to be
-	 *            negative. Use Double.MAX_VALUE to indicate illegal or empty
-	 *            inputs. This will result to not checking the assertion.
-	 * 
-	 * @throws IllegalArgumentException
-	 *             if <code>duration</code> is negative.
-	 */
-	public void setAllowedDuration(long duration) throws IllegalArgumentException {
-		if (duration < 0L) {
-			throw new IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative"));
-		}
-		if (duration == Long.MAX_VALUE) {
-			setProperty(new LongProperty(DURATION_KEY, 0));
-		} else {
-			setProperty(new LongProperty(DURATION_KEY, duration));
-		}
-	}
 }

Modified: jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/gui/DurationAssertionGui.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/gui/DurationAssertionGui.java?rev=345098&r1=345097&r2=345098&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/gui/DurationAssertionGui.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/components/org/apache/jmeter/assertions/gui/DurationAssertionGui.java Wed Nov 16 12:18:28 2005
@@ -19,27 +19,24 @@
 package org.apache.jmeter.assertions.gui;
 
 import java.awt.BorderLayout;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
 
 import javax.swing.BorderFactory;
 import javax.swing.JLabel;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 
 import org.apache.jmeter.assertions.DurationAssertion;
-import org.apache.jmeter.gui.util.HorizontalPanel;
+import org.apache.jmeter.gui.util.VerticalPanel;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.util.JMeterUtils;
-import org.apache.jorphan.logging.LoggingManager;
-import org.apache.log.Logger;
+//import org.apache.jorphan.logging.LoggingManager;
+//import org.apache.log.Logger;
 
 /**
  * @version $Revision$ Last updated: $Date$
  */
-public class DurationAssertionGui extends AbstractAssertionGui implements FocusListener {
-	transient private static Logger log = LoggingManager.getLoggerForClass();
+public class DurationAssertionGui extends AbstractAssertionGui {
+	//private static final Logger log = LoggingManager.getLoggerForClass();
 
 	private JTextField duration;
 
@@ -48,11 +45,11 @@
 	}
 
 	public String getLabelResource() {
-		return "duration_assertion_title";
+		return "duration_assertion_title"; // $NON-NLS-1$
 	}
 
 	public String getDurationAttributesTitle() {
-		return JMeterUtils.getResString("duration_assertion_duration_test");
+		return JMeterUtils.getResString("duration_assertion_duration_test"); // $NON-NLS-1$
 	}
 
 	public TestElement createTestElement() {
@@ -68,20 +65,12 @@
 	 */
 	public void modifyTestElement(TestElement el) {
 		configureTestElement(el);
-		String durationString = duration.getText();
-		long assertionDuration = 0;
-		try {
-			assertionDuration = Long.parseLong(durationString);
-		} catch (NumberFormatException e) {
-			assertionDuration = Long.MAX_VALUE;
-		}
-		((DurationAssertion) el).setAllowedDuration(assertionDuration);
+		el.setProperty(DurationAssertion.DURATION_KEY,duration.getText());
 	}
 
 	public void configure(TestElement el) {
 		super.configure(el);
-		DurationAssertion assertion = (DurationAssertion) el;
-		duration.setText(String.valueOf(assertion.getAllowedDuration()));
+		duration.setText(el.getPropertyAsString(DurationAssertion.DURATION_KEY));
 	}
 
 	private void init() {
@@ -93,40 +82,21 @@
 		JPanel mainPanel = new JPanel(new BorderLayout());
 
 		// USER_INPUT
-		HorizontalPanel durationPanel = new HorizontalPanel();
+		VerticalPanel durationPanel = new VerticalPanel();
 		durationPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
 				getDurationAttributesTitle()));
 
-		durationPanel.add(new JLabel(JMeterUtils.getResString("duration_assertion_label")));
-
-		duration = new JTextField(5);
-		duration.addFocusListener(this);
-		durationPanel.add(duration);
-
+		JPanel labelPanel = new JPanel(new BorderLayout(5, 0));
+		JLabel durationLabel = 
+			new JLabel(JMeterUtils.getResString("duration_assertion_label")); // $NON-NLS-1$ 
+		labelPanel.add(durationLabel, BorderLayout.WEST);
+
+		duration = new JTextField();
+		labelPanel.add(duration, BorderLayout.CENTER);
+		durationLabel.setLabelFor(duration);
+		durationPanel.add(labelPanel);
+		
 		mainPanel.add(durationPanel, BorderLayout.NORTH);
 		add(mainPanel, BorderLayout.CENTER);
-	}
-
-	public void focusLost(FocusEvent e) {
-		boolean isInvalid = false;
-		String durationString = duration.getText();
-		if (durationString != null) {
-			try {
-				long assertionDuration = Long.parseLong(durationString);
-				if (assertionDuration < 0) {
-					isInvalid = true;
-				}
-			} catch (NumberFormatException ex) {
-				isInvalid = true;
-			}
-			if (isInvalid) {
-				log.warn("DurationAssertionGui: Not a valid number!");
-				JOptionPane.showMessageDialog(null, JMeterUtils.getResString("duration_assertion_input_error"),
-						"Error", JOptionPane.ERROR_MESSAGE);
-			}
-		}
-	}
-
-	public void focusGained(FocusEvent e) {
 	}
 }



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