001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import static org.junit.Assert.*;
021
022import java.io.IOException;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.HBaseTestingUtility;
026import org.apache.hadoop.hbase.io.HFileLink;
027import org.apache.hadoop.hbase.testclassification.RegionServerTests;
028import org.apache.hadoop.hbase.testclassification.SmallTests;
029import org.junit.ClassRule;
030import org.junit.Test;
031import org.junit.experimental.categories.Category;
032
033/**
034 * Test HStoreFile
035 */
036@Category({RegionServerTests.class, SmallTests.class})
037public class TestStoreFileInfo {
038
039  @ClassRule
040  public static final HBaseClassTestRule CLASS_RULE =
041      HBaseClassTestRule.forClass(TestStoreFileInfo.class);
042
043  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
044
045  /**
046   * Validate that we can handle valid tables with '.', '_', and '-' chars.
047   */
048  @Test
049  public void testStoreFileNames() {
050    String[] legalHFileLink = { "MyTable_02=abc012-def345", "MyTable_02.300=abc012-def345",
051      "MyTable_02-400=abc012-def345", "MyTable_02-400.200=abc012-def345",
052      "MyTable_02=abc012-def345_SeqId_1_", "MyTable_02=abc012-def345_SeqId_20_" };
053    for (String name: legalHFileLink) {
054      assertTrue("should be a valid link: " + name, HFileLink.isHFileLink(name));
055      assertTrue("should be a valid StoreFile" + name, StoreFileInfo.validateStoreFileName(name));
056      assertFalse("should not be a valid reference: " + name, StoreFileInfo.isReference(name));
057
058      String refName = name + ".6789";
059      assertTrue("should be a valid link reference: " + refName,
060          StoreFileInfo.isReference(refName));
061      assertTrue("should be a valid StoreFile" + refName,
062          StoreFileInfo.validateStoreFileName(refName));
063    }
064
065    String[] illegalHFileLink = { ".MyTable_02=abc012-def345", "-MyTable_02.300=abc012-def345",
066      "MyTable_02-400=abc0_12-def345", "MyTable_02-400.200=abc012-def345...." };
067    for (String name: illegalHFileLink) {
068      assertFalse("should not be a valid link: " + name, HFileLink.isHFileLink(name));
069    }
070  }
071
072  @Test
073  public void testEqualsWithLink() throws IOException {
074    Path origin = new Path("/origin");
075    Path tmp = TEST_UTIL.getDataTestDir();
076    Path mob = new Path("/mob");
077    Path archive = new Path("/archive");
078    HFileLink link1 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
079      new Path(mob, "f1"), new Path(archive, "f1"));
080    HFileLink link2 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"),
081      new Path(mob, "f1"), new Path(archive, "f1"));
082
083    StoreFileInfo info1 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
084      TEST_UTIL.getTestFileSystem(), null, link1);
085    StoreFileInfo info2 = new StoreFileInfo(TEST_UTIL.getConfiguration(),
086      TEST_UTIL.getTestFileSystem(), null, link2);
087
088    assertEquals(info1, info2);
089    assertEquals(info1.hashCode(), info2.hashCode());
090  }
091}
092