/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter.control;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.junit.stubs.TestSampler;
import org.apache.jmeter.samplers.Sampler;
import org.junit.Test;
/**
 * @version $Revision$
 */
public class TestRunTime extends JMeterTestCase {

    @Test
        public void testProcessing() throws Exception {

            RunTime controller = new RunTime();
            controller.setRuntime(10);
            TestSampler samp1 = new TestSampler("Sample 1", 500);
            TestSampler samp2 = new TestSampler("Sample 2", 480);

            LoopController sub1 = new LoopController();
            sub1.setLoops(2);
            sub1.setContinueForever(false);
            sub1.addTestElement(samp1);

            LoopController sub2 = new LoopController();
            sub2.setLoops(40);
            sub2.setContinueForever(false);
            sub2.addTestElement(samp2);
            controller.addTestElement(sub1);
            controller.addTestElement(sub2);
            controller.setRunningVersion(true);
            sub1.setRunningVersion(true);
            sub2.setRunningVersion(true);
            controller.initialize();
            Sampler sampler = null;
            int loops = 0;
            long now = System.currentTimeMillis();
            while ((sampler = controller.next()) != null) {
                loops++;
                sampler.sample(null);
            }
            long elapsed = System.currentTimeMillis() - now;
            assertTrue("Should be at least 20 loops "+loops, loops >= 20);
            assertTrue("Should be fewer than 30 loops "+loops, loops < 30);
            assertTrue("Should take at least 10 seconds "+elapsed, elapsed >= 10000);
            assertTrue("Should take less than 12 seconds "+elapsed, elapsed <= 12000);
            assertEquals("Sampler 1 should run 2 times", 2, samp1.getSamples());
            assertTrue("Sampler 2 should run >= 18 times", samp2.getSamples() >= 18);
        }
}

@@ -1090,35 +1090,13 @@
 st;%0A
+%0A
 /**%0A
- * @version $Revision$%0A
  */%0A
@@ -1156,20 +1156,16 @@
   @Test%0A
-    
     publ
@@ -1217,20 +1217,16 @@
         
-    
 RunTime 
@@ -1253,36 +1253,32 @@
 Time();%0A        
- 
-   
 controller.setRu
@@ -1284,28 +1284,24 @@
 untime(10);%0A
-    
         Test
@@ -1354,28 +1354,24 @@
 0);%0A        
-  
-  
 TestSampler 
@@ -1413,36 +1413,32 @@
  480);%0A%0A        
-    
 LoopController s
@@ -1465,36 +1465,32 @@
 ller();%0A        
-   
- 
 sub1.setLoops(2)
@@ -1487,28 +1487,24 @@
 etLoops(2);%0A
-    
         sub1
@@ -1523,36 +1523,32 @@
 Forever(false);%0A
-    
         sub1.add
@@ -1572,28 +1572,24 @@
 );%0A%0A        
-    
 LoopControll
@@ -1620,36 +1620,32 @@
 ller();%0A        
-    
 sub2.setLoops(40
@@ -1647,36 +1647,32 @@
 ps(40);%0A        
- 
-   
 sub2.setContinue
@@ -1691,28 +1691,24 @@
 e);%0A        
-    
 sub2.addTest
@@ -1723,36 +1723,32 @@
 samp2);%0A        
-  
-  
 controller.addTe
@@ -1764,36 +1764,32 @@
 (sub1);%0A        
-   
- 
 controller.addTe
@@ -1805,36 +1805,32 @@
 (sub2);%0A        
-   
- 
 controller.setRu
@@ -1853,28 +1853,24 @@
 e);%0A        
-    
 sub1.setRunn
@@ -1879,36 +1879,32 @@
 gVersion(true);%0A
-    
         sub2.set
@@ -1929,28 +1929,24 @@
 e);%0A        
-    
 controller.i
@@ -1966,20 +1966,16 @@
         
-    
 Sampler 
@@ -1998,20 +1998,16 @@
         
- 
-   
 int loop
@@ -2013,20 +2013,16 @@
 ps = 0;%0A
-    
         
@@ -2068,20 +2068,16 @@
         
-  
-  
 while ((
@@ -2128,20 +2128,16 @@
         
-    
 loops++;
@@ -2149,20 +2149,16 @@
         
-   
- 
 sampler.
@@ -2183,18 +2183,10 @@
     
-    %7D%0A    
+%7D%0A
     
@@ -2238,36 +2238,32 @@
  - now;%0A        
-    
 assertTrue(%22Shou
@@ -2279,33 +2279,35 @@
 least 20 loops %22
-+
+ + 
 loops, loops %3E= 
@@ -2311,36 +2311,32 @@
 %3E= 20);%0A        
-   
- 
 assertTrue(%22Shou
@@ -2362,17 +2362,19 @@
  loops %22
-+
+ + 
 loops, l
@@ -2385,36 +2385,32 @@
  %3C 30);%0A        
-  
-  
 assertTrue(%22Shou
@@ -2430,33 +2430,35 @@
 ast 10 seconds %22
-+
+ + 
 elapsed, elapsed
@@ -2469,36 +2469,32 @@
 10000);%0A        
-    
 assertTrue(%22Shou
@@ -2523,17 +2523,19 @@
 econds %22
-+
+ + 
 elapsed,
@@ -2558,28 +2558,24 @@
 0);%0A        
-   
- 
 assertEquals
@@ -2631,20 +2631,16 @@
 les());%0A
-    
         
@@ -2713,20 +2713,16 @@
 %3E= 18);%0A
-    
     %7D%0A%7D%0A

Format and remove @version