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.mob;
20  
21  import java.io.IOException;
22  
23  import org.apache.hadoop.conf.Configuration;
24  import org.apache.hadoop.fs.FileSystem;
25  import org.apache.hadoop.fs.Path;
26  import org.apache.hadoop.hbase.HBaseConfiguration;
27  import org.apache.hadoop.hbase.TableName;
28  import org.apache.hadoop.hbase.io.HFileLink;
29  import org.apache.hadoop.hbase.testclassification.SmallTests;
30  import org.apache.hadoop.hbase.util.FSUtils;
31  import org.apache.hadoop.hbase.util.HFileArchiveUtil;
32  import org.junit.Assert;
33  import org.junit.Test;
34  import org.junit.experimental.categories.Category;
35  
36  @Category(SmallTests.class)
37  public class TestMobFileLink {
38  
39    @Test
40    public void testMobFilePath() throws IOException {
41      TableName tableName = TableName.valueOf("testMobFilePath");
42      Configuration conf = HBaseConfiguration.create();
43      FileSystem fs = FileSystem.get(conf);
44      Path rootDir = FSUtils.getRootDir(conf);
45      Path tableDir = FSUtils.getTableDir(rootDir, tableName);
46      Path archiveDir = FSUtils.getTableDir(HFileArchiveUtil.getArchivePath(conf), tableName);
47      String fileName = "mobFile";
48      String encodedRegionName = MobUtils.getMobRegionInfo(tableName).getEncodedName();
49      String columnFamily = "columnFamily";
50      Path regionDir = new Path(tableDir, encodedRegionName);
51      Path archivedRegionDir = new Path(archiveDir, encodedRegionName);
52      Path expectedMobFilePath = new Path(MobUtils.getMobFamilyPath(conf, tableName, columnFamily),
53        fileName).makeQualified(fs.getUri(), fs.getWorkingDirectory());
54      Path expectedOriginPath = new Path(new Path(regionDir, columnFamily), fileName).makeQualified(
55        fs.getUri(), fs.getWorkingDirectory());
56      Path expectedArchivePath = new Path(new Path(archivedRegionDir, columnFamily), fileName)
57        .makeQualified(fs.getUri(), fs.getWorkingDirectory());
58  
59      String hfileLinkName = tableName.getNameAsString() + "=" + encodedRegionName + "-" + fileName;
60      Path hfileLinkPath = new Path(columnFamily, hfileLinkName);
61      HFileLink hfileLink = HFileLink.buildFromHFileLinkPattern(conf, hfileLinkPath);
62      Assert.assertEquals(expectedMobFilePath, hfileLink.getMobPath());
63      Assert.assertEquals(expectedOriginPath, hfileLink.getOriginPath());
64      Assert.assertEquals(expectedArchivePath, hfileLink.getArchivePath());
65    }
66  }