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