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