1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver.wal;
21
22 import java.io.IOException;
23 import java.util.LinkedList;
24 import java.util.Queue;
25
26 import org.apache.hadoop.hbase.wal.WAL.Entry;
27
28 public class FaultySequenceFileLogReader extends SequenceFileLogReader {
29
30
31 public 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 Entry next(Entry reuse) throws IOException {
44 this.entryStart = this.getPosition();
45 boolean b = true;
46
47 if (nextQueue.isEmpty()) {
48 while (b == true) {
49 Entry e = new Entry(new HLogKey(), new WALEdit());
50 if (compressionContext != null) {
51 e.setCompressionContext(compressionContext);
52 }
53 b = readNext(e);
54 nextQueue.offer(e);
55 numberOfFileEntries++;
56 }
57 }
58
59 if (nextQueue.size() == this.numberOfFileEntries
60 && getFailureType() == FailureType.BEGINNING) {
61 throw this.addFileInfoToException(new IOException("fake Exception"));
62 } else if (nextQueue.size() == this.numberOfFileEntries / 2
63 && getFailureType() == FailureType.MIDDLE) {
64 throw this.addFileInfoToException(new IOException("fake Exception"));
65 } else if (nextQueue.size() == 1 && getFailureType() == FailureType.END) {
66 throw this.addFileInfoToException(new IOException("fake Exception"));
67 }
68
69 if (nextQueue.peek() != null) {
70 edit++;
71 }
72
73 Entry e = nextQueue.poll();
74
75 if (e.getEdit().isEmpty()) {
76 return null;
77 }
78 return e;
79 }
80 }