1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.io.IOException;
22 import java.util.Map;
23 import java.util.TreeMap;
24
25 import org.apache.hadoop.fs.Path;
26 import org.apache.hadoop.hbase.HBaseTestingUtility;
27 import org.apache.hadoop.hbase.KeyValue.KVComparator;
28 import org.apache.hadoop.hbase.io.hfile.CacheConfig;
29 import org.apache.hadoop.hbase.util.Bytes;
30
31
32 public class MockStoreFile extends StoreFile {
33 long length = 0;
34 boolean isRef = false;
35 long ageInDisk;
36 long sequenceid;
37 private Map<byte[], byte[]> metadata = new TreeMap<byte[], byte[]>(Bytes.BYTES_COMPARATOR);
38 byte[] splitPoint = null;
39 TimeRangeTracker timeRangeTracker;
40 long entryCount;
41
42 MockStoreFile(HBaseTestingUtility testUtil, Path testPath,
43 long length, long ageInDisk, boolean isRef, long sequenceid) throws IOException {
44 super(testUtil.getTestFileSystem(), testPath, testUtil.getConfiguration(),
45 new CacheConfig(testUtil.getConfiguration()), BloomType.NONE);
46 this.length = length;
47 this.isRef = isRef;
48 this.ageInDisk = ageInDisk;
49 this.sequenceid = sequenceid;
50 }
51
52 void setLength(long newLen) {
53 this.length = newLen;
54 }
55
56 @Override
57 byte[] getFileSplitPoint(KVComparator comparator) throws IOException {
58 return this.splitPoint;
59 }
60
61 @Override
62 public long getMaxSequenceId() {
63 return sequenceid;
64 }
65
66 @Override
67 public boolean isMajorCompaction() {
68 return false;
69 }
70
71 @Override
72 public boolean isReference() {
73 return this.isRef;
74 }
75
76 @Override
77 boolean isBulkLoadResult() {
78 return false;
79 }
80
81 @Override
82 public byte[] getMetadataValue(byte[] key) {
83 return this.metadata.get(key);
84 }
85
86 public void setMetadataValue(byte[] key, byte[] value) {
87 this.metadata.put(key, value);
88 }
89
90 void setTimeRangeTracker(TimeRangeTracker timeRangeTracker) {
91 this.timeRangeTracker = timeRangeTracker;
92 }
93
94 void setEntries(long entryCount) {
95 this.entryCount = entryCount;
96 }
97
98 public Long getMinimumTimestamp() {
99 return (timeRangeTracker == null) ?
100 null :
101 timeRangeTracker.getMinimumTimestamp();
102 }
103
104 public Long getMaximumTimestamp() {
105 return (timeRangeTracker == null) ?
106 null :
107 timeRangeTracker.getMaximumTimestamp();
108 }
109
110 @Override
111 public StoreFile.Reader getReader() {
112 final long len = this.length;
113 final TimeRangeTracker timeRange = this.timeRangeTracker;
114 final long entries = this.entryCount;
115 return new StoreFile.Reader() {
116 @Override
117 public long length() {
118 return len;
119 }
120
121 @Override
122 public long getMaxTimestamp() {
123 return timeRange == null ? Long.MAX_VALUE : timeRange.maximumTimestamp;
124 }
125
126 @Override
127 public long getEntries() {
128 return entries;
129 }
130 };
131 }
132 }