1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.regionserver.wal;
22
23 import java.io.IOException;
24 import java.util.LinkedList;
25 import java.util.Queue;
26
27 import org.apache.hadoop.hbase.regionserver.wal.HLog.Entry;
28
29 public class FaultySequenceFileLogReader extends SequenceFileLogReader {
30
31 enum FailureType {
32 BEGINNING, MIDDLE, END, NONE
33 }
34
35 Queue<Entry> nextQueue = new LinkedList<Entry>();
36 int numberOfFileEntries = 0;
37
38 FailureType getFailureType() {
39 return FailureType.valueOf(conf.get("faultysequencefilelogreader.failuretype", "NONE"));
40 }
41
42 @Override
43 public HLog.Entry next(HLog.Entry reuse) throws IOException {
44 this.entryStart = this.reader.getPosition();
45 boolean b = true;
46
47 if (nextQueue.isEmpty()) {
48 while (b == true) {
49 HLogKey key = HLog.newKey(conf);
50 WALEdit val = new WALEdit();
51 HLog.Entry e = new HLog.Entry(key, val);
52 b = this.reader.next(e.getKey(), e.getEdit());
53 nextQueue.offer(e);
54 numberOfFileEntries++;
55 }
56 }
57
58 if (nextQueue.size() == this.numberOfFileEntries
59 && getFailureType() == FailureType.BEGINNING) {
60 throw this.addFileInfoToException(new IOException("fake Exception"));
61 } else if (nextQueue.size() == this.numberOfFileEntries / 2
62 && getFailureType() == FailureType.MIDDLE) {
63 throw this.addFileInfoToException(new IOException("fake Exception"));
64 } else if (nextQueue.size() == 1 && getFailureType() == FailureType.END) {
65 throw this.addFileInfoToException(new IOException("fake Exception"));
66 }
67
68 if (nextQueue.peek() != null) {
69 edit++;
70 }
71
72 Entry e = nextQueue.poll();
73
74 if (e.getEdit().isEmpty()) {
75 return null;
76 }
77 return e;
78 }
79 }