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