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