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 junit.framework.Assert;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.ClockOutOfSyncException;
28 import org.apache.hadoop.hbase.HBaseConfiguration;
29 import org.apache.hadoop.hbase.HServerAddress;
30 import org.apache.hadoop.hbase.HServerInfo;
31 import org.apache.hadoop.hbase.Server;
32 import org.apache.hadoop.hbase.catalog.CatalogTracker;
33 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
34 import org.junit.Test;
35
36
37 public class TestClockSkewDetection {
38 private static final Log LOG =
39 LogFactory.getLog(TestClockSkewDetection.class);
40
41 @Test
42 public void testClockSkewDetection() throws Exception {
43 final Configuration conf = HBaseConfiguration.create();
44 ServerManager sm = new ServerManager(new Server() {
45 @Override
46 public CatalogTracker getCatalogTracker() {
47 return null;
48 }
49
50 @Override
51 public Configuration getConfiguration() {
52 return conf;
53 }
54
55 @Override
56 public String getServerName() {
57 return null;
58 }
59
60 @Override
61 public ZooKeeperWatcher getZooKeeper() {
62 return null;
63 }
64
65 @Override
66 public void abort(String why, Throwable e) {}
67
68 @Override
69 public boolean isStopped() {
70 return false;
71 }
72
73 @Override
74 public void stop(String why) {
75 }}, null, null);
76
77 LOG.debug("regionServerStartup 1");
78 HServerInfo hsi1 = new HServerInfo(new HServerAddress("example.org:1234"),
79 System.currentTimeMillis(), -1, "example.com");
80 sm.regionServerStartup(hsi1, System.currentTimeMillis());
81
82 long maxSkew = 30000;
83
84 try {
85 LOG.debug("regionServerStartup 2");
86 HServerInfo hsi2 = new HServerInfo(new HServerAddress("example.org:1235"),
87 System.currentTimeMillis(), -1, "example.com");
88 sm.regionServerStartup(hsi2, System.currentTimeMillis() - maxSkew * 2);
89 Assert.assertTrue("HMaster should have thrown an ClockOutOfSyncException "
90 + "but didn't.", false);
91 } catch(ClockOutOfSyncException e) {
92
93 LOG.info("Recieved expected exception: "+e);
94 }
95 }
96 }