001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master; 019 020import org.apache.hadoop.hbase.HBaseClassTestRule; 021import org.apache.hadoop.hbase.HBaseTestingUtility; 022import org.apache.hadoop.hbase.HConstants; 023import org.apache.hadoop.hbase.MetaTableAccessor; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.client.TableState; 026import org.apache.hadoop.hbase.testclassification.LargeTests; 027import org.apache.hadoop.hbase.testclassification.MasterTests; 028import org.apache.hadoop.hbase.util.JVMClusterUtil; 029import org.apache.hadoop.hbase.util.Threads; 030import org.junit.After; 031import org.junit.Assert; 032import org.junit.Before; 033import org.junit.ClassRule; 034import org.junit.Rule; 035import org.junit.Test; 036import org.junit.experimental.categories.Category; 037import org.junit.rules.TestName; 038 039 040import static junit.framework.TestCase.assertTrue; 041 042/** 043 * Tests the default table lock manager 044 */ 045@Category({ MasterTests.class, LargeTests.class }) 046public class TestTableStateManager { 047 048 @ClassRule 049 public static final HBaseClassTestRule CLASS_RULE = 050 HBaseClassTestRule.forClass(TestTableStateManager.class); 051 052 private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 053 054 @Rule 055 public TestName name = new TestName(); 056 057 @Before 058 public void before() throws Exception { 059 TEST_UTIL.startMiniCluster(); 060 } 061 062 @After 063 public void after() throws Exception { 064 TEST_UTIL.shutdownMiniCluster(); 065 } 066 067 @Test 068 public void testMigration() throws Exception { 069 final TableName tableName = TableName.valueOf(name.getMethodName()); 070 TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY_STR); 071 TEST_UTIL.getAdmin().disableTable(tableName); 072 // Table is disabled. Now remove the DISABLED column from the hbase:meta for this table's 073 // region. We want to see if Master will read the DISABLED from zk and make use of it as 074 // though it were reading the zk table state written by a hbase-1.x cluster. 075 TableState state = MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), tableName); 076 assertTrue("State=" + state, state.getState().equals(TableState.State.DISABLED)); 077 MetaTableAccessor.deleteTableState(TEST_UTIL.getConnection(), tableName); 078 assertTrue(MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), tableName) == null); 079 // Now kill Master so a new one can come up and run through the zk migration. 080 HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); 081 master.stop("Restarting"); 082 while (!master.isStopped()) { 083 Threads.sleep(1); 084 } 085 assertTrue(master.isStopped()); 086 JVMClusterUtil.MasterThread newMasterThread = TEST_UTIL.getMiniHBaseCluster().startMaster(); 087 master = newMasterThread.getMaster(); 088 while (!master.isInitialized()) { 089 Threads.sleep(1); 090 } 091 assertTrue(MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), 092 tableName).getState().equals(TableState.State.DISABLED)); 093 } 094}