|
| 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; |
| 19 | + |
| 20 | +import com.google.protobuf.Service; |
| 21 | + |
| 22 | +import java.io.IOException; |
| 23 | +import java.net.InetSocketAddress; |
| 24 | +import java.util.List; |
| 25 | +import java.util.Map; |
| 26 | +import java.util.Set; |
| 27 | +import java.util.concurrent.ConcurrentMap; |
| 28 | + |
| 29 | +import org.apache.hadoop.conf.Configuration; |
| 30 | +import org.apache.hadoop.fs.FileSystem; |
| 31 | +import org.apache.hadoop.hbase.client.ClusterConnection; |
| 32 | +import org.apache.hadoop.hbase.executor.ExecutorService; |
| 33 | +import org.apache.hadoop.hbase.ipc.RpcServerInterface; |
| 34 | +import org.apache.hadoop.hbase.master.TableLockManager; |
| 35 | +import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; |
| 36 | +import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos; |
| 37 | +import org.apache.hadoop.hbase.quotas.RegionServerQuotaManager; |
| 38 | +import org.apache.hadoop.hbase.regionserver.CompactionRequestor; |
| 39 | +import org.apache.hadoop.hbase.regionserver.FlushRequester; |
| 40 | +import org.apache.hadoop.hbase.regionserver.HeapMemoryManager; |
| 41 | +import org.apache.hadoop.hbase.regionserver.Leases; |
| 42 | +import org.apache.hadoop.hbase.regionserver.MetricsRegionServer; |
| 43 | +import org.apache.hadoop.hbase.regionserver.Region; |
| 44 | +import org.apache.hadoop.hbase.regionserver.RegionServerAccounting; |
| 45 | +import org.apache.hadoop.hbase.regionserver.RegionServerServices; |
| 46 | +import org.apache.hadoop.hbase.regionserver.ServerNonceManager; |
| 47 | +import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController; |
| 48 | +import org.apache.hadoop.hbase.wal.WAL; |
| 49 | +import org.apache.hadoop.hbase.wal.WALProvider; |
| 50 | +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; |
| 51 | +import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; |
| 52 | +import org.apache.zookeeper.KeeperException; |
| 53 | + |
| 54 | +/** |
| 55 | + * Mock region server services with WALProvider, it can be used for testing wal related tests, |
| 56 | + * like split or merge regions. |
| 57 | + */ |
| 58 | +public class MockRegionServerServicesWithWALs implements RegionServerServices { |
| 59 | + WALProvider provider; |
| 60 | + RegionServerServices rss; |
| 61 | + |
| 62 | + public MockRegionServerServicesWithWALs(RegionServerServices rss, WALProvider provider) { |
| 63 | + this.rss = rss; |
| 64 | + this.provider = provider; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public boolean isStopping() { |
| 69 | + return rss.isStopping(); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public WAL getWAL(HRegionInfo hri) throws IOException { |
| 74 | + return provider.getWAL(hri.getEncodedNameAsBytes(), hri.getTable().getNamespace()); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public CompactionRequestor getCompactionRequester() { |
| 79 | + return rss.getCompactionRequester(); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public FlushRequester getFlushRequester() { |
| 84 | + return rss.getFlushRequester(); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public RegionServerAccounting getRegionServerAccounting() { |
| 89 | + return rss.getRegionServerAccounting(); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public TableLockManager getTableLockManager() { |
| 94 | + return rss.getTableLockManager(); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public RegionServerQuotaManager getRegionServerQuotaManager() { |
| 99 | + return rss.getRegionServerQuotaManager(); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public void postOpenDeployTasks(PostOpenDeployContext context) |
| 104 | + throws KeeperException, IOException { |
| 105 | + rss.postOpenDeployTasks(context); |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public void postOpenDeployTasks(Region r) throws KeeperException, IOException { |
| 110 | + rss.postOpenDeployTasks(r); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public boolean reportRegionStateTransition(RegionStateTransitionContext context) { |
| 115 | + return rss.reportRegionStateTransition(context); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public boolean reportRegionStateTransition( |
| 120 | + RegionServerStatusProtos.RegionStateTransition.TransitionCode code, long openSeqNum, |
| 121 | + HRegionInfo... hris) { |
| 122 | + return rss.reportRegionStateTransition(code, openSeqNum, hris); |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public boolean reportRegionStateTransition( |
| 127 | + RegionServerStatusProtos.RegionStateTransition.TransitionCode code, HRegionInfo... hris) { |
| 128 | + return rss.reportRegionStateTransition(code, hris); |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public RpcServerInterface getRpcServer() { |
| 133 | + return rss.getRpcServer(); |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public ConcurrentMap<byte[], Boolean> getRegionsInTransitionInRS() { |
| 138 | + return rss.getRegionsInTransitionInRS(); |
| 139 | + } |
| 140 | + |
| 141 | + @Override |
| 142 | + public FileSystem getFileSystem() { |
| 143 | + return rss.getFileSystem(); |
| 144 | + } |
| 145 | + |
| 146 | + @Override |
| 147 | + public Leases getLeases() { |
| 148 | + return rss.getLeases(); |
| 149 | + } |
| 150 | + |
| 151 | + @Override |
| 152 | + public ExecutorService getExecutorService() { |
| 153 | + return rss.getExecutorService(); |
| 154 | + } |
| 155 | + |
| 156 | + @Override |
| 157 | + public Map<String, Region> getRecoveringRegions() { |
| 158 | + return rss.getRecoveringRegions(); |
| 159 | + } |
| 160 | + |
| 161 | + @Override |
| 162 | + public ServerNonceManager getNonceManager() { |
| 163 | + return rss.getNonceManager(); |
| 164 | + } |
| 165 | + |
| 166 | + @Override |
| 167 | + public boolean registerService(Service service) { |
| 168 | + return rss.registerService(service); |
| 169 | + } |
| 170 | + |
| 171 | + @Override |
| 172 | + public HeapMemoryManager getHeapMemoryManager() { |
| 173 | + return rss.getHeapMemoryManager(); |
| 174 | + } |
| 175 | + |
| 176 | + @Override |
| 177 | + public double getCompactionPressure() { |
| 178 | + return rss.getCompactionPressure(); |
| 179 | + } |
| 180 | + |
| 181 | + @Override |
| 182 | + public Set<TableName> getOnlineTables() { |
| 183 | + return rss.getOnlineTables(); |
| 184 | + } |
| 185 | + |
| 186 | + @Override |
| 187 | + public ThroughputController getFlushThroughputController() { |
| 188 | + return rss.getFlushThroughputController(); |
| 189 | + } |
| 190 | + |
| 191 | + @Override |
| 192 | + public double getFlushPressure() { |
| 193 | + return rss.getFlushPressure(); |
| 194 | + } |
| 195 | + |
| 196 | + @Override |
| 197 | + public MetricsRegionServer getMetrics() { |
| 198 | + return rss.getMetrics(); |
| 199 | + } |
| 200 | + |
| 201 | + @Override |
| 202 | + public void unassign(byte[] regionName) throws IOException { |
| 203 | + rss.unassign(regionName); |
| 204 | + } |
| 205 | + |
| 206 | + @Override |
| 207 | + public void addToOnlineRegions(Region r) { |
| 208 | + rss.addToOnlineRegions(r); |
| 209 | + } |
| 210 | + |
| 211 | + @Override |
| 212 | + public boolean removeFromOnlineRegions(Region r, ServerName destination) { |
| 213 | + return rss.removeFromOnlineRegions(r, destination); |
| 214 | + } |
| 215 | + |
| 216 | + @Override |
| 217 | + public Region getFromOnlineRegions(String encodedRegionName) { |
| 218 | + return rss.getFromOnlineRegions(encodedRegionName); |
| 219 | + } |
| 220 | + |
| 221 | + @Override |
| 222 | + public List<Region> getOnlineRegions(TableName tableName) throws IOException { |
| 223 | + return rss.getOnlineRegions(tableName); |
| 224 | + } |
| 225 | + |
| 226 | + @Override |
| 227 | + public List<Region> getOnlineRegions() { |
| 228 | + return rss.getOnlineRegions(); |
| 229 | + } |
| 230 | + |
| 231 | + @Override |
| 232 | + public Configuration getConfiguration() { |
| 233 | + return rss.getConfiguration(); |
| 234 | + } |
| 235 | + |
| 236 | + @Override |
| 237 | + public ZooKeeperWatcher getZooKeeper() { |
| 238 | + return rss.getZooKeeper(); |
| 239 | + } |
| 240 | + |
| 241 | + @Override |
| 242 | + public ClusterConnection getConnection() { |
| 243 | + return rss.getConnection(); |
| 244 | + } |
| 245 | + |
| 246 | + @Override |
| 247 | + public MetaTableLocator getMetaTableLocator() { |
| 248 | + return rss.getMetaTableLocator(); |
| 249 | + } |
| 250 | + |
| 251 | + @Override |
| 252 | + public ServerName getServerName() { |
| 253 | + return rss.getServerName(); |
| 254 | + } |
| 255 | + |
| 256 | + @Override |
| 257 | + public CoordinatedStateManager getCoordinatedStateManager() { |
| 258 | + return rss.getCoordinatedStateManager(); |
| 259 | + } |
| 260 | + |
| 261 | + @Override |
| 262 | + public ChoreService getChoreService() { |
| 263 | + return rss.getChoreService(); |
| 264 | + } |
| 265 | + |
| 266 | + @Override |
| 267 | + public void abort(String why, Throwable e) { |
| 268 | + rss.abort(why, e); |
| 269 | + } |
| 270 | + |
| 271 | + @Override |
| 272 | + public boolean isAborted() { |
| 273 | + return rss.isAborted(); |
| 274 | + } |
| 275 | + |
| 276 | + @Override |
| 277 | + public void stop(String why) { |
| 278 | + rss.stop(why); |
| 279 | + } |
| 280 | + |
| 281 | + @Override |
| 282 | + public boolean isStopped() { |
| 283 | + return rss.isStopped(); |
| 284 | + } |
| 285 | + |
| 286 | + @Override |
| 287 | + public void updateRegionFavoredNodesMapping(String encodedRegionName, |
| 288 | + List<HBaseProtos.ServerName> favoredNodes) { |
| 289 | + rss.updateRegionFavoredNodesMapping(encodedRegionName, favoredNodes); |
| 290 | + } |
| 291 | + |
| 292 | + @Override |
| 293 | + public InetSocketAddress[] getFavoredNodesForRegion(String encodedRegionName) { |
| 294 | + return rss.getFavoredNodesForRegion(encodedRegionName); |
| 295 | + } |
| 296 | +} |
0 commit comments