1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.master.procedure;
20
21 import static org.junit.Assert.assertTrue;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.hbase.HBaseTestingUtility;
26 import org.apache.hadoop.hbase.testclassification.MediumTests;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
29 import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos;
30 import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
31 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
32 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
33 import org.junit.After;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37 @Category(MediumTests.class)
38 public class TestCreateTableProcedure2 {
39 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
40 private static final Log LOG = LogFactory.getLog(TestCreateTableProcedure2.class);
41
42 @After
43 public void tearDown() throws Exception {
44 TEST_UTIL.shutdownMiniCluster();
45 TEST_UTIL.shutdownMiniZKCluster();
46 }
47
48 @Test
49 public void testMasterRestartAfterNameSpaceEnablingNodeIsCreated() throws Exception {
50
51 MiniZooKeeperCluster zkCluster;
52 zkCluster = TEST_UTIL.startMiniZKCluster();
53
54 TableName tableName = TableName.valueOf("hbase:namespace");
55 ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
56 String znode = ZKUtil.joinZNode(zkw.tableZNode, tableName.getNameAsString());
57 ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder();
58 builder.setState(ZooKeeperProtos.Table.State.ENABLED);
59 byte [] data = ProtobufUtil.prependPBMagic(builder.build().toByteArray());
60 ZKUtil.createSetData(zkw, znode, data);
61 LOG.info("Create an orphaned Znode " + znode + " with data " + data);
62
63 TEST_UTIL.setZkCluster(zkCluster);
64
65 TEST_UTIL.startMiniCluster();
66 assertTrue(TEST_UTIL.getHBaseCluster().getLiveMasterThreads().size() == 1);
67 }
68 }