1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.master;
21
22 import java.net.InetAddress;
23
24 import junit.framework.Assert;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.conf.Configuration;
29 import org.apache.hadoop.hbase.ClockOutOfSyncException;
30 import org.apache.hadoop.hbase.HBaseConfiguration;
31 import org.apache.hadoop.hbase.Server;
32 import org.apache.hadoop.hbase.ServerName;
33 import org.apache.hadoop.hbase.catalog.CatalogTracker;
34 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
35 import org.junit.Test;
36
37
38 public class TestClockSkewDetection {
39 private static final Log LOG =
40 LogFactory.getLog(TestClockSkewDetection.class);
41
42 @Test
43 public void testClockSkewDetection() throws Exception {
44 final Configuration conf = HBaseConfiguration.create();
45 ServerManager sm = new ServerManager(new Server() {
46 @Override
47 public CatalogTracker getCatalogTracker() {
48 return null;
49 }
50
51 @Override
52 public Configuration getConfiguration() {
53 return conf;
54 }
55
56 @Override
57 public ServerName getServerName() {
58 return null;
59 }
60
61 @Override
62 public ZooKeeperWatcher getZooKeeper() {
63 return null;
64 }
65
66 @Override
67 public void abort(String why, Throwable e) {}
68
69 @Override
70 public boolean isAborted() {
71 return false;
72 }
73
74 @Override
75 public boolean isStopped() {
76 return false;
77 }
78
79 @Override
80 public void stop(String why) {
81 }}, null, false);
82
83 LOG.debug("regionServerStartup 1");
84 InetAddress ia1 = InetAddress.getLocalHost();
85 sm.regionServerStartup(ia1, 1234, -1, System.currentTimeMillis());
86
87 long maxSkew = 30000;
88
89 try {
90 LOG.debug("regionServerStartup 2");
91 InetAddress ia2 = InetAddress.getLocalHost();
92 sm.regionServerStartup(ia2, 1235, -1, System.currentTimeMillis() - maxSkew * 2);
93 Assert.assertTrue("HMaster should have thrown an ClockOutOfSyncException "
94 + "but didn't.", false);
95 } catch(ClockOutOfSyncException e) {
96
97 LOG.info("Recieved expected exception: "+e);
98 }
99 }
100 }