1 18 19 package org.apache.jmeter.control; 20 21 import java.io.Serializable ; 22 23 import org.apache.jmeter.samplers.Sampler; 24 import org.apache.jmeter.testelement.property.LongProperty; 25 import org.apache.jmeter.testelement.property.StringProperty; 26 29 32 public class RunTime extends GenericController implements Serializable 33 { 34 36 private final static String SECONDS = "RunTime.seconds"; 37 private volatile long startTime = 0; 38 39 private int loopCount = 0; 41 public RunTime() 42 { 43 } 44 45 public void setRuntime(long seconds) 46 { 47 setProperty(new LongProperty(SECONDS, seconds)); 48 } 49 50 public void setRuntime(String seconds) 51 { 52 setProperty(new StringProperty(SECONDS, seconds)); 53 } 54 55 public long getRuntime() 56 { 57 try 58 { 59 return Long.parseLong(getPropertyAsString(SECONDS)); 60 } 61 catch (NumberFormatException e) 62 { 63 return 0L; 64 } 65 } 66 67 public String getRuntimeString() 68 { 69 return getPropertyAsString(SECONDS); 70 } 71 72 75 public boolean isDone() 76 { 77 if (getRuntime() > 0 && getSubControllers().size() > 0) 78 { 79 return super.isDone(); 80 } 81 else 82 { 83 return true; } 85 } 86 87 private boolean endOfLoop() 88 { 89 return System.currentTimeMillis()-startTime >= 1000*getRuntime(); 90 } 91 92 public Sampler next() 93 { 94 if (startTime == 0) startTime=System.currentTimeMillis(); 95 return super.next(); 96 } 97 100 protected Sampler nextIsNull() throws NextIsNullException 101 { 102 reInitialize(); 103 if (endOfLoop()) 104 { 105 resetLoopCount(); 106 return null; 107 } 108 else 109 { 110 return next(); 111 } 112 } 113 114 protected void incrementLoopCount() 115 { 116 loopCount++; 117 } 118 protected void resetLoopCount() 119 { 120 loopCount=0; 121 startTime=0; 122 } 123 126 protected int getIterCount() 127 { 128 return loopCount + 1; 129 } 130 protected void reInitialize() 131 { 132 setFirst(true); 133 resetCurrent(); 134 incrementLoopCount(); 135 } 136 } | Popular Tags |