View Javadoc

1   package org.e2etrace.trace;
2   
3   /*
4    * Copyright 2006 Gunther Popp
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.e2etrace.trace.DefaultTraceStepFactory;
20  import org.e2etrace.trace.ITraceStep;
21  import org.e2etrace.trace.ITraceStepFactory;
22  import org.e2etrace.trace.SimpleTraceStepId;
23  import org.e2etrace.trace.TraceSessionRootStep;
24  import org.e2etrace.trace.TraceSessionRootStepId;
25  
26  import junit.framework.TestCase;
27  
28  /**
29   * JUnit testcase for {@link org.e2etrace.trace.TraceSessionRootStep}
30   *
31   * @author Gunther Popp
32   *
33   */
34  public class TraceSessionRootStepTest extends TestCase {
35  
36    public static void main(String[] args) {
37      junit.textui.TestRunner.run(TraceSessionRootStepTest.class);
38    }
39  
40    /**
41     * Tests <code>getAccumulatedDuration</code> and <code>getDuration</code>.
42     *
43     */
44    public void testDurations() {
45      TraceSessionRootStep root;
46      ITraceStep step1, step2;
47      ITraceStepFactory factory;
48  
49      factory = new DefaultTraceStepFactory(new MockTimerFactory(new long[] { 10, 20 }));
50      step1 = factory.newInstance(new SimpleTraceStepId("1"));
51      step2 = factory.newInstance(new SimpleTraceStepId("2"));
52  
53      step1.enter();
54      step1.leave();
55  
56      step2.enter();
57      step2.leave();
58  
59      root = new TraceSessionRootStep(new TraceSessionRootStepId("root"));
60  
61      root.addChild(step1);
62      root.addChild(step2);
63  
64      // Test, if the accumulated duration of the root step matches the summed up
65      // durations of the childs
66      assertEquals(30, root.getDuration());
67  
68      // Test, if the duration of the root step is always 0
69      assertEquals(0, root.getIsolatedDuration());
70    }
71  
72  }