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.HDFSBlocksDistribution;
29 import org.apache.hadoop.hbase.io.hfile.CacheConfig;
30 import org.apache.hadoop.hbase.regionserver.RSRpcServices;
31 import org.apache.hadoop.hbase.util.Bytes;
32 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
33
34
35 public class MockStoreFile extends StoreFile {
36 long length = 0;
37 boolean isRef = false;
38 long ageInDisk;
39 long sequenceid;
40 private Map<byte[], byte[]> metadata = new TreeMap<byte[], byte[]>(Bytes.BYTES_COMPARATOR);
41 byte[] splitPoint = null;
42 TimeRangeTracker timeRangeTracker;
43 long entryCount;
44 boolean isMajor;
45 HDFSBlocksDistribution hdfsBlocksDistribution;
46 long modificationTime;
47 boolean compactedAway;
48
49 MockStoreFile(HBaseTestingUtility testUtil, Path testPath,
50 long length, long ageInDisk, boolean isRef, long sequenceid) throws IOException {
51 super(testUtil.getTestFileSystem(), testPath, testUtil.getConfiguration(),
52 new CacheConfig(testUtil.getConfiguration()), BloomType.NONE);
53 this.length = length;
54 this.isRef = isRef;
55 this.ageInDisk = ageInDisk;
56 this.sequenceid = sequenceid;
57 this.isMajor = false;
58 hdfsBlocksDistribution = new HDFSBlocksDistribution();
59 hdfsBlocksDistribution.addHostsAndBlockWeight(
60 new String[] { RSRpcServices.getHostname(testUtil.getConfiguration(), false) }, 1);
61 modificationTime = EnvironmentEdgeManager.currentTime();
62 }
63
64 void setLength(long newLen) {
65 this.length = newLen;
66 }
67
68 @Override
69 byte[] getFileSplitPoint(KVComparator comparator) throws IOException {
70 return this.splitPoint;
71 }
72
73 @Override
74 public long getMaxSequenceId() {
75 return sequenceid;
76 }
77
78 @Override
79 public boolean isMajorCompaction() {
80 return isMajor;
81 }
82
83 public void setIsMajor(boolean isMajor) {
84 this.isMajor = isMajor;
85 }
86
87 @Override
88 public boolean isReference() {
89 return this.isRef;
90 }
91
92 @Override
93 public boolean isBulkLoadResult() {
94 return false;
95 }
96
97 @Override
98 public byte[] getMetadataValue(byte[] key) {
99 return this.metadata.get(key);
100 }
101
102 public void setMetadataValue(byte[] key, byte[] value) {
103 this.metadata.put(key, value);
104 }
105
106 void setTimeRangeTracker(TimeRangeTracker timeRangeTracker) {
107 this.timeRangeTracker = timeRangeTracker;
108 }
109
110 void setEntries(long entryCount) {
111 this.entryCount = entryCount;
112 }
113
114 public Long getMinimumTimestamp() {
115 return (timeRangeTracker == null) ?
116 null : timeRangeTracker.getMin();
117 }
118
119 public Long getMaximumTimestamp() {
120 return (timeRangeTracker == null) ?
121 null : timeRangeTracker.getMax();
122 }
123
124 @Override
125 public void markCompactedAway() {
126 this.compactedAway = true;
127 }
128
129 @Override
130 public long getModificationTimeStamp() {
131 return modificationTime;
132 }
133
134 @Override
135 public HDFSBlocksDistribution getHDFSBlockDistribution() {
136 return hdfsBlocksDistribution;
137 }
138
139 @Override
140 public StoreFile.Reader getReader() {
141 final long len = this.length;
142 final TimeRangeTracker timeRangeTracker = this.timeRangeTracker;
143 final long entries = this.entryCount;
144 final boolean compactedAway = this.compactedAway;
145 return new StoreFile.Reader() {
146 @Override
147 public long length() {
148 return len;
149 }
150
151 @Override
152 public long getMaxTimestamp() {
153 return timeRange == null? Long.MAX_VALUE: timeRangeTracker.getMax();
154 }
155
156 @Override
157 public long getEntries() {
158 return entries;
159 }
160
161 @Override
162 public boolean isCompactedAway() {
163 return compactedAway;
164 }
165
166 @Override
167 public void close(boolean evictOnClose) throws IOException {
168
169 }
170 };
171 }
172 }