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  package org.apache.hadoop.hbase;
20  
21  import static org.junit.Assert.assertFalse;
22  import static org.junit.Assert.assertTrue;
23  
24  import java.io.IOException;
25  
26  import org.apache.hadoop.fs.FileSystem;
27  import org.apache.hadoop.fs.Path;
28  import org.apache.hadoop.hbase.testclassification.MiscTests;
29  import org.apache.hadoop.hbase.testclassification.SmallTests;
30  import org.apache.hadoop.hbase.util.FSTableDescriptors;
31  import org.junit.*;
32  import org.junit.experimental.categories.Category;
33  
34  @Category({MiscTests.class, SmallTests.class})
35  public class TestFSTableDescriptorForceCreation {
36    private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
37  
38    @Test
39    public void testShouldCreateNewTableDescriptorIfForcefulCreationIsFalse()
40        throws IOException {
41      final String name = "newTable2";
42      FileSystem fs = FileSystem.get(UTIL.getConfiguration());
43      Path rootdir = new Path(UTIL.getDataTestDir(), name);
44      FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
45      HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
46  
47      assertTrue("Should create new table descriptor", fstd.createTableDescriptor(htd, false));
48    }
49  
50    @Test
51    public void testShouldNotCreateTheSameTableDescriptorIfForcefulCreationIsFalse()
52        throws IOException {
53      final String name = "testAlreadyExists";
54      FileSystem fs = FileSystem.get(UTIL.getConfiguration());
55      // Cleanup old tests if any detritus laying around.
56      Path rootdir = new Path(UTIL.getDataTestDir(), name);
57      FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
58      HTableDescriptor htd = new HTableDescriptor(name);
59      fstd.add(htd);
60      assertFalse("Should not create new table descriptor", fstd.createTableDescriptor(htd, false));
61    }
62  
63    @Test
64    public void testShouldAllowForcefulCreationOfAlreadyExistingTableDescriptor()
65        throws Exception {
66      final String name = "createNewTableNew2";
67      FileSystem fs = FileSystem.get(UTIL.getConfiguration());
68      Path rootdir = new Path(UTIL.getDataTestDir(), name);
69      FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
70      HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
71      fstd.createTableDescriptor(htd, false);
72      assertTrue("Should create new table descriptor",
73          fstd.createTableDescriptor(htd, true));
74    }
75  
76  }
77