View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  /** A mock used so our tests don't deal with actual StoreFiles */
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    @Override
99    public StoreFile.Reader getReader() {
100     final long len = this.length;
101     final TimeRangeTracker timeRange = this.timeRangeTracker;
102     final long entries = this.entryCount;
103     return new StoreFile.Reader() {
104       @Override
105       public long length() {
106         return len;
107       }
108 
109       @Override
110       public long getMaxTimestamp() {
111         return timeRange == null ? Long.MAX_VALUE : timeRange.maximumTimestamp;
112       }
113 
114       @Override
115       public long getEntries() {
116         return entries;
117       }
118     };
119   }
120 }