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 static org.junit.Assert.*;
22  
23  import java.io.IOException;
24  
25  import org.apache.hadoop.fs.Path;
26  import org.apache.hadoop.hbase.HBaseTestingUtility;
27  import org.apache.hadoop.hbase.testclassification.SmallTests;
28  import org.apache.hadoop.hbase.io.HFileLink;
29  import org.junit.Test;
30  import org.junit.experimental.categories.Category;
31  
32  /**
33   * Test HStoreFile
34   */
35  @Category(SmallTests.class)
36  public class TestStoreFileInfo {
37    private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
38  
39    /**
40     * Validate that we can handle valid tables with '.', '_', and '-' chars.
41     */
42    @Test
43    public void testStoreFileNames() {
44      String[] legalHFileLink = { "MyTable_02=abc012-def345", "MyTable_02.300=abc012-def345",
45        "MyTable_02-400=abc012-def345", "MyTable_02-400.200=abc012-def345",
46        "MyTable_02=abc012-def345_SeqId_1_", "MyTable_02=abc012-def345_SeqId_20_" };
47      for (String name: legalHFileLink) {
48        assertTrue("should be a valid link: " + name, HFileLink.isHFileLink(name));
49        assertTrue("should be a valid StoreFile" + name, StoreFileInfo.validateStoreFileName(name));
50        assertFalse("should not be a valid reference: " + name, StoreFileInfo.isReference(name));
51  
52        String refName = name + ".6789";
53        assertTrue("should be a valid link reference: " + refName,
54            StoreFileInfo.isReference(refName));
55        assertTrue("should be a valid StoreFile" + refName,
56            StoreFileInfo.validateStoreFileName(refName));
57      }
58  
59      String[] illegalHFileLink = { ".MyTable_02=abc012-def345", "-MyTable_02.300=abc012-def345",
60        "MyTable_02-400=abc0_12-def345", "MyTable_02-400.200=abc012-def345...." };
61      for (String name: illegalHFileLink) {
62        assertFalse("should not be a valid link: " + name, HFileLink.isHFileLink(name));
63      }
64    }
65  
66    @Test
67    public void testEqualsWithLink() throws IOException {
68      Path origin = new Path("/origin");
69      Path tmp = new Path("/tmp");
70      Path archive = new Path("/archive");
71      HFileLink link1 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
72        new Path(archive, "f1"));
73      HFileLink link2 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
74        new Path(archive, "f1"));
75  
76  
77      StoreFileInfo info1 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
78        TEST_UTIL.getTestFileSystem(), null, link1);
79      StoreFileInfo info2 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
80        TEST_UTIL.getTestFileSystem(), null, link2);
81  
82      assertEquals(info1, info2);
83      assertEquals(info1.hashCode(), info2.hashCode());
84    }
85  }
86