Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
* contributor license agreements. See the NOTICE file distributed with |
4 |
* this work for additional information regarding copyright ownership. |
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
* (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* |
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
10 |
* |
11 |
* Unless required by applicable law or agreed to in writing, software |
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
* See the License for the specific language governing permissions and |
15 |
* limitations under the License. |
16 |
* |
17 |
*/ |
18 |
|
19 |
package org.apache.jmeter.timers; |
20 |
|
21 |
import java.lang.reflect.Field; |
22 |
import java.util.ArrayList; |
23 |
import java.util.List; |
24 |
|
25 |
import org.apache.jmeter.junit.JMeterTestCase; |
26 |
import org.apache.jmeter.threads.JMeterContextService; |
27 |
import org.apache.jorphan.logging.LoggingManager; |
28 |
import org.apache.log.Logger; |
29 |
|
30 |
public class ConstantThroughputTimerTest extends JMeterTestCase { |
31 |
|
32 |
private static final Logger LOG = LoggingManager.getLoggerForClass(); |
33 |
|
34 |
/** |
35 |
* Simulation Clock used to manage "SystemClock" time during tests |
36 |
*/ |
37 |
private SimulationClock simulationClock; |
38 |
|
39 |
public ConstantThroughputTimerTest(String arg0) { |
40 |
super(arg0); |
41 |
} |
42 |
|
43 |
/** |
44 |
* <p> |
45 |
* This "simulates" which test data has the next event. In order to handle |
46 |
* shared mode appropriately the "nextEvent" needs to be moved to the end of |
47 |
* the list otherwise the same test data will be returned each time and none |
48 |
* of the other "threads" (which sit after this in the list) will get a |
49 |
* turn. |
50 |
* </p> |
51 |
* |
52 |
* @param testDataList |
53 |
* the list of test data |
54 |
* @return the test data that contains the next event in the simulation, or |
55 |
* null if the are no more events. Non-null next events will be |
56 |
* moved to the end of the <code>List</code> |
57 |
*/ |
58 |
private ConstantThroughputTimerTestData getNextEvent( |
59 |
List<ConstantThroughputTimerTestData> testDataList) { |
60 |
|
61 |
ConstantThroughputTimerTestData nextTestData = null; |
62 |
long nextTestDataEventAt = 0; |
63 |
for (ConstantThroughputTimerTestData testData : testDataList) { |
64 |
SimulationEvent simulationEvent = testData.peekFirstEvent(); |
65 |
if (simulationEvent != null) { |
66 |
if (nextTestData == null |
67 |
|| simulationEvent.getClockOffset() < nextTestDataEventAt) { |
68 |
nextTestData = testData; |
69 |
nextTestDataEventAt = simulationEvent.getClockOffset(); |
70 |
} |
71 |
} |
72 |
} |
73 |
if (nextTestData != null) { |
74 |
assertTrue("Moving nextTestData to end failed", |
75 |
testDataList.remove(nextTestData)); |
76 |
assertTrue("Moving nextTestData to end failed", |
77 |
testDataList.add(nextTestData)); |
78 |
} |
79 |
return nextTestData; |
80 |
} |
81 |
|
82 |
/** |
83 |
* Run the simulation against the test data list provided. |
84 |
* |
85 |
* @param testDataList |
86 |
* the test data for the simulation |
87 |
* @throws Exception |
88 |
* simulation failures. |
89 |
*/ |
90 |
private void runSimulation( |
91 |
List<ConstantThroughputTimerTestData> testDataList) |
92 |
throws Exception { |
93 |
|
94 |
ConstantThroughputTimerTestData |
95 |
.setupJMeterContextService_numberOfActiveThreads(testDataList); |
96 |
LOG.info("Active Thread Count = " |
97 |
+ JMeterContextService.getNumberOfThreads()); |
98 |
|
99 |
testStarted(testDataList); |
100 |
|
101 |
while (true) { |
102 |
ConstantThroughputTimerTestData nextTestData = getNextEvent(testDataList); |
103 |
if (nextTestData == null) { |
104 |
break; |
105 |
} |
106 |
nextTestData.activate(); |
107 |
|
108 |
SimulationEvent currentEvent = nextTestData.peekFirstEvent(); |
109 |
simulationClock.setOffset(currentEvent.getClockOffset()); |
110 |
|
111 |
long expectedDelay = currentEvent.getDelay(); |
112 |
|
113 |
LOG.info("Invocation at SimulationClock.offset=" |
114 |
+ simulationClock.getOffset() + " expect delay of " |
115 |
+ expectedDelay + " for Test " + nextTestData); |
116 |
long actualDelay = nextTestData.getTimer().delay(); |
117 |
if (actualDelay > 9223300000000000000L) { |
118 |
/* |
119 |
* The above values roughly Double.INFINITY - "current time" |
120 |
* failing to call setThroughput causes a division by zero |
121 |
* (hence INFINITY) but the delay is based on the time as well |
122 |
*/ |
123 |
fail("setThroughput() was not called on test data: " |
124 |
+ nextTestData); |
125 |
} |
126 |
assertEquals("Invocation at " + simulationClock.toString() |
127 |
+ ", for " + nextTestData, expectedDelay, actualDelay); |
128 |
|
129 |
nextTestData.removeFirstEvent(); |
130 |
} |
131 |
|
132 |
testEnded(testDataList); |
133 |
} |
134 |
|
135 |
/** |
136 |
* Sets up the <code>ThroughputInfo.systemClock</code> to be a |
137 |
* <code>SimulationClock</code>. |
138 |
* |
139 |
* @throws Exception |
140 |
* setUp failures |
141 |
*/ |
142 |
@Override |
143 |
protected void setUp() throws Exception { |
144 |
super.setUp(); |
145 |
simulationClock = new SimulationClock(); |
146 |
ThroughputInfo.setSystemClock(simulationClock); |
147 |
|
148 |
ConstantThroughputTimerTestData |
149 |
.setupJMeterContextService_threadContext(); |
150 |
} |
151 |
|
152 |
/** |
153 |
* Resets the <code>ThroughputInfo.systemClock</code> to |
154 |
* <code>ThroughputInfo.SystemClock</code> |
155 |
* |
156 |
* @throws Exception |
157 |
* tearDown failures |
158 |
*/ |
159 |
@Override |
160 |
protected void tearDown() throws Exception { |
161 |
ThroughputInfo.setSystemClock(new ThroughputInfo.SystemClock()); |
162 |
super.tearDown(); |
163 |
} |
164 |
|
165 |
/** |
166 |
* Mode 1 "This Thead Only", In this test threads take |
167 |
* <code>msPerRequest</code> to complete. i.e. on the optimal boundaries. |
168 |
* |
169 |
* @throws Exception |
170 |
* test failures |
171 |
*/ |
172 |
public void testDelayMode1ThisThreadOnly() throws Exception { |
173 |
LOG.info("testDelayMode1ThisThreadOnly"); |
174 |
|
175 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
176 |
testData.setThroughput(12.0); |
177 |
testData.setNumberOfThreadsInThreadGroup(1); |
178 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_1); |
179 |
|
180 |
testData.addEvent(new SimulationEvent(0, 0)); |
181 |
testData.addEvent(new SimulationEvent(5000, 0)); |
182 |
testData.addEvent(new SimulationEvent(10000, 0)); |
183 |
testData.addEvent(new SimulationEvent(15000, 0)); |
184 |
testData.addEvent(new SimulationEvent(20000, 0)); |
185 |
testData.addEvent(new SimulationEvent(25000, 0)); |
186 |
testData.addEvent(new SimulationEvent(30000, 0)); |
187 |
testData.addEvent(new SimulationEvent(35000, 0)); |
188 |
testData.addEvent(new SimulationEvent(40000, 0)); |
189 |
testData.addEvent(new SimulationEvent(45000, 0)); |
190 |
testData.addEvent(new SimulationEvent(50000, 0)); |
191 |
testData.addEvent(new SimulationEvent(55000, 0)); |
192 |
testData.addEvent(new SimulationEvent(60000, 0)); |
193 |
|
194 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
195 |
simulation.add(testData); |
196 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
197 |
|
198 |
runSimulation(simulation); |
199 |
} |
200 |
|
201 |
/** |
202 |
* Mode 2 "All Active Threads", the delay is |
203 |
* <code>msPerRequest * AllActiveThread Count</code>. |
204 |
* |
205 |
* @throws Exception |
206 |
* test failures |
207 |
*/ |
208 |
public void testDelayMode2AllActiveThreads_ManyThreads() throws Exception { |
209 |
LOG.info("testDelayMode2AllActiveThreads_ManyThreads"); |
210 |
|
211 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
212 |
testData.setThroughput(12.0); |
213 |
testData.setNumberOfThreadsInThreadGroup(200); |
214 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_2); |
215 |
|
216 |
testData.addEvent(new SimulationEvent(0, 0)); |
217 |
testData.addEvent(new SimulationEvent(5000 * 200 * 1, 0)); |
218 |
testData.addEvent(new SimulationEvent(5000 * 200 * 2, 0)); |
219 |
testData.addEvent(new SimulationEvent(5000 * 200 * 3, 0)); |
220 |
testData.addEvent(new SimulationEvent(5000 * 200 * 4, 0)); |
221 |
testData.addEvent(new SimulationEvent(5000 * 200 * 5, 0)); |
222 |
|
223 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
224 |
simulation.add(testData); |
225 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
226 |
|
227 |
runSimulation(simulation); |
228 |
} |
229 |
|
230 |
/** |
231 |
* Mode 2 "All Active Threads", the delay is |
232 |
* <code>msPerRequest * AllActiveThread Count</code>, for one thread is the |
233 |
* same as Mode 1. |
234 |
* |
235 |
* @throws Exception |
236 |
* test failures |
237 |
*/ |
238 |
public void testDelayMode2AllActiveThreads_OneThread() throws Exception { |
239 |
LOG.info("testDelayMode2AllActiveThreads_OneThread"); |
240 |
|
241 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
242 |
testData.setThroughput(12.0); |
243 |
testData.setNumberOfThreadsInThreadGroup(1); |
244 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_2); |
245 |
|
246 |
testData.addEvent(new SimulationEvent(0, 0)); |
247 |
testData.addEvent(new SimulationEvent(5000, 0)); |
248 |
testData.addEvent(new SimulationEvent(10000, 0)); |
249 |
testData.addEvent(new SimulationEvent(15000, 0)); |
250 |
testData.addEvent(new SimulationEvent(20000, 0)); |
251 |
testData.addEvent(new SimulationEvent(25000, 0)); |
252 |
testData.addEvent(new SimulationEvent(30000, 0)); |
253 |
testData.addEvent(new SimulationEvent(35000, 0)); |
254 |
testData.addEvent(new SimulationEvent(40000, 0)); |
255 |
testData.addEvent(new SimulationEvent(45000, 0)); |
256 |
testData.addEvent(new SimulationEvent(50000, 0)); |
257 |
testData.addEvent(new SimulationEvent(55000, 0)); |
258 |
testData.addEvent(new SimulationEvent(60000, 0)); |
259 |
|
260 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
261 |
simulation.add(testData); |
262 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
263 |
|
264 |
runSimulation(simulation); |
265 |
} |
266 |
|
267 |
/** |
268 |
* Mode 2 "All Active Threads", the delay is |
269 |
* <code>msPerRequest * AllActiveThread Count</code>. |
270 |
* |
271 |
* @throws Exception |
272 |
* test failures |
273 |
*/ |
274 |
public void testDelayMode2AllActiveThreads_TwoThreads() throws Exception { |
275 |
LOG.info("testDelayMode2AllActiveThreads_TwoThreads"); |
276 |
|
277 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
278 |
testData.setThroughput(12.0); |
279 |
testData.setNumberOfThreadsInThreadGroup(2); |
280 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_2); |
281 |
|
282 |
testData.addEvent(new SimulationEvent(0, 0)); |
283 |
testData.addEvent(new SimulationEvent(10000, 0)); |
284 |
testData.addEvent(new SimulationEvent(20000, 0)); |
285 |
testData.addEvent(new SimulationEvent(30000, 0)); |
286 |
testData.addEvent(new SimulationEvent(40000, 0)); |
287 |
testData.addEvent(new SimulationEvent(50000, 0)); |
288 |
testData.addEvent(new SimulationEvent(60000, 0)); |
289 |
|
290 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
291 |
simulation.add(testData); |
292 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
293 |
|
294 |
runSimulation(simulation); |
295 |
} |
296 |
|
297 |
/** |
298 |
* Mode 3 "All Active Threads in Thread Group", the delay is |
299 |
* <code>msPerRequest * active ThreadsInThreadGroup Count</code>. |
300 |
* |
301 |
* @throws Exception |
302 |
* test failures |
303 |
*/ |
304 |
public void testDelayMode3AllActiveThreadsInThreadGroup_ManyThreads() |
305 |
throws Exception { |
306 |
LOG.info("testDelayMode3AllActiveThreadsInThreadGroup_ManyThreads"); |
307 |
|
308 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
309 |
testData.setThroughput(12.0); |
310 |
testData.setNumberOfThreadsInThreadGroup(200); |
311 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_3); |
312 |
|
313 |
testData.addEvent(new SimulationEvent(0, 0)); |
314 |
testData.addEvent(new SimulationEvent(5000 * 200 * 1, 0)); |
315 |
testData.addEvent(new SimulationEvent(5000 * 200 * 2, 0)); |
316 |
testData.addEvent(new SimulationEvent(5000 * 200 * 3, 0)); |
317 |
testData.addEvent(new SimulationEvent(5000 * 200 * 4, 0)); |
318 |
testData.addEvent(new SimulationEvent(5000 * 200 * 5, 0)); |
319 |
|
320 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
321 |
simulation.add(testData); |
322 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
323 |
|
324 |
runSimulation(simulation); |
325 |
} |
326 |
|
327 |
/** |
328 |
* Mode 3 "All Active Threads in Thread Group", the delay is |
329 |
* <code>msPerRequest * ThreadsInThreadGroup Count</code>. For 1 Thread this |
330 |
* is the same as Mode 1. |
331 |
* |
332 |
* @throws Exception |
333 |
* test failures |
334 |
*/ |
335 |
public void testDelayMode3AllActiveThreadsInThreadGroup_OneThread() |
336 |
throws Exception { |
337 |
LOG.info("testDelayMode3AllActiveThreadsInThreadGroup_OneThread"); |
338 |
|
339 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
340 |
testData.setThroughput(12.0); |
341 |
testData.setNumberOfThreadsInThreadGroup(1); |
342 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_3); |
343 |
|
344 |
testData.addEvent(new SimulationEvent(0, 0)); |
345 |
testData.addEvent(new SimulationEvent(5000, 0)); |
346 |
testData.addEvent(new SimulationEvent(10000, 0)); |
347 |
testData.addEvent(new SimulationEvent(15000, 0)); |
348 |
testData.addEvent(new SimulationEvent(20000, 0)); |
349 |
testData.addEvent(new SimulationEvent(25000, 0)); |
350 |
testData.addEvent(new SimulationEvent(30000, 0)); |
351 |
testData.addEvent(new SimulationEvent(35000, 0)); |
352 |
testData.addEvent(new SimulationEvent(40000, 0)); |
353 |
testData.addEvent(new SimulationEvent(45000, 0)); |
354 |
testData.addEvent(new SimulationEvent(50000, 0)); |
355 |
testData.addEvent(new SimulationEvent(55000, 0)); |
356 |
testData.addEvent(new SimulationEvent(60000, 0)); |
357 |
|
358 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
359 |
simulation.add(testData); |
360 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
361 |
|
362 |
runSimulation(simulation); |
363 |
} |
364 |
|
365 |
/** |
366 |
* Mode 3 "All Active Threads in Thread Group", the delay is |
367 |
* <code>msPerRequest * ThreadsInThreadGroup Count</code>. |
368 |
* |
369 |
* @throws Exception |
370 |
* test failures |
371 |
*/ |
372 |
public void testDelayMode3AllActiveThreadsInThreadGroup_TwoThreads() |
373 |
throws Exception { |
374 |
LOG.info("testDelayMode3AllActiveThreadsInThreadGroup_TwoThreads"); |
375 |
|
376 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
377 |
testData.setThroughput(12.0); |
378 |
testData.setNumberOfThreadsInThreadGroup(2); |
379 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_3); |
380 |
|
381 |
testData.addEvent(new SimulationEvent(0, 0)); |
382 |
testData.addEvent(new SimulationEvent(10000, 0)); |
383 |
testData.addEvent(new SimulationEvent(20000, 0)); |
384 |
testData.addEvent(new SimulationEvent(30000, 0)); |
385 |
testData.addEvent(new SimulationEvent(40000, 0)); |
386 |
testData.addEvent(new SimulationEvent(50000, 0)); |
387 |
testData.addEvent(new SimulationEvent(60000, 0)); |
388 |
|
389 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
390 |
simulation.add(testData); |
391 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
392 |
|
393 |
runSimulation(simulation); |
394 |
} |
395 |
|
396 |
/** |
397 |
* Mode 4 "All Active Threads (Shared)", the delay is a constant |
398 |
* <code>msPerRequest</code> but each thread shares the |
399 |
* <code>previousTime</code> a request was invoked. |
400 |
* |
401 |
* @throws Exception |
402 |
* test failures |
403 |
*/ |
404 |
public void testDelayMode4AllActiveThreadsShared_OneThread() |
405 |
throws Exception { |
406 |
LOG.info("testDelayMode4AllActiveThreadsShared"); |
407 |
|
408 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
409 |
testData.setThroughput(12.0); |
410 |
testData.setNumberOfThreadsInThreadGroup(1); |
411 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_4); |
412 |
|
413 |
testData.addEvent(new SimulationEvent(0, 0)); |
414 |
testData.addEvent(new SimulationEvent(5000, 0)); |
415 |
testData.addEvent(new SimulationEvent(10000, 0)); |
416 |
testData.addEvent(new SimulationEvent(15000, 0)); |
417 |
testData.addEvent(new SimulationEvent(20000, 0)); |
418 |
testData.addEvent(new SimulationEvent(25000, 0)); |
419 |
testData.addEvent(new SimulationEvent(30000, 0)); |
420 |
testData.addEvent(new SimulationEvent(35000, 0)); |
421 |
testData.addEvent(new SimulationEvent(40000, 0)); |
422 |
testData.addEvent(new SimulationEvent(45000, 0)); |
423 |
testData.addEvent(new SimulationEvent(50000, 0)); |
424 |
testData.addEvent(new SimulationEvent(55000, 0)); |
425 |
testData.addEvent(new SimulationEvent(60000, 0)); |
426 |
|
427 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
428 |
simulation.add(testData); |
429 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
430 |
|
431 |
runSimulation(simulation); |
432 |
} |
433 |
|
434 |
/** |
435 |
* Mode 5 "All Active Threads In Thread Group(Shared)", the delay is a |
436 |
* constant <code>msPerRequest</code> but each thread in the thread group |
437 |
* shares the <code>previousTime</code> a request was invoked. |
438 |
* |
439 |
* @throws Exception |
440 |
* test failures |
441 |
*/ |
442 |
public void testDelayMode5AllActiveThreadsInThreadGroupShared_OneThread() |
443 |
throws Exception { |
444 |
LOG.info("testDelayMode5AllActiveThreadsInThreadGroupShared"); |
445 |
|
446 |
ConstantThroughputTimerTestData testData = new ConstantThroughputTimerTestData(); |
447 |
testData.setThroughput(12.0); |
448 |
testData.setNumberOfThreadsInThreadGroup(1); |
449 |
testData.setCalcMode(ConstantThroughputTimerTestData.CALC_MODE_5); |
450 |
|
451 |
testData.addEvent(new SimulationEvent(0, 0)); |
452 |
testData.addEvent(new SimulationEvent(5000, 0)); |
453 |
testData.addEvent(new SimulationEvent(10000, 0)); |
454 |
testData.addEvent(new SimulationEvent(15000, 0)); |
455 |
testData.addEvent(new SimulationEvent(20000, 0)); |
456 |
testData.addEvent(new SimulationEvent(25000, 0)); |
457 |
testData.addEvent(new SimulationEvent(30000, 0)); |
458 |
testData.addEvent(new SimulationEvent(35000, 0)); |
459 |
testData.addEvent(new SimulationEvent(40000, 0)); |
460 |
testData.addEvent(new SimulationEvent(45000, 0)); |
461 |
testData.addEvent(new SimulationEvent(50000, 0)); |
462 |
testData.addEvent(new SimulationEvent(55000, 0)); |
463 |
testData.addEvent(new SimulationEvent(60000, 0)); |
464 |
|
465 |
List<ConstantThroughputTimerTestData> simulation = new ArrayList<ConstantThroughputTimerTestData>(); |
466 |
simulation.add(testData); |
467 |
ConstantThroughputTimerTestData.createAdditionalThreads(simulation); |
468 |
|
469 |
runSimulation(simulation); |
470 |
} |
471 |
|
472 |
/** |
473 |
* Notify all the timers in the list of test data that the tests have ended. |
474 |
* |
475 |
* @param testDataList |
476 |
* varargs list of test data to notify |
477 |
*/ |
478 |
private void testEnded(List<ConstantThroughputTimerTestData> testDataList) { |
479 |
for (ConstantThroughputTimerTestData testData : testDataList) { |
480 |
testData.getTimer().testEnded(); |
481 |
} |
482 |
} |
483 |
|
484 |
/** |
485 |
* Test Mode 1 timers from simulation file simulator_mode1.txt |
486 |
* |
487 |
* @throws Exception |
488 |
* test failures |
489 |
*/ |
490 |
public void testMode1Timers() throws Exception { |
491 |
ConstantThroughPutTimerSimulation simulation = new ConstantThroughPutTimerSimulation(); |
492 |
List<ConstantThroughputTimerTestData> testDataList = simulation |
493 |
.loadSimulationFile("org/apache/jmeter/timers/simulator_mode1.txt"); |
494 |
|
495 |
runSimulation(testDataList); |
496 |
} |
497 |
|
498 |
/** |
499 |
* Test Mode 2 timers from simulation file simulator_mode2.txt |
500 |
* |
501 |
* @throws Exception |
502 |
* test failures |
503 |
*/ |
504 |
public void testMode2Timers() throws Exception { |
505 |
ConstantThroughPutTimerSimulation simulation = new ConstantThroughPutTimerSimulation(); |
506 |
List<ConstantThroughputTimerTestData> testDataList = simulation |
507 |
.loadSimulationFile("org/apache/jmeter/timers/simulator_mode2.txt"); |
508 |
|
509 |
runSimulation(testDataList); |
510 |
} |
511 |
|
512 |
/** |
513 |
* Test Mode 3 timers from simulation file simulator_mode3.txt |
514 |
* |
515 |
* @throws Exception |
516 |
* test failures |
517 |
*/ |
518 |
public void testMode3Timers() throws Exception { |
519 |
ConstantThroughPutTimerSimulation simulation = new ConstantThroughPutTimerSimulation(); |
520 |
List<ConstantThroughputTimerTestData> testDataList = simulation |
521 |
.loadSimulationFile("org/apache/jmeter/timers/simulator_mode3.txt"); |
522 |
|
523 |
runSimulation(testDataList); |
524 |
} |
525 |
|
526 |
/** |
527 |
* Test Mode 4 timers from simulation file simulator_mode4.txt |
528 |
* |
529 |
* @throws Exception |
530 |
* test failures |
531 |
*/ |
532 |
public void testMode4Timers() throws Exception { |
533 |
ConstantThroughPutTimerSimulation simulation = new ConstantThroughPutTimerSimulation(); |
534 |
List<ConstantThroughputTimerTestData> testDataList = simulation |
535 |
.loadSimulationFile("org/apache/jmeter/timers/simulator_mode4.txt"); |
536 |
|
537 |
runSimulation(testDataList); |
538 |
} |
539 |
|
540 |
/** |
541 |
* Test Mode 5 timers from simulation file simulator_mode5.txt |
542 |
* |
543 |
* @throws Exception |
544 |
* test failures |
545 |
*/ |
546 |
public void testMode5Timers() throws Exception { |
547 |
ConstantThroughPutTimerSimulation simulation = new ConstantThroughPutTimerSimulation(); |
548 |
List<ConstantThroughputTimerTestData> testDataList = simulation |
549 |
.loadSimulationFile("org/apache/jmeter/timers/simulator_mode5.txt"); |
550 |
|
551 |
runSimulation(testDataList); |
552 |
} |
553 |
|
554 |
/** |
555 |
* Notify all the timers in the list of test data that the tests are |
556 |
* starting. |
557 |
* |
558 |
* @param testDataList |
559 |
* list of test data to notify |
560 |
*/ |
561 |
private void testStarted(List<ConstantThroughputTimerTestData> testDataList) { |
562 |
for (ConstantThroughputTimerTestData testData : testDataList) { |
563 |
testData.activate(); |
564 |
testData.getTimer().testStarted(); |
565 |
} |
566 |
} |
567 |
} |
568 |
|
569 |
/** |
570 |
* JMeter depends on commons-lang:2.4. These methods are copied from 2.5 |
571 |
* |
572 |
* TODO: Delete when dependency upgraded. |
573 |
*/ |
574 |
class Copy_Commons_Lang_2_5_Reflect { |
575 |
public static Field getDeclaredField(Class<?> cls, String fieldName, |
576 |
boolean forceAccess) { |
577 |
if (cls == null) { |
578 |
throw new IllegalArgumentException("The class must not be null"); |
579 |
} |
580 |
if (fieldName == null) { |
581 |
throw new IllegalArgumentException( |
582 |
"The field name must not be null"); |
583 |
} |
584 |
try { |
585 |
// only consider the specified class by using getDeclaredField() |
586 |
Field field = cls.getDeclaredField(fieldName); |
587 |
field.setAccessible(true); |
588 |
return field; |
589 |
} catch (NoSuchFieldException e) { |
590 |
} |
591 |
return null; |
592 |
} |
593 |
|
594 |
public static void writeDeclaredStaticField(Class<?> cls, String fieldName, |
595 |
Object value, boolean forceAccess) throws IllegalAccessException { |
596 |
Field field = getDeclaredField(cls, fieldName, forceAccess); |
597 |
if (field == null) { |
598 |
throw new IllegalArgumentException("Cannot locate declared field " |
599 |
+ cls.getName() + "." + fieldName); |
600 |
} |
601 |
// already forced access above, don't repeat it here: |
602 |
writeField(field, (Object) null, value, false); |
603 |
} |
604 |
|
605 |
public static void writeField(Field field, Object target, Object value, |
606 |
boolean forceAccess) throws IllegalAccessException { |
607 |
if (field == null) { |
608 |
throw new IllegalArgumentException("The field must not be null"); |
609 |
} |
610 |
field.set(target, value); |
611 |
} |
612 |
} |