1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.SmallTests;
29 import org.apache.hadoop.hbase.util.FSTableDescriptors;
30 import org.junit.*;
31 import org.junit.experimental.categories.Category;
32
33 @Category(SmallTests.class)
34 public class TestFSTableDescriptorForceCreation {
35 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
36
37 @Test
38 public void testShouldCreateNewTableDescriptorIfForcefulCreationIsFalse()
39 throws IOException {
40 final String name = "newTable2";
41 FileSystem fs = FileSystem.get(UTIL.getConfiguration());
42 Path rootdir = new Path(UTIL.getDataTestDir(), name);
43 FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
44 HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
45
46 assertTrue("Should create new table descriptor", fstd.createTableDescriptor(htd, false));
47 }
48
49 @Test
50 public void testShouldNotCreateTheSameTableDescriptorIfForcefulCreationIsFalse()
51 throws IOException {
52 final String name = "testAlreadyExists";
53 FileSystem fs = FileSystem.get(UTIL.getConfiguration());
54
55 Path rootdir = new Path(UTIL.getDataTestDir(), name);
56 FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
57 HTableDescriptor htd = new HTableDescriptor(name);
58 fstd.add(htd);
59 assertFalse("Should not create new table descriptor", fstd.createTableDescriptor(htd, false));
60 }
61
62 @Test
63 public void testShouldAllowForcefulCreationOfAlreadyExistingTableDescriptor()
64 throws Exception {
65 final String name = "createNewTableNew2";
66 FileSystem fs = FileSystem.get(UTIL.getConfiguration());
67 Path rootdir = new Path(UTIL.getDataTestDir(), name);
68 FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir);
69 HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
70 fstd.createTableDescriptor(htd, false);
71 assertTrue("Should create new table descriptor",
72 fstd.createTableDescriptor(htd, true));
73 }
74
75 }
76