01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.control;
20:
21: import org.apache.jmeter.junit.JMeterTestCase;
22: import org.apache.jmeter.junit.stubs.TestSampler;
23: import org.apache.jmeter.samplers.Sampler;
24:
25: /**
26: * @version $Revision: 493796 $
27: */
28: public class TestRunTime extends JMeterTestCase {
29: public TestRunTime(String name) {
30: super (name);
31: }
32:
33: public void testProcessing() throws Exception {
34:
35: RunTime controller = new RunTime();
36: controller.setRuntime(10);
37: TestSampler samp1 = new TestSampler("Sample 1", 500);
38: TestSampler samp2 = new TestSampler("Sample 2", 490);
39:
40: LoopController sub1 = new LoopController();
41: sub1.setLoops(2);
42: sub1.setContinueForever(false);
43: sub1.addTestElement(samp1);
44:
45: LoopController sub2 = new LoopController();
46: sub2.setLoops(40);
47: sub2.setContinueForever(false);
48: sub2.addTestElement(samp2);
49: controller.addTestElement(sub1);
50: controller.addTestElement(sub2);
51: controller.setRunningVersion(true);
52: sub1.setRunningVersion(true);
53: sub2.setRunningVersion(true);
54: controller.initialize();
55: Sampler sampler = null;
56: int loops = 0;
57: long now = System.currentTimeMillis();
58: while ((sampler = controller.next()) != null) {
59: loops++;
60: sampler.sample(null);
61: }
62: long elapsed = System.currentTimeMillis() - now;
63: assertTrue("Should be at least 20 loops " + loops, loops >= 20);
64: assertTrue("Should be fewer than 30 loops " + loops, loops < 30);
65: assertTrue("Should take at least 10 seconds " + elapsed,
66: elapsed >= 10000);
67: assertTrue("Should take less than 12 seconds " + elapsed,
68: elapsed <= 12000);
69: assertEquals("Sampler 1 should run 2 times", 2, samp1
70: .getSamples());
71: assertTrue("Sampler 2 should run >= 18 times", samp2
72: .getSamples() >= 18);
73: }
74: }
|