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.client;
019
020import static org.junit.Assert.assertNotNull;
021
022import java.io.IOException;
023import org.apache.hadoop.hbase.HBaseTestingUtility;
024import org.apache.hadoop.hbase.HConstants;
025import org.apache.hadoop.hbase.MetaTableAccessor;
026import org.apache.hadoop.hbase.TableName;
027import org.junit.After;
028import org.junit.AfterClass;
029import org.junit.BeforeClass;
030import org.junit.Rule;
031import org.junit.rules.TestName;
032
033public class TestAdminBase {
034
035  protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
036  protected final static int NB_SERVERS = 3;
037  protected static Admin ADMIN;
038
039  @Rule
040  public TestName name = new TestName();
041
042  @BeforeClass
043  public static void setUpBeforeClass() throws Exception {
044    TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
045    TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
046    TEST_UTIL.getConfiguration().setInt("hbase.client.retries.number", 6);
047    TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true);
048    TEST_UTIL.getConfiguration().setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 30);
049    TEST_UTIL.getConfiguration().setInt(HConstants.REGION_SERVER_HANDLER_COUNT, 30);
050    TEST_UTIL.getConfiguration().setBoolean(HConstants.SLOW_LOG_BUFFER_ENABLED_KEY, true);
051    TEST_UTIL.startMiniCluster(NB_SERVERS);
052    ADMIN = TEST_UTIL.getAdmin();
053  }
054
055  @AfterClass
056  public static void tearDownAfterClass() throws Exception {
057    TEST_UTIL.shutdownMiniCluster();
058  }
059
060  @After
061  public void tearDown() throws Exception {
062    for (TableDescriptor htd : ADMIN.listTableDescriptors()) {
063      TEST_UTIL.deleteTable(htd.getTableName());
064    }
065  }
066
067  protected TableState.State getStateFromMeta(TableName table) throws IOException {
068    TableState state = MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), table);
069    assertNotNull(state);
070    return state.getState();
071  }
072}