1 package org.e2etrace.timer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.e2etrace.timer.DefaultTimerFactory;
20 import org.e2etrace.timer.ExactTimer;
21 import org.e2etrace.timer.ITimer;
22
23 import junit.framework.TestCase;
24
25
26
27
28
29
30
31 public class ExactTimerTest extends TestCase {
32
33 public static void main(String[] args) {
34 junit.textui.TestRunner.run(ExactTimerTest.class);
35 }
36
37
38
39
40
41
42 public void testGetDuration() throws InterruptedException {
43 DefaultTimerFactory tf = new DefaultTimerFactory(ExactTimer.class);
44 ITimer timer;
45 long duration;
46
47
48
49 timer = tf.newInstance();
50
51 assertEquals(timer.getClass(), ExactTimer.class);
52
53 timer.start();
54 Thread.sleep(100);
55 duration = timer.measure();
56
57 assertTrue("Expected duration: between 90ms and 110ms, measured duration: "
58 + duration + "ms", duration >= 90 && duration <= 110);
59
60
61
62 timer = tf.newInstance();
63 assertEquals(-1, timer.measure());
64
65 }
66
67 }