Line 0
Link Here
|
0 |
- |
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 org.apache.jmeter.threads.JMeterContext |
22 |
import org.apache.jmeter.threads.JMeterContextService |
23 |
import org.apache.jmeter.threads.JMeterThread |
24 |
|
25 |
import spock.lang.Specification |
26 |
|
27 |
class SyncTimerSpec extends Specification { |
28 |
|
29 |
def "timer with scheduled end point"() { |
30 |
setup: |
31 |
def timer = new SyncTimer() |
32 |
def context = Stub(JMeterContext) |
33 |
def thread = Stub(JMeterThread) |
34 |
|
35 |
thread.getEndTime() >> System.currentTimeMillis() + 100L |
36 |
context.getThread() >> thread |
37 |
|
38 |
JMeterContextService.replaceContext(context) |
39 |
timer.groupSize = 2 |
40 |
timer.testStarted() |
41 |
when: |
42 |
def start = System.currentTimeMillis(); |
43 |
def delay = timer.delay() |
44 |
def elapsed = System.currentTimeMillis() - start |
45 |
then: |
46 |
delay == 0 |
47 |
elapsed < 10 * 100L |
48 |
} |
49 |
|
50 |
def "timer with scheduled end point and shorter max timeout in ms"() { |
51 |
setup: |
52 |
def timer = new SyncTimer() |
53 |
timer.setTimeoutInMs(100L) |
54 |
def context = Stub(JMeterContext) |
55 |
def thread = Stub(JMeterThread) |
56 |
|
57 |
thread.getEndTime() >> System.currentTimeMillis() + 2000L |
58 |
context.getThread() >> thread |
59 |
|
60 |
JMeterContextService.replaceContext(context) |
61 |
timer.groupSize = 2 |
62 |
timer.testStarted() |
63 |
when: |
64 |
def start = System.currentTimeMillis(); |
65 |
def delay = timer.delay() |
66 |
def elapsed = System.currentTimeMillis() - start |
67 |
then: |
68 |
delay == 0 |
69 |
elapsed < 10 * 100L |
70 |
} |
71 |
|
72 |
def "timer with scheduled end point and longer max timeout in ms"() { |
73 |
setup: |
74 |
def timer = new SyncTimer() |
75 |
timer.setTimeoutInMs(2000L) |
76 |
def context = Stub(JMeterContext) |
77 |
def thread = Stub(JMeterThread) |
78 |
|
79 |
thread.getEndTime() >> System.currentTimeMillis() + 100L |
80 |
context.getThread() >> thread |
81 |
|
82 |
JMeterContextService.replaceContext(context) |
83 |
timer.groupSize = 2 |
84 |
timer.testStarted() |
85 |
when: |
86 |
def start = System.currentTimeMillis(); |
87 |
def delay = timer.delay() |
88 |
def elapsed = System.currentTimeMillis() - start |
89 |
then: |
90 |
delay == 0 |
91 |
elapsed < 10 * 100L |
92 |
} |
93 |
|
94 |
} |