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 */ 018 019package org.apache.hadoop.hbase.master.procedure; 020 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.hbase.HBaseTestingUtility; 023import org.apache.hadoop.hbase.HTableDescriptor; 024import org.apache.hadoop.hbase.master.HMaster; 025import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 026import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; 027import org.junit.After; 028import org.junit.AfterClass; 029import org.junit.Before; 030import org.junit.BeforeClass; 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034import static org.junit.Assert.assertTrue; 035 036public abstract class TestTableDDLProcedureBase { 037 private static final Logger LOG = LoggerFactory.getLogger(TestTableDDLProcedureBase.class); 038 protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); 039 040 private static void setupConf(Configuration conf) { 041 conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); 042 //testxxxDoubleExecution requires only one worker 043 conf.setInt(MasterProcedureConstants.MASTER_URGENT_PROCEDURE_THREADS, 0); 044 } 045 046 @BeforeClass 047 public static void setupCluster() throws Exception { 048 setupConf(UTIL.getConfiguration()); 049 UTIL.startMiniCluster(1); 050 } 051 052 @AfterClass 053 public static void cleanupTest() throws Exception { 054 try { 055 UTIL.shutdownMiniCluster(); 056 } catch (Exception e) { 057 LOG.warn("failure shutting down cluster", e); 058 } 059 } 060 061 @Before 062 public void setup() throws Exception { 063 resetProcExecutorTestingKillFlag(); 064 } 065 066 @After 067 public void tearDown() throws Exception { 068 resetProcExecutorTestingKillFlag(); 069 for (HTableDescriptor htd: UTIL.getAdmin().listTables()) { 070 LOG.info("Tear down, remove table=" + htd.getTableName()); 071 UTIL.deleteTable(htd.getTableName()); 072 } 073 } 074 075 protected void resetProcExecutorTestingKillFlag() { 076 final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); 077 ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); 078 assertTrue("expected executor to be running", procExec.isRunning()); 079 } 080 081 protected ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { 082 return getMaster().getMasterProcedureExecutor(); 083 } 084 085 protected HMaster getMaster() { 086 return UTIL.getHBaseCluster().getMaster(); 087 } 088}