1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util;
19
20 import java.io.IOException;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseTestingUtility;
26 import org.apache.hadoop.hbase.Server;
27 import org.apache.hadoop.hbase.ServerName;
28 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
29 import org.apache.hadoop.hbase.catalog.CatalogTracker;
30 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
31
32
33
34
35 public class MockServer implements Server {
36 static final Log LOG = LogFactory.getLog(MockServer.class);
37 final static ServerName NAME = ServerName.valueOf("MockServer", 123, -1);
38
39 boolean stopped;
40 boolean aborted;
41 final ZooKeeperWatcher zk;
42 final HBaseTestingUtility htu;
43
44 @SuppressWarnings("unused")
45 public MockServer() throws ZooKeeperConnectionException, IOException {
46
47 this(null);
48 }
49
50 public MockServer(final HBaseTestingUtility htu)
51 throws ZooKeeperConnectionException, IOException {
52 this(htu, true);
53 }
54
55
56
57
58
59
60
61 public MockServer(final HBaseTestingUtility htu, final boolean zkw)
62 throws ZooKeeperConnectionException, IOException {
63 this.htu = htu;
64 this.zk = zkw?
65 new ZooKeeperWatcher(htu.getConfiguration(), NAME.toString(), this, true):
66 null;
67 }
68
69 @Override
70 public void abort(String why, Throwable e) {
71 LOG.fatal("Abort why=" + why, e);
72 stop(why);
73 this.aborted = true;
74 }
75
76 @Override
77 public void stop(String why) {
78 LOG.debug("Stop why=" + why);
79 this.stopped = true;
80 }
81
82 @Override
83 public boolean isStopped() {
84 return this.stopped;
85 }
86
87 @Override
88 public Configuration getConfiguration() {
89 return this.htu.getConfiguration();
90 }
91
92 @Override
93 public ZooKeeperWatcher getZooKeeper() {
94 return this.zk;
95 }
96
97 @Override
98 public CatalogTracker getCatalogTracker() {
99 return null;
100 }
101
102 @Override
103 public ServerName getServerName() {
104 return NAME;
105 }
106
107 @Override
108 public boolean isAborted() {
109
110 return this.aborted;
111 }
112 }