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.master;
019
020import static org.junit.Assert.assertEquals;
021
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.HBaseTestingUtility;
026import org.apache.hadoop.hbase.testclassification.MasterTests;
027import org.apache.hadoop.hbase.testclassification.MediumTests;
028import org.apache.hadoop.hbase.util.FSUtils;
029import org.junit.AfterClass;
030import org.junit.BeforeClass;
031import org.junit.ClassRule;
032import org.junit.Test;
033import org.junit.experimental.categories.Category;
034import org.slf4j.Logger;
035import org.slf4j.LoggerFactory;
036
037/**
038 * Test the master filesystem in a local cluster
039 */
040@Category({MasterTests.class, MediumTests.class})
041public class TestMasterFileSystem {
042
043  @ClassRule
044  public static final HBaseClassTestRule CLASS_RULE =
045      HBaseClassTestRule.forClass(TestMasterFileSystem.class);
046
047  private static final Logger LOG = LoggerFactory.getLogger(TestMasterFileSystem.class);
048
049  private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
050
051  @BeforeClass
052  public static void setupTest() throws Exception {
053    UTIL.startMiniCluster();
054  }
055
056  @AfterClass
057  public static void teardownTest() throws Exception {
058    UTIL.shutdownMiniCluster();
059  }
060
061  @Test
062  public void testFsUriSetProperly() throws Exception {
063    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
064    MasterFileSystem fs = master.getMasterFileSystem();
065    Path masterRoot = FSUtils.getRootDir(fs.getConfiguration());
066    Path rootDir = FSUtils.getRootDir(fs.getFileSystem().getConf());
067    // make sure the fs and the found root dir have the same scheme
068    LOG.debug("from fs uri:" + FileSystem.getDefaultUri(fs.getFileSystem().getConf()));
069    LOG.debug("from configuration uri:" + FileSystem.getDefaultUri(fs.getConfiguration()));
070    // make sure the set uri matches by forcing it.
071    assertEquals(masterRoot, rootDir);
072  }
073}