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