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.mob;
019
020import java.io.IOException;
021import org.apache.hadoop.conf.Configuration;
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.HBaseConfiguration;
026import org.apache.hadoop.hbase.TableName;
027import org.apache.hadoop.hbase.io.HFileLink;
028import org.apache.hadoop.hbase.testclassification.SmallTests;
029import org.apache.hadoop.hbase.util.FSUtils;
030import org.apache.hadoop.hbase.util.HFileArchiveUtil;
031import org.junit.Assert;
032import org.junit.ClassRule;
033import org.junit.Rule;
034import org.junit.Test;
035import org.junit.experimental.categories.Category;
036import org.junit.rules.TestName;
037
038@Category(SmallTests.class)
039public class TestMobFileLink {
040
041  @ClassRule
042  public static final HBaseClassTestRule CLASS_RULE =
043      HBaseClassTestRule.forClass(TestMobFileLink.class);
044
045  @Rule
046  public TestName name = new TestName();
047
048  @Test
049  public void testMobFilePath() throws IOException {
050    final TableName tableName = TableName.valueOf(name.getMethodName());
051    Configuration conf = HBaseConfiguration.create();
052    FileSystem fs = FileSystem.get(conf);
053    Path rootDir = FSUtils.getRootDir(conf);
054    Path tableDir = FSUtils.getTableDir(rootDir, tableName);
055    Path archiveDir = FSUtils.getTableDir(HFileArchiveUtil.getArchivePath(conf), tableName);
056    String fileName = "mobFile";
057    String encodedRegionName = MobUtils.getMobRegionInfo(tableName).getEncodedName();
058    String columnFamily = "columnFamily";
059    Path regionDir = new Path(tableDir, encodedRegionName);
060    Path archivedRegionDir = new Path(archiveDir, encodedRegionName);
061    Path expectedMobFilePath = new Path(MobUtils.getMobFamilyPath(conf, tableName, columnFamily),
062      fileName).makeQualified(fs.getUri(), fs.getWorkingDirectory());
063    Path expectedOriginPath = new Path(new Path(regionDir, columnFamily), fileName).makeQualified(
064      fs.getUri(), fs.getWorkingDirectory());
065    Path expectedArchivePath = new Path(new Path(archivedRegionDir, columnFamily), fileName)
066      .makeQualified(fs.getUri(), fs.getWorkingDirectory());
067
068    String hfileLinkName = tableName.getNameAsString() + "=" + encodedRegionName + "-" + fileName;
069    Path hfileLinkPath = new Path(columnFamily, hfileLinkName);
070    HFileLink hfileLink = HFileLink.buildFromHFileLinkPattern(conf, hfileLinkPath);
071    Assert.assertEquals(expectedMobFilePath, hfileLink.getMobPath());
072    Assert.assertEquals(expectedOriginPath, hfileLink.getOriginPath());
073    Assert.assertEquals(expectedArchivePath, hfileLink.getArchivePath());
074  }
075}