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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  package org.apache.hadoop.hbase.util;
19  
20  import java.io.IOException;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.concurrent.ConcurrentSkipListMap;
25  
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.fs.FileSystem;
28  import org.apache.hadoop.hbase.HRegionInfo;
29  import org.apache.hadoop.hbase.ServerName;
30  import org.apache.hadoop.hbase.catalog.CatalogTracker;
31  import org.apache.hadoop.hbase.fs.HFileSystem;
32  import org.apache.hadoop.hbase.ipc.RpcServer;
33  import org.apache.hadoop.hbase.regionserver.CompactionRequestor;
34  import org.apache.hadoop.hbase.regionserver.FlushRequester;
35  import org.apache.hadoop.hbase.regionserver.HRegion;
36  import org.apache.hadoop.hbase.regionserver.Leases;
37  import org.apache.hadoop.hbase.regionserver.RegionServerAccounting;
38  import org.apache.hadoop.hbase.regionserver.RegionServerServices;
39  import org.apache.hadoop.hbase.regionserver.wal.HLog;
40  import org.apache.hadoop.hbase.util.Bytes;
41  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
42  import org.apache.zookeeper.KeeperException;
43  
44  /**
45   * Basic mock region server services.
46   */
47  public class MockRegionServerServices implements RegionServerServices {
48    private final Map<String, HRegion> regions = new HashMap<String, HRegion>();
49    private boolean stopping = false;
50    private final ConcurrentSkipListMap<byte[], Boolean> rit = 
51      new ConcurrentSkipListMap<byte[], Boolean>(Bytes.BYTES_COMPARATOR);
52    private HFileSystem hfs = null;
53  
54    @Override
55    public boolean removeFromOnlineRegions(String encodedRegionName) {
56      return this.regions.remove(encodedRegionName) != null;
57    }
58  
59    @Override
60    public HRegion getFromOnlineRegions(String encodedRegionName) {
61      return this.regions.get(encodedRegionName);
62    }
63  
64    public List<HRegion> getOnlineRegions(byte[] tableName) throws IOException {
65      return null;
66    }
67  
68    @Override
69    public void addToOnlineRegions(HRegion r) {
70      this.regions.put(r.getRegionInfo().getEncodedName(), r);
71    }
72  
73    @Override
74    public void postOpenDeployTasks(HRegion r, CatalogTracker ct, boolean daughter)
75        throws KeeperException, IOException {
76      addToOnlineRegions(r);
77    }
78  
79    @Override
80    public boolean isStopping() {
81      return this.stopping;
82    }
83  
84    @Override
85    public HLog getWAL(HRegionInfo regionInfo) throws IOException {
86      return null;
87    }
88  
89    @Override
90    public HLog getWAL() throws IOException {
91      return null;
92    }
93  
94    @Override
95    public RpcServer getRpcServer() {
96      return null;
97    }
98  
99    @Override
100   public FlushRequester getFlushRequester() {
101     return null;
102   }
103 
104   @Override
105   public CompactionRequestor getCompactionRequester() {
106     return null;
107   }
108 
109   @Override
110   public CatalogTracker getCatalogTracker() {
111     return null;
112   }
113 
114   @Override
115   public ZooKeeperWatcher getZooKeeper() {
116     return null;
117   }
118   
119   public RegionServerAccounting getRegionServerAccounting() {
120     return null;
121   }
122 
123   @Override
124   public ServerName getServerName() {
125     return null;
126   }
127 
128   @Override
129   public Configuration getConfiguration() {
130     return null;
131   }
132 
133   @Override
134   public void abort(String why, Throwable e) {
135      //no-op
136   }
137 
138   @Override
139   public void stop(String why) {
140     //no-op
141   }
142 
143   @Override
144   public boolean isStopped() {
145     return false;
146   }
147 
148   @Override
149   public boolean isAborted() {
150     return false;
151   }
152 
153   @Override
154   public HFileSystem getFileSystem() {
155     return this.hfs;
156   }
157 
158   public void setFileSystem(FileSystem hfs) {
159     this.hfs = (HFileSystem)hfs;
160   }
161 
162   @Override
163   public Leases getLeases() {
164     return null;
165   }
166 
167   @Override
168   public boolean removeFromRegionsInTransition(HRegionInfo hri) {
169     // TODO Auto-generated method stub
170     return false;
171   }
172 
173   @Override
174   public boolean containsKeyInRegionsInTransition(HRegionInfo hri) {
175     // TODO Auto-generated method stub
176     return false;
177   }
178 }