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.Map;
23  import java.util.concurrent.ConcurrentSkipListMap;
24  
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.hadoop.hbase.ServerName;
27  import org.apache.hadoop.hbase.catalog.CatalogTracker;
28  import org.apache.hadoop.hbase.ipc.RpcServer;
29  import org.apache.hadoop.hbase.regionserver.CompactionRequestor;
30  import org.apache.hadoop.hbase.regionserver.FlushRequester;
31  import org.apache.hadoop.hbase.regionserver.HRegion;
32  import org.apache.hadoop.hbase.regionserver.RegionServerAccounting;
33  import org.apache.hadoop.hbase.regionserver.RegionServerServices;
34  import org.apache.hadoop.hbase.regionserver.wal.HLog;
35  import org.apache.hadoop.hbase.util.Bytes;
36  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
37  import org.apache.zookeeper.KeeperException;
38  
39  /**
40   * Basic mock region server services.
41   */
42  public class MockRegionServerServices implements RegionServerServices {
43    private final Map<String, HRegion> regions = new HashMap<String, HRegion>();
44    private boolean stopping = false;
45    private final ConcurrentSkipListMap<byte[], Boolean> rit = 
46      new ConcurrentSkipListMap<byte[], Boolean>(Bytes.BYTES_COMPARATOR);
47  
48    @Override
49    public boolean removeFromOnlineRegions(String encodedRegionName) {
50      return this.regions.remove(encodedRegionName) != null;
51    }
52  
53    @Override
54    public HRegion getFromOnlineRegions(String encodedRegionName) {
55      return this.regions.get(encodedRegionName);
56    }
57  
58    @Override
59    public void addToOnlineRegions(HRegion r) {
60      this.regions.put(r.getRegionInfo().getEncodedName(), r);
61    }
62  
63    @Override
64    public void postOpenDeployTasks(HRegion r, CatalogTracker ct, boolean daughter)
65        throws KeeperException, IOException {
66    }
67  
68    @Override
69    public boolean isStopping() {
70      return this.stopping;
71    }
72  
73    @Override
74    public HLog getWAL() {
75      return null;
76    }
77  
78    @Override
79    public RpcServer getRpcServer() {
80      return null;
81    }
82  
83    @Override
84    public ConcurrentSkipListMap<byte[], Boolean> getRegionsInTransitionInRS() {
85      return rit;
86    }
87  
88    @Override
89    public FlushRequester getFlushRequester() {
90      return null;
91    }
92  
93    @Override
94    public CompactionRequestor getCompactionRequester() {
95      return null;
96    }
97  
98    @Override
99    public CatalogTracker getCatalogTracker() {
100     return null;
101   }
102 
103   @Override
104   public ZooKeeperWatcher getZooKeeper() {
105     return null;
106   }
107   
108   public RegionServerAccounting getRegionServerAccounting() {
109     return null;
110   }
111 
112   @Override
113   public ServerName getServerName() {
114     return null;
115   }
116 
117   @Override
118   public Configuration getConfiguration() {
119     return null;
120   }
121 
122   @Override
123   public void abort(String why, Throwable e) {
124      //no-op
125   }
126 
127   @Override
128   public void stop(String why) {
129     //no-op
130   }
131 
132   @Override
133   public boolean isStopped() {
134     return false;
135   }
136 
137   @Override
138   public boolean isAborted() {
139     return false;
140   }
141   
142 }