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 org.apache.hadoop.hbase.HBaseTestCase;
22  import org.apache.hadoop.hbase.HBaseTestingUtility;
23  import org.apache.hadoop.hbase.io.HFileLink;
24  import org.apache.hadoop.hbase.testclassification.SmallTests;
25  import org.junit.experimental.categories.Category;
26  
27  /**
28   * Test HStoreFile
29   */
30  @Category(SmallTests.class)
31  public class TestStoreFileInfo extends HBaseTestCase {
32    private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
33  
34    /**
35     * Validate that we can handle valid tables with '.', '_', and '-' chars.
36     */
37    public void testStoreFileNames() {
38      String[] legalHFileLink = { "MyTable_02=abc012-def345", "MyTable_02.300=abc012-def345",
39        "MyTable_02-400=abc012-def345", "MyTable_02-400.200=abc012-def345",
40        "MyTable_02=abc012-def345_SeqId_1_", "MyTable_02=abc012-def345_SeqId_20_" };
41      for (String name: legalHFileLink) {
42        assertTrue("should be a valid link: " + name, HFileLink.isHFileLink(name));
43        assertTrue("should be a valid StoreFile" + name, StoreFileInfo.validateStoreFileName(name));
44        assertFalse("should not be a valid reference: " + name, StoreFileInfo.isReference(name));
45  
46        String refName = name + ".6789";
47        assertTrue("should be a valid link reference: " + refName,
48            StoreFileInfo.isReference(refName));
49        assertTrue("should be a valid StoreFile" + refName,
50            StoreFileInfo.validateStoreFileName(refName));
51      }
52  
53      String[] illegalHFileLink = { ".MyTable_02=abc012-def345", "-MyTable_02.300=abc012-def345",
54        "MyTable_02-400=abc0_12-def345", "MyTable_02-400.200=abc012-def345...." };
55      for (String name: illegalHFileLink) {
56        assertFalse("should not be a valid link: " + name, HFileLink.isHFileLink(name));
57      }
58    }
59  }
60