001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.util;
019
020import java.io.IOException;
021import org.apache.hadoop.conf.Configuration;
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.hbase.ChoreService;
024import org.apache.hadoop.hbase.CoordinatedStateManager;
025import org.apache.hadoop.hbase.Server;
026import org.apache.hadoop.hbase.ServerName;
027import org.apache.hadoop.hbase.client.AsyncClusterConnection;
028import org.apache.hadoop.hbase.client.Connection;
029import org.apache.hadoop.hbase.keymeta.KeyManagementService;
030import org.apache.hadoop.hbase.log.HBaseMarkers;
031import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
032import org.slf4j.Logger;
033import org.slf4j.LoggerFactory;
034
035/**
036 * Basic mock Server for handler tests.
037 */
038public class MockServer implements Server {
039  private static final Logger LOG = LoggerFactory.getLogger(MockServer.class);
040
041  final static ServerName NAME = ServerName.valueOf("MockServer", 123, 123456789);
042
043  protected volatile boolean stopped;
044  protected volatile boolean aborted;
045
046  public MockServer() {
047    stopped = false;
048    aborted = false;
049  }
050
051  @Override
052  public void abort(String why, Throwable e) {
053    LOG.error(HBaseMarkers.FATAL, "Abort {} why={}", getServerName(), why, e);
054    stop(why);
055    this.aborted = true;
056  }
057
058  @Override
059  public void stop(String why) {
060    LOG.debug("Stop {} why={}", getServerName(), why);
061    this.stopped = true;
062  }
063
064  @Override
065  public boolean isStopped() {
066    return this.stopped;
067  }
068
069  @Override
070  public Configuration getConfiguration() {
071    throw new UnsupportedOperationException();
072  }
073
074  @Override
075  public ZKWatcher getZooKeeper() {
076    throw new UnsupportedOperationException();
077  }
078
079  @Override
080  public CoordinatedStateManager getCoordinatedStateManager() {
081    throw new UnsupportedOperationException();
082  }
083
084  @Override
085  public Connection getConnection() {
086    throw new UnsupportedOperationException();
087  }
088
089  @Override
090  public ServerName getServerName() {
091    return NAME;
092  }
093
094  @Override
095  public boolean isAborted() {
096    return this.aborted;
097  }
098
099  @Override
100  public ChoreService getChoreService() {
101    throw new UnsupportedOperationException();
102  }
103
104  @Override
105  public FileSystem getFileSystem() {
106    throw new UnsupportedOperationException();
107  }
108
109  @Override
110  public boolean isStopping() {
111    return false;
112  }
113
114  @Override
115  public Connection createConnection(Configuration conf) throws IOException {
116    throw new UnsupportedOperationException();
117  }
118
119  @Override
120  public AsyncClusterConnection getAsyncClusterConnection() {
121    throw new UnsupportedOperationException();
122  }
123
124  @Override
125  public KeyManagementService getKeyManagementService() {
126    return null;
127  }
128}