HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / mob / TestMobFileLink.java
blob57bcf1fd88eb27f8e0d7b7786762f8f380998aca
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.mob;
20 import java.io.IOException;
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.fs.FileSystem;
23 import org.apache.hadoop.fs.Path;
24 import org.apache.hadoop.hbase.HBaseClassTestRule;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.io.HFileLink;
28 import org.apache.hadoop.hbase.testclassification.SmallTests;
29 import org.apache.hadoop.hbase.util.FSUtils;
30 import org.apache.hadoop.hbase.util.HFileArchiveUtil;
31 import org.junit.Assert;
32 import org.junit.ClassRule;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36 import org.junit.rules.TestName;
38 @Category(SmallTests.class)
39 public class TestMobFileLink {
41 @ClassRule
42 public static final HBaseClassTestRule CLASS_RULE =
43 HBaseClassTestRule.forClass(TestMobFileLink.class);
45 @Rule
46 public TestName name = new TestName();
48 @Test
49 public void testMobFilePath() throws IOException {
50 final TableName tableName = TableName.valueOf(name.getMethodName());
51 Configuration conf = HBaseConfiguration.create();
52 FileSystem fs = FileSystem.get(conf);
53 Path rootDir = FSUtils.getRootDir(conf);
54 Path tableDir = FSUtils.getTableDir(rootDir, tableName);
55 Path archiveDir = FSUtils.getTableDir(HFileArchiveUtil.getArchivePath(conf), tableName);
56 String fileName = "mobFile";
57 String encodedRegionName = MobUtils.getMobRegionInfo(tableName).getEncodedName();
58 String columnFamily = "columnFamily";
59 Path regionDir = new Path(tableDir, encodedRegionName);
60 Path archivedRegionDir = new Path(archiveDir, encodedRegionName);
61 Path expectedMobFilePath = new Path(MobUtils.getMobFamilyPath(conf, tableName, columnFamily),
62 fileName).makeQualified(fs.getUri(), fs.getWorkingDirectory());
63 Path expectedOriginPath = new Path(new Path(regionDir, columnFamily), fileName).makeQualified(
64 fs.getUri(), fs.getWorkingDirectory());
65 Path expectedArchivePath = new Path(new Path(archivedRegionDir, columnFamily), fileName)
66 .makeQualified(fs.getUri(), fs.getWorkingDirectory());
68 String hfileLinkName = tableName.getNameAsString() + "=" + encodedRegionName + "-" + fileName;
69 Path hfileLinkPath = new Path(columnFamily, hfileLinkName);
70 HFileLink hfileLink = HFileLink.buildFromHFileLinkPattern(conf, hfileLinkPath);
71 Assert.assertEquals(expectedMobFilePath, hfileLink.getMobPath());
72 Assert.assertEquals(expectedOriginPath, hfileLink.getOriginPath());
73 Assert.assertEquals(expectedArchivePath, hfileLink.getArchivePath());