Lines 18-24
Link Here
|
18 |
|
18 |
|
19 |
package org.apache.jmeter.threads; |
19 |
package org.apache.jmeter.threads; |
20 |
|
20 |
|
|
|
21 |
import static org.junit.Assert.assertFalse; |
22 |
import static org.junit.Assert.assertTrue; |
23 |
|
24 |
import java.util.Date; |
25 |
|
26 |
import org.apache.jmeter.control.LoopController; |
27 |
import org.apache.jmeter.samplers.AbstractSampler; |
28 |
import org.apache.jmeter.samplers.Entry; |
29 |
import org.apache.jmeter.samplers.SampleResult; |
21 |
import org.apache.jmeter.testelement.ThreadListener; |
30 |
import org.apache.jmeter.testelement.ThreadListener; |
|
|
31 |
import org.apache.jmeter.timers.ConstantTimer; |
22 |
import org.apache.jorphan.collections.HashTree; |
32 |
import org.apache.jorphan.collections.HashTree; |
23 |
import org.junit.Test; |
33 |
import org.junit.Test; |
24 |
|
34 |
|
Lines 26-31
Link Here
|
26 |
* Tests for {@link JMeterThread} |
36 |
* Tests for {@link JMeterThread} |
27 |
*/ |
37 |
*/ |
28 |
public class TestJMeterThread { |
38 |
public class TestJMeterThread { |
|
|
39 |
|
40 |
private static final class DummySampler extends AbstractSampler { |
41 |
private static final long serialVersionUID = 1L; |
42 |
private boolean called = false; |
43 |
|
44 |
public boolean isCalled() { |
45 |
return called; |
46 |
} |
47 |
|
48 |
@Override |
49 |
public SampleResult sample(Entry e) { |
50 |
called = true; |
51 |
return null; |
52 |
} |
53 |
|
54 |
@Override |
55 |
public int hashCode() { |
56 |
final int prime = 31; |
57 |
int result = super.hashCode(); |
58 |
result = prime * result + (called ? 1231 : 1237); |
59 |
return result; |
60 |
} |
61 |
|
62 |
@Override |
63 |
public boolean equals(Object obj) { |
64 |
if (this == obj) |
65 |
return true; |
66 |
if (!super.equals(obj)) |
67 |
return false; |
68 |
if (getClass() != obj.getClass()) |
69 |
return false; |
70 |
DummySampler other = (DummySampler) obj; |
71 |
return called == other.called; |
72 |
} |
73 |
|
74 |
} |
75 |
|
29 |
private static class ThrowingThreadListener implements ThreadListener { |
76 |
private static class ThrowingThreadListener implements ThreadListener { |
30 |
|
77 |
|
31 |
private boolean throwError; |
78 |
private boolean throwError; |
Lines 71-75
Link Here
|
71 |
new JMeterThread.ThreadListenerTraverser(true); |
118 |
new JMeterThread.ThreadListenerTraverser(true); |
72 |
hashTree.traverse(traverser); |
119 |
hashTree.traverse(traverser); |
73 |
} |
120 |
} |
74 |
|
121 |
|
|
|
122 |
@Test |
123 |
public void testBug63490EndTestWhenDelayIsTooLongForScheduler() { |
124 |
|
125 |
JMeterContextService.getContext().setVariables(new JMeterVariables()); |
126 |
|
127 |
HashTree testTree = new HashTree(); |
128 |
LoopController samplerController = createLoopController(); |
129 |
testTree.add(samplerController); |
130 |
testTree.add(samplerController, createConstantTimer("3000")); |
131 |
DummySampler dummySampler = createSampler(); |
132 |
testTree.add(samplerController, dummySampler); |
133 |
|
134 |
TestCompiler compiler = new TestCompiler(testTree); |
135 |
testTree.traverse(compiler); |
136 |
|
137 |
ThreadGroup threadGroup = new ThreadGroup(); |
138 |
threadGroup.setNumThreads(1); |
139 |
long maxDuration = 2000l; |
140 |
threadGroup.setDuration(maxDuration); |
141 |
|
142 |
JMeterThread jMeterThread = new JMeterThread(testTree, threadGroup, null); |
143 |
jMeterThread.setScheduled(true); |
144 |
jMeterThread.setEndTime(System.currentTimeMillis() + maxDuration); |
145 |
jMeterThread.setThreadGroup(threadGroup); |
146 |
long startTime = new Date().getTime(); |
147 |
jMeterThread.run(); |
148 |
long duration = new Date().getTime() - startTime; |
149 |
|
150 |
assertFalse("Sampler should not be called", dummySampler.isCalled()); |
151 |
|
152 |
// the duration of this test plan should currently be around zero seconds, |
153 |
// but it is allowed to take up to maxDuration amount of time |
154 |
assertTrue("Test plan should not run for longer than duration", duration <= maxDuration); |
155 |
} |
156 |
|
157 |
private LoopController createLoopController() { |
158 |
LoopController result = new LoopController(); |
159 |
result.setLoops(LoopController.INFINITE_LOOP_COUNT); |
160 |
result.setEnabled(true); |
161 |
return result; |
162 |
} |
163 |
|
164 |
private DummySampler createSampler() { |
165 |
DummySampler result = new DummySampler(); |
166 |
result.setName("Call me"); |
167 |
return result; |
168 |
} |
169 |
|
170 |
private ConstantTimer createConstantTimer(String delay) { |
171 |
ConstantTimer constantTimer = new ConstantTimer(); |
172 |
constantTimer.setEnabled(true); |
173 |
constantTimer.setDelay(delay); |
174 |
constantTimer.setName("Long delay"); |
175 |
return constantTimer; |
176 |
} |
75 |
} |
177 |
} |