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() {
86      return null;
87    }
88  
89    @Override
90    public RpcServer getRpcServer() {
91      return null;
92    }
93  
94    @Override
95    public FlushRequester getFlushRequester() {
96      return null;
97    }
98  
99    @Override
100   public CompactionRequestor getCompactionRequester() {
101     return null;
102   }
103 
104   @Override
105   public CatalogTracker getCatalogTracker() {
106     return null;
107   }
108 
109   @Override
110   public ZooKeeperWatcher getZooKeeper() {
111     return null;
112   }
113   
114   public RegionServerAccounting getRegionServerAccounting() {
115     return null;
116   }
117 
118   @Override
119   public ServerName getServerName() {
120     return null;
121   }
122 
123   @Override
124   public Configuration getConfiguration() {
125     return null;
126   }
127 
128   @Override
129   public void abort(String why, Throwable e) {
130      //no-op
131   }
132 
133   @Override
134   public void stop(String why) {
135     //no-op
136   }
137 
138   @Override
139   public boolean isStopped() {
140     return false;
141   }
142 
143   @Override
144   public boolean isAborted() {
145     return false;
146   }
147 
148   @Override
149   public HFileSystem getFileSystem() {
150     return this.hfs;
151   }
152 
153   public void setFileSystem(FileSystem hfs) {
154     this.hfs = (HFileSystem)hfs;
155   }
156 
157   @Override
158   public Leases getLeases() {
159     return null;
160   }
161 
162   @Override
163   public boolean removeFromRegionsInTransition(HRegionInfo hri) {
164     // TODO Auto-generated method stub
165     return false;
166   }
167 
168   @Override
169   public boolean containsKeyInRegionsInTransition(HRegionInfo hri) {
170     // TODO Auto-generated method stub
171     return false;
172   }
173 }