HBASE-23723 Ensure MOB compaction works in optimized mode after snapshot clone (...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / util / MockServer.java
blob380c1c7d7d869b96c61ba1507d15d3cac72c048f
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.util;
20 import java.io.IOException;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.fs.FileSystem;
23 import org.apache.hadoop.hbase.ChoreService;
24 import org.apache.hadoop.hbase.CoordinatedStateManager;
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.client.AsyncClusterConnection;
30 import org.apache.hadoop.hbase.client.Connection;
31 import org.apache.hadoop.hbase.log.HBaseMarkers;
32 import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 /**
37 * Basic mock Server for handler tests.
39 public class MockServer implements Server {
40 private static final Logger LOG = LoggerFactory.getLogger(MockServer.class);
41 final static ServerName NAME = ServerName.valueOf("MockServer", 123, -1);
43 boolean stopped;
44 boolean aborted;
45 final ZKWatcher zk;
46 final HBaseTestingUtility htu;
48 public MockServer() throws ZooKeeperConnectionException, IOException {
49 // Shutdown default constructor by making it private.
50 this(null);
53 public MockServer(final HBaseTestingUtility htu)
54 throws ZooKeeperConnectionException, IOException {
55 this(htu, true);
58 /**
59 * @param htu Testing utility to use
60 * @param zkw If true, create a zkw.
61 * @throws ZooKeeperConnectionException
62 * @throws IOException
64 public MockServer(final HBaseTestingUtility htu, final boolean zkw)
65 throws ZooKeeperConnectionException, IOException {
66 this.htu = htu;
67 this.zk = zkw?
68 new ZKWatcher(htu.getConfiguration(), NAME.toString(), this, true):
69 null;
72 @Override
73 public void abort(String why, Throwable e) {
74 LOG.error(HBaseMarkers.FATAL, "Abort why=" + why, e);
75 stop(why);
76 this.aborted = true;
79 @Override
80 public void stop(String why) {
81 LOG.debug("Stop why=" + why);
82 this.stopped = true;
85 @Override
86 public boolean isStopped() {
87 return this.stopped;
90 @Override
91 public Configuration getConfiguration() {
92 return this.htu.getConfiguration();
95 @Override
96 public ZKWatcher getZooKeeper() {
97 return this.zk;
100 @Override
101 public CoordinatedStateManager getCoordinatedStateManager() {
102 return null;
105 @Override
106 public Connection getConnection() {
107 return null;
110 @Override
111 public ServerName getServerName() {
112 return NAME;
115 @Override
116 public boolean isAborted() {
117 return this.aborted;
120 @Override
121 public ChoreService getChoreService() {
122 return null;
125 @Override
126 public FileSystem getFileSystem() {
127 return null;
130 @Override
131 public boolean isStopping() {
132 return false;
135 @Override
136 public Connection createConnection(Configuration conf) throws IOException {
137 return null;
140 @Override
141 public AsyncClusterConnection getAsyncClusterConnection() {
142 return null;