View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.util;
21  
22  import junit.framework.TestCase;
23  
24  import java.io.IOException;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  import org.apache.hadoop.fs.Path;
30  import org.apache.hadoop.hbase.SmallTests;
31  import org.junit.experimental.categories.Category;
32  
33  /**
34   * Test requirement that root directory must be a URI
35   */
36  @Category(SmallTests.class)
37  public class TestRootPath extends TestCase {
38    private static final Log LOG = LogFactory.getLog(TestRootPath.class);
39  
40    /** The test */
41    public void testRootPath() {
42      try {
43        // Try good path
44        FSUtils.validateRootPath(new Path("file:///tmp/hbase/hbase"));
45      } catch (IOException e) {
46        LOG.fatal("Unexpected exception checking valid path:", e);
47        fail();
48      }
49      try {
50        // Try good path
51        FSUtils.validateRootPath(new Path("hdfs://a:9000/hbase"));
52      } catch (IOException e) {
53        LOG.fatal("Unexpected exception checking valid path:", e);
54        fail();
55      }
56      try {
57        // bad path
58        FSUtils.validateRootPath(new Path("/hbase"));
59        fail();
60      } catch (IOException e) {
61        // Expected.
62        LOG.info("Got expected exception when checking invalid path:", e);
63      }
64    }
65  
66  }
67