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 static org.junit.jupiter.api.Assertions.assertEquals; 021 022import java.io.IOException; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.fs.FileSystem; 025import org.apache.hadoop.fs.Path; 026import org.apache.hadoop.hbase.HBaseConfiguration; 027import org.apache.hadoop.hbase.TableName; 028import org.apache.hadoop.hbase.io.HFileLink; 029import org.apache.hadoop.hbase.testclassification.SmallTests; 030import org.apache.hadoop.hbase.util.CommonFSUtils; 031import org.apache.hadoop.hbase.util.HFileArchiveUtil; 032import org.junit.jupiter.api.Tag; 033import org.junit.jupiter.api.Test; 034import org.junit.jupiter.api.TestInfo; 035 036@Tag(SmallTests.TAG) 037public class TestMobFileLink { 038 039 @Test 040 public void testMobFilePath(TestInfo testInfo) throws IOException { 041 final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); 042 Configuration conf = HBaseConfiguration.create(); 043 FileSystem fs = FileSystem.get(conf); 044 Path rootDir = CommonFSUtils.getRootDir(conf); 045 Path tableDir = CommonFSUtils.getTableDir(rootDir, tableName); 046 Path archiveDir = CommonFSUtils.getTableDir(HFileArchiveUtil.getArchivePath(conf), tableName); 047 String fileName = "mobFile"; 048 String encodedRegionName = MobUtils.getMobRegionInfo(tableName).getEncodedName(); 049 String columnFamily = "columnFamily"; 050 Path regionDir = new Path(tableDir, encodedRegionName); 051 Path archivedRegionDir = new Path(archiveDir, encodedRegionName); 052 Path expectedMobFilePath = 053 new Path(MobUtils.getMobFamilyPath(conf, tableName, columnFamily), fileName) 054 .makeQualified(fs.getUri(), fs.getWorkingDirectory()); 055 Path expectedOriginPath = new Path(new Path(regionDir, columnFamily), fileName) 056 .makeQualified(fs.getUri(), fs.getWorkingDirectory()); 057 Path expectedArchivePath = new Path(new Path(archivedRegionDir, columnFamily), fileName) 058 .makeQualified(fs.getUri(), fs.getWorkingDirectory()); 059 060 String hfileLinkName = tableName.getNameAsString() + "=" + encodedRegionName + "-" + fileName; 061 Path hfileLinkPath = new Path(columnFamily, hfileLinkName); 062 HFileLink hfileLink = HFileLink.buildFromHFileLinkPattern(conf, hfileLinkPath); 063 assertEquals(expectedMobFilePath, hfileLink.getMobPath()); 064 assertEquals(expectedOriginPath, hfileLink.getOriginPath()); 065 assertEquals(expectedArchivePath, hfileLink.getArchivePath()); 066 } 067}