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.util;
019
020import static org.junit.Assert.assertNotNull;
021
022import java.io.IOException;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.fs.Path;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.TableName;
027import org.apache.hadoop.hbase.client.RegionInfo;
028import org.apache.hadoop.hbase.client.RegionInfoBuilder;
029import org.apache.hadoop.hbase.testclassification.MiscTests;
030import org.apache.hadoop.hbase.testclassification.SmallTests;
031import org.junit.ClassRule;
032import org.junit.Rule;
033import org.junit.Test;
034import org.junit.experimental.categories.Category;
035import org.junit.rules.TestName;
036
037/**
038 * Test that the utility works as expected
039 */
040@Category({ MiscTests.class, SmallTests.class })
041public class TestHFileArchiveUtil {
042
043  @ClassRule
044  public static final HBaseClassTestRule CLASS_RULE =
045    HBaseClassTestRule.forClass(TestHFileArchiveUtil.class);
046
047  private Path rootDir = new Path("./");
048
049  @Rule
050  public TestName name = new TestName();
051
052  @Test
053  public void testGetTableArchivePath() {
054    assertNotNull(
055      HFileArchiveUtil.getTableArchivePath(rootDir, TableName.valueOf(name.getMethodName())));
056  }
057
058  @Test
059  public void testGetArchivePath() throws Exception {
060    Configuration conf = new Configuration();
061    CommonFSUtils.setRootDir(conf, new Path("root"));
062    assertNotNull(HFileArchiveUtil.getArchivePath(conf));
063  }
064
065  @Test
066  public void testRegionArchiveDir() {
067    Path regionDir = new Path("region");
068    assertNotNull(HFileArchiveUtil.getRegionArchiveDir(rootDir,
069      TableName.valueOf(name.getMethodName()), regionDir));
070  }
071
072  @Test
073  public void testGetStoreArchivePath() throws IOException {
074    byte[] family = Bytes.toBytes("Family");
075    Path tabledir = CommonFSUtils.getTableDir(rootDir, TableName.valueOf(name.getMethodName()));
076    RegionInfo region =
077      RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
078    Configuration conf = new Configuration();
079    CommonFSUtils.setRootDir(conf, new Path("root"));
080    assertNotNull(HFileArchiveUtil.getStoreArchivePath(conf, region, tabledir, family));
081  }
082}