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.ChoreService;
26 import org.apache.hadoop.hbase.CoordinatedStateManager;
27 import org.apache.hadoop.hbase.HBaseTestingUtility;
28 import org.apache.hadoop.hbase.Server;
29 import org.apache.hadoop.hbase.ServerName;
30 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
31 import org.apache.hadoop.hbase.client.ClusterConnection;
32 import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
33 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
34
35
36
37
38 public class MockServer implements Server {
39 static final Log LOG = LogFactory.getLog(MockServer.class);
40 final static ServerName NAME = ServerName.valueOf("MockServer", 123, -1);
41
42 boolean stopped;
43 boolean aborted;
44 final ZooKeeperWatcher zk;
45 final HBaseTestingUtility htu;
46
47 @SuppressWarnings("unused")
48 public MockServer() throws ZooKeeperConnectionException, IOException {
49
50 this(null);
51 }
52
53 public MockServer(final HBaseTestingUtility htu)
54 throws ZooKeeperConnectionException, IOException {
55 this(htu, true);
56 }
57
58
59
60
61
62
63
64 public MockServer(final HBaseTestingUtility htu, final boolean zkw)
65 throws ZooKeeperConnectionException, IOException {
66 this.htu = htu;
67 this.zk = zkw?
68 new ZooKeeperWatcher(htu.getConfiguration(), NAME.toString(), this, true):
69 null;
70 }
71
72 @Override
73 public void abort(String why, Throwable e) {
74 LOG.fatal("Abort why=" + why, e);
75 stop(why);
76 this.aborted = true;
77 }
78
79 @Override
80 public void stop(String why) {
81 LOG.debug("Stop why=" + why);
82 this.stopped = true;
83 }
84
85 @Override
86 public boolean isStopped() {
87 return this.stopped;
88 }
89
90 @Override
91 public Configuration getConfiguration() {
92 return this.htu.getConfiguration();
93 }
94
95 @Override
96 public ZooKeeperWatcher getZooKeeper() {
97 return this.zk;
98 }
99
100 @Override
101 public CoordinatedStateManager getCoordinatedStateManager() {
102 return null;
103 }
104
105 @Override
106 public ClusterConnection getConnection() {
107 return null;
108 }
109
110 @Override
111 public MetaTableLocator getMetaTableLocator() {
112 return null;
113 }
114
115 @Override
116 public ServerName getServerName() {
117 return NAME;
118 }
119
120 @Override
121 public boolean isAborted() {
122
123 return this.aborted;
124 }
125
126 @Override
127 public ChoreService getChoreService() {
128 return null;
129 }
130 }