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