HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / wal / FaultyFSLog.java
blobf58d36428cf4b61fdcba842395b0748475e394ff
1 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org.apache.hadoop.hbase.wal;
22 import java.io.IOException;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.fs.FileSystem;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.client.RegionInfo;
28 import org.apache.hadoop.hbase.regionserver.wal.FSHLog;
29 import org.apache.yetus.audience.InterfaceAudience;
31 // imports for things that haven't moved yet
33 /**
34 * This is a utility class, used by tests, which fails operation specified by FailureType enum
36 @InterfaceAudience.Private
37 public class FaultyFSLog extends FSHLog {
38 public enum FailureType {
39 NONE, APPEND, SYNC
41 FailureType ft = FailureType.NONE;
43 public FaultyFSLog(FileSystem fs, Path rootDir, String logName, Configuration conf)
44 throws IOException {
45 super(fs, rootDir, logName, conf);
48 public void setFailureType(FailureType fType) {
49 this.ft = fType;
52 @Override
53 public void sync(long txid) throws IOException {
54 sync(txid, false);
57 @Override
58 public void sync(long txid, boolean forceSync) throws IOException {
59 if (this.ft == FailureType.SYNC) {
60 throw new IOException("sync");
62 super.sync(txid, forceSync);
65 @Override
66 protected long append(RegionInfo info, WALKeyImpl key, WALEdit edits, boolean inMemstore)
67 throws IOException {
68 if (this.ft == FailureType.APPEND) {
69 throw new IOException("append");
71 return super.append(info, key, edits, inMemstore);