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