1 18 19 package org.apache.jmeter.assertions; 20 import java.io.Serializable ; 21 import java.text.MessageFormat ; 22 23 import org.apache.jmeter.samplers.SampleResult; 24 import org.apache.jmeter.testelement.AbstractTestElement; 25 import org.apache.jmeter.testelement.property.LongProperty; 26 import org.apache.jmeter.util.JMeterUtils; 27 35 public class DurationAssertion 36 extends AbstractTestElement 37 implements Serializable , Assertion 38 { 39 40 private static final String DURATION_KEY = "DurationAssertion.duration"; 41 47 public AssertionResult getResult(SampleResult response) 48 { 49 AssertionResult result = new AssertionResult(); 50 result.setFailure(false); 51 if (((response.getTime() > getAllowedDuration()) 53 && (getAllowedDuration() > 0))) 54 { 55 result.setFailure(true); 56 Object [] arguments = 57 { new Long (response.getTime()), new Long (getAllowedDuration())}; 58 String message = 59 MessageFormat.format( 60 JMeterUtils.getResString("duration_assertion_failure"), 61 arguments); 62 result.setFailureMessage(message); 63 } 64 return result; 65 } 66 67 71 public long getAllowedDuration() 72 { 73 return getPropertyAsLong(DURATION_KEY); 74 } 75 76 86 public void setAllowedDuration(long duration) throws IllegalArgumentException 87 { 88 if (duration < 0L) 89 { 90 throw new IllegalArgumentException ( 91 JMeterUtils.getResString("argument_must_not_be_negative")); 92 } 93 if (duration == Long.MAX_VALUE) 94 { 95 setProperty(new LongProperty(DURATION_KEY,0)); 96 } 97 else 98 { 99 setProperty(new LongProperty(DURATION_KEY,duration)); 100 } 101 } 102 } | Popular Tags |