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.fail;
021
022import java.io.IOException;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.log.HBaseMarkers;
026import org.apache.hadoop.hbase.testclassification.MiscTests;
027import org.apache.hadoop.hbase.testclassification.SmallTests;
028import org.junit.ClassRule;
029import org.junit.Test;
030import org.junit.experimental.categories.Category;
031import org.slf4j.Logger;
032import org.slf4j.LoggerFactory;
033
034/**
035 * Test requirement that root directory must be a URI
036 */
037@Category({ MiscTests.class, SmallTests.class })
038public class TestRootPath {
039
040  @ClassRule
041  public static final HBaseClassTestRule CLASS_RULE =
042    HBaseClassTestRule.forClass(TestRootPath.class);
043
044  private static final Logger LOG = LoggerFactory.getLogger(TestRootPath.class);
045
046  /** The test */
047  @Test
048  public void testRootPath() {
049    try {
050      // Try good path
051      CommonFSUtils.validateRootPath(new Path("file:///tmp/hbase/hbase"));
052    } catch (IOException e) {
053      LOG.error(HBaseMarkers.FATAL, "Unexpected exception checking valid path:", e);
054      fail();
055    }
056    try {
057      // Try good path
058      CommonFSUtils.validateRootPath(new Path("hdfs://a:9000/hbase"));
059    } catch (IOException e) {
060      LOG.error(HBaseMarkers.FATAL, "Unexpected exception checking valid path:", e);
061      fail();
062    }
063    try {
064      // bad path
065      CommonFSUtils.validateRootPath(new Path("/hbase"));
066      fail();
067    } catch (IOException e) {
068      // Expected.
069      LOG.info("Got expected exception when checking invalid path:", e);
070    }
071  }
072
073}