/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.hbase.master.procedure;

import static org.junit.Assert.assertTrue;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
import org.apache.hadoop.hbase.procedure2.RemoteProcedureDispatcher;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class TestTableDDLProcedureBase {
  private static final Logger LOG = LoggerFactory.getLogger(TestTableDDLProcedureBase.class);
  protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility();

  private static void setupConf(Configuration conf) {
    conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1);
    // increase the dispatch delay so we can do more batching
    conf.setInt(RemoteProcedureDispatcher.DISPATCH_DELAY_CONF_KEY, 2000);
  }

  @BeforeClass
  public static void setupCluster() throws Exception {
    setupConf(UTIL.getConfiguration());
    UTIL.startMiniCluster(1);
  }

  @AfterClass
  public static void cleanupTest() throws Exception {
    try {
      UTIL.shutdownMiniCluster();
    } catch (Exception e) {
      LOG.warn("failure shutting down cluster", e);
    }
  }

  @Before
  public void setup() throws Exception {
    resetProcExecutorTestingKillFlag();
  }

  @After
  public void tearDown() throws Exception {
    resetProcExecutorTestingKillFlag();
    for (TableDescriptor htd : UTIL.getAdmin().listTableDescriptors()) {
      LOG.info("Tear down, remove table=" + htd.getTableName());
      UTIL.deleteTable(htd.getTableName());
    }
  }

  protected void resetProcExecutorTestingKillFlag() {
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false);
    assertTrue("expected executor to be running", procExec.isRunning());
  }

  protected ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
    return getMaster().getMasterProcedureExecutor();
  }

  protected HMaster getMaster() {
    return UTIL.getHBaseCluster().getMaster();
  }
}

@@ -800,16 +800,17 @@
 se.%0A */%0A
+%0A
 package 
@@ -856,52 +856,8 @@
 e;%0A%0A
-import static org.junit.Assert.assertTrue;%0A%0A
 impo
@@ -984,15 +984,9 @@
 ase.
-client.
+H
 Tabl
@@ -1177,77 +1177,8 @@
 ty;%0A
-import org.apache.hadoop.hbase.procedure2.RemoteProcedureDispatcher;%0A
 impo
@@ -1339,16 +1339,60 @@
 ctory;%0A%0A
+import static org.junit.Assert.assertTrue;%0A%0A
 public a
@@ -1736,144 +1736,8 @@
 1);%0A
-    // increase the dispatch delay so we can do more batching%0A    conf.setInt(RemoteProcedureDispatcher.DISPATCH_DELAY_CONF_KEY, 2000);%0A
   %7D%0A
@@ -2283,16 +2283,17 @@
    for (
+H
 TableDes
@@ -2303,17 +2303,16 @@
 ptor htd
- 
 : UTIL.g
@@ -2330,26 +2330,16 @@
 istTable
-Descriptor
 s()) %7B%0A 

Revert "HBASE-21093 Increase the dispatch delay for testing DDL procedures"