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.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      // Step 1: start mini zk cluster.
51      MiniZooKeeperCluster zkCluster;
52      zkCluster = TEST_UTIL.startMiniZKCluster();
53      // Step 2: add an orphaned system table ZNODE
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      // Step 3: link the zk cluster to hbase cluster
63      TEST_UTIL.setZkCluster(zkCluster);
64      // Step 4: start hbase cluster and expect master to start successfully.
65      TEST_UTIL.startMiniCluster();
66      assertTrue(TEST_UTIL.getHBaseCluster().getLiveMasterThreads().size() == 1);
67    }
68  }