View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import java.io.IOException;
22  import java.nio.ByteBuffer;
23  import java.util.ArrayList;
24  import java.util.Arrays;
25  import java.util.Collections;
26  import java.util.Comparator;
27  import java.util.List;
28  import java.util.Map;
29  import java.util.TreeSet;
30  
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.apache.hadoop.conf.Configuration;
34  import org.apache.hadoop.fs.FileSystem;
35  import org.apache.hadoop.fs.Path;
36  import org.apache.hadoop.hbase.HBaseTestCase;
37  import org.apache.hadoop.hbase.HBaseTestingUtility;
38  import org.apache.hadoop.hbase.HConstants;
39  import org.apache.hadoop.hbase.HRegionInfo;
40  import org.apache.hadoop.hbase.KeyValue;
41  import org.apache.hadoop.hbase.SmallTests;
42  import org.apache.hadoop.hbase.client.Scan;
43  import org.apache.hadoop.hbase.io.HFileLink;
44  import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
45  import org.apache.hadoop.hbase.io.hfile.BlockCache;
46  import org.apache.hadoop.hbase.io.hfile.CacheConfig;
47  import org.apache.hadoop.hbase.io.hfile.CacheStats;
48  import org.apache.hadoop.hbase.io.hfile.HFileDataBlockEncoder;
49  import org.apache.hadoop.hbase.io.hfile.HFileDataBlockEncoderImpl;
50  import org.apache.hadoop.hbase.io.hfile.HFileScanner;
51  import org.apache.hadoop.hbase.io.hfile.NoOpDataBlockEncoder;
52  import org.apache.hadoop.hbase.util.BloomFilterFactory;
53  import org.apache.hadoop.hbase.util.Bytes;
54  import org.apache.hadoop.hbase.util.ChecksumType;
55  import org.apache.hadoop.hbase.util.FSUtils;
56  import org.junit.experimental.categories.Category;
57  import org.mockito.Mockito;
58  
59  import com.google.common.base.Joiner;
60  import com.google.common.collect.Iterables;
61  import com.google.common.collect.Lists;
62  
63  /**
64   * Test HStoreFile
65   */
66  @Category(SmallTests.class)
67  public class TestStoreFileInfo extends HBaseTestCase {
68    private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
69  
70    /**
71     * Validate that we can handle valid tables with '.', '_', and '-' chars.
72     */
73    public void testStoreFileNames() {
74      String[] legalHFileLink = { "MyTable_02=abc012-def345", "MyTable_02.300=abc012-def345",
75        "MyTable_02-400=abc012-def345", "MyTable_02-400.200=abc012-def345",
76        "MyTable_02=abc012-def345_SeqId_1_", "MyTable_02=abc012-def345_SeqId_20_" };
77      for (String name: legalHFileLink) {
78        assertTrue("should be a valid link: " + name, HFileLink.isHFileLink(name));
79        assertTrue("should be a valid StoreFile" + name, StoreFileInfo.validateStoreFileName(name));
80        assertFalse("should not be a valid reference: " + name, StoreFileInfo.isReference(name));
81  
82        String refName = name + ".6789";
83        assertTrue("should be a valid link reference: " + refName,
84            StoreFileInfo.isReference(refName));
85        assertTrue("should be a valid StoreFile" + refName,
86            StoreFileInfo.validateStoreFileName(refName));
87      }
88  
89      String[] illegalHFileLink = { ".MyTable_02=abc012-def345", "-MyTable_02.300=abc012-def345",
90        "MyTable_02-400=abc0_12-def345", "MyTable_02-400.200=abc012-def345...." };
91      for (String name: illegalHFileLink) {
92        assertFalse("should not be a valid link: " + name, HFileLink.isHFileLink(name));
93      }
94    }
95  }
96