1 18 19 package org.apache.jmeter.timers; 20 21 import org.apache.jmeter.engine.event.LoopIterationEvent; 22 import org.apache.jmeter.testbeans.TestBean; 23 import org.apache.jmeter.testelement.TestListener; 24 import org.apache.jmeter.util.JMeterUtils; 25 import org.apache.jorphan.logging.LoggingManager; 26 import org.apache.log.Logger; 27 28 35 public class ConstantThroughputTimer 36 extends TestBean 37 implements Timer, TestListener 38 { 39 private static final Logger log = LoggingManager.getLoggerForClass(); 40 41 46 private long targetTime= 0; 47 48 51 private double throughput; 52 53 56 public ConstantThroughputTimer() 57 { 58 } 59 60 65 public void setThroughput(double throughput) 66 { 67 this.throughput= throughput; 68 } 69 70 75 public double getThroughput() 76 { 77 return throughput; 78 } 79 80 85 public synchronized long delay() 86 { 87 long currentTime = System.currentTimeMillis(); 88 long currentTarget = targetTime == 0 ? currentTime : targetTime; 89 targetTime = currentTarget + (long)( 60000.0 / getThroughput() ); 90 if (currentTime > currentTarget) 91 { 92 return 0; 94 } 95 return currentTarget - currentTime; 96 } 97 98 106 public String toString() 107 { 108 return JMeterUtils.getResString("constant_throughput_timer_memo"); 109 } 110 111 116 public synchronized void testStarted() { 118 log.debug("Test started - reset throughput calculation."); 119 targetTime= 0; 120 } 121 122 125 public void testEnded() 126 { 127 } 128 129 132 public void testStarted(String host) 133 { 134 } 135 136 139 public void testEnded(String host) 140 { 141 } 142 143 146 public void testIterationStart(LoopIterationEvent event) 147 { 148 } 149 } | Popular Tags |