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.client;
020
021import static junit.framework.TestCase.assertTrue;
022
023import java.io.IOException;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.HBaseTestingUtility;
026import org.apache.hadoop.hbase.HTableDescriptor;
027import org.apache.hadoop.hbase.TableName;
028import org.apache.hadoop.hbase.testclassification.ClientTests;
029import org.apache.hadoop.hbase.testclassification.LargeTests;
030import org.junit.After;
031import org.junit.AfterClass;
032import org.junit.Before;
033import org.junit.BeforeClass;
034import org.junit.ClassRule;
035import org.junit.Rule;
036import org.junit.Test;
037import org.junit.experimental.categories.Category;
038import org.junit.rules.TestName;
039import org.slf4j.Logger;
040import org.slf4j.LoggerFactory;
041
042/**
043 * Class to test HBaseHbck.
044 * Spins up the minicluster once at test start and then takes it down afterward.
045 * Add any testing of HBaseHbck functionality here.
046 */
047@Category({LargeTests.class, ClientTests.class})
048public class TestHbck {
049  @ClassRule
050  public static final HBaseClassTestRule CLASS_RULE =
051      HBaseClassTestRule.forClass(TestHbck.class);
052
053  private static final Logger LOG = LoggerFactory.getLogger(TestHbck.class);
054  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
055  private Admin admin;
056  private Hbck hbck;
057
058  @Rule
059  public TestName name = new TestName();
060
061  private static final TableName tableName = TableName.valueOf(TestHbck.class.getSimpleName());
062
063  @BeforeClass
064  public static void setUpBeforeClass() throws Exception {
065    TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
066    TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
067    TEST_UTIL.getConfiguration().setInt("hbase.client.retries.number", 6);
068    TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true);
069    TEST_UTIL.startMiniCluster(3);
070
071    TEST_UTIL.createTable(tableName, "family1");
072  }
073
074  @AfterClass
075  public static void tearDownAfterClass() throws Exception {
076    TEST_UTIL.shutdownMiniCluster();
077  }
078
079  @Before
080  public void setUp() throws Exception {
081    this.admin = TEST_UTIL.getAdmin();
082    this.hbck = TEST_UTIL.getHbck();
083  }
084
085  @After
086  public void tearDown() throws Exception {
087    for (HTableDescriptor htd : this.admin.listTables()) {
088      TEST_UTIL.deleteTable(htd.getTableName());
089    }
090    this.hbck.close();
091  }
092
093  @Test
094  public void testSetTableStateInMeta() throws IOException {
095    // set table state to DISABLED
096    hbck.setTableStateInMeta(new TableState(tableName, TableState.State.DISABLED));
097    // Method {@link Hbck#setTableStateInMeta()} returns previous state, which in this case
098    // will be DISABLED
099    TableState prevState =
100        hbck.setTableStateInMeta(new TableState(tableName, TableState.State.ENABLED));
101    assertTrue("Incorrect previous state! expeced=DISABLED, found=" + prevState.getState(),
102        prevState.isDisabled());
103  }
104}