1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.util;
20
21 import org.apache.hadoop.hbase.testclassification.MediumTests;
22 import org.junit.Test;
23 import org.junit.experimental.categories.Category;
24
25 import static junit.framework.Assert.assertTrue;
26 import static junit.framework.Assert.fail;
27
28
29
30
31
32 @Category(MediumTests.class)
33 public class TestDefaultEnvironmentEdge {
34
35 @Test
36 public void testGetCurrentTimeUsesSystemClock() {
37 DefaultEnvironmentEdge edge = new DefaultEnvironmentEdge();
38 long systemTime = System.currentTimeMillis();
39 long edgeTime = edge.currentTimeMillis();
40 assertTrue("System time must be either the same or less than the edge time",
41 systemTime < edgeTime || systemTime == edgeTime);
42 try {
43 Thread.sleep(1);
44 } catch (InterruptedException e) {
45 fail(e.getMessage());
46 }
47 long secondEdgeTime = edge.currentTimeMillis();
48 assertTrue("Second time must be greater than the first",
49 secondEdgeTime > edgeTime);
50 }
51
52
53 }
54