001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.wal;
021
022import java.io.IOException;
023
024import org.apache.hadoop.conf.Configuration;
025import org.apache.hadoop.fs.FileSystem;
026import org.apache.hadoop.fs.Path;
027import org.apache.hadoop.hbase.client.RegionInfo;
028import org.apache.hadoop.hbase.regionserver.wal.FSHLog;
029import org.apache.yetus.audience.InterfaceAudience;
030
031// imports for things that haven't moved yet
032
033/**
034 * This is a utility class, used by tests, which fails operation specified by FailureType enum
035 */
036@InterfaceAudience.Private
037public class FaultyFSLog extends FSHLog {
038  public enum FailureType {
039    NONE, APPEND, SYNC
040  }
041  FailureType ft = FailureType.NONE;
042
043  public FaultyFSLog(FileSystem fs, Path rootDir, String logName, Configuration conf)
044      throws IOException {
045    super(fs, rootDir, logName, conf);
046  }
047
048  public void setFailureType(FailureType fType) {
049    this.ft = fType;
050  }
051
052  @Override
053  public void sync(long txid) throws IOException {
054    if (this.ft == FailureType.SYNC) {
055      throw new IOException("sync");
056    }
057    super.sync(txid);
058  }
059
060  @Override
061  public long append(RegionInfo info, WALKeyImpl key,
062      WALEdit edits, boolean inMemstore) throws IOException {
063    if (this.ft == FailureType.APPEND) {
064      throw new IOException("append");
065    }
066    return super.append(info, key, edits, inMemstore);
067  }
068}
069