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.log.HBaseMarkers; 030import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034/** 035 * Basic mock Server for handler tests. 036 */ 037public class MockServer implements Server { 038 private static final Logger LOG = LoggerFactory.getLogger(MockServer.class); 039 040 final static ServerName NAME = ServerName.valueOf("MockServer", 123, 123456789); 041 042 protected volatile boolean stopped; 043 protected volatile boolean aborted; 044 045 public MockServer() { 046 stopped = false; 047 aborted = false; 048 } 049 050 @Override 051 public void abort(String why, Throwable e) { 052 LOG.error(HBaseMarkers.FATAL, "Abort {} why={}", getServerName(), why, e); 053 stop(why); 054 this.aborted = true; 055 } 056 057 @Override 058 public void stop(String why) { 059 LOG.debug("Stop {} why={}", getServerName(), why); 060 this.stopped = true; 061 } 062 063 @Override 064 public boolean isStopped() { 065 return this.stopped; 066 } 067 068 @Override 069 public Configuration getConfiguration() { 070 throw new UnsupportedOperationException(); 071 } 072 073 @Override 074 public ZKWatcher getZooKeeper() { 075 throw new UnsupportedOperationException(); 076 } 077 078 @Override 079 public CoordinatedStateManager getCoordinatedStateManager() { 080 throw new UnsupportedOperationException(); 081 } 082 083 @Override 084 public Connection getConnection() { 085 throw new UnsupportedOperationException(); 086 } 087 088 @Override 089 public ServerName getServerName() { 090 return NAME; 091 } 092 093 @Override 094 public boolean isAborted() { 095 return this.aborted; 096 } 097 098 @Override 099 public ChoreService getChoreService() { 100 throw new UnsupportedOperationException(); 101 } 102 103 @Override 104 public FileSystem getFileSystem() { 105 throw new UnsupportedOperationException(); 106 } 107 108 @Override 109 public boolean isStopping() { 110 return false; 111 } 112 113 @Override 114 public Connection createConnection(Configuration conf) throws IOException { 115 throw new UnsupportedOperationException(); 116 } 117 118 @Override 119 public AsyncClusterConnection getAsyncClusterConnection() { 120 throw new UnsupportedOperationException(); 121 } 122}