1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }