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.region;
019
020import static org.junit.Assert.assertEquals;
021
022import java.io.IOException;
023import org.apache.hadoop.hbase.HBaseClassTestRule;
024import org.apache.hadoop.hbase.HBaseTestingUtil;
025import org.apache.hadoop.hbase.HConstants;
026import org.apache.hadoop.hbase.TableName;
027import org.apache.hadoop.hbase.client.TableDescriptor;
028import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
029import org.apache.hadoop.hbase.testclassification.MasterTests;
030import org.apache.hadoop.hbase.testclassification.MediumTests;
031import org.apache.hadoop.hbase.util.Bytes;
032import org.junit.AfterClass;
033import org.junit.BeforeClass;
034import org.junit.ClassRule;
035import org.junit.Test;
036import org.junit.experimental.categories.Category;
037
038/**
039 * Make sure we do not loss data after changing SFT implementation
040 */
041@Category({ MasterTests.class, MediumTests.class })
042public class TestChangeSFTForMasterRegion {
043
044  @ClassRule
045  public static final HBaseClassTestRule CLASS_RULE =
046    HBaseClassTestRule.forClass(TestChangeSFTForMasterRegion.class);
047
048  private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
049
050  private static TableName NAME = TableName.valueOf("test");
051
052  private static byte[] FAMILY = Bytes.toBytes("family");
053
054  @BeforeClass
055  public static void setUp() throws Exception {
056    UTIL.getConfiguration().set(MasterRegionFactory.TRACKER_IMPL,
057      StoreFileTrackerFactory.Trackers.DEFAULT.name());
058    // use zk connection registry, as we will shutdown the only master instance which will likely to
059    // lead to dead loop
060    UTIL.getConfiguration().set(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
061      HConstants.ZK_CONNECTION_REGISTRY_CLASS);
062    UTIL.startMiniCluster(1);
063    UTIL.createTable(NAME, FAMILY).close();
064  }
065
066  @AfterClass
067  public static void tearDown() throws IOException {
068    UTIL.shutdownMiniCluster();
069  }
070
071  @Test
072  public void test() throws Exception {
073    // shutdown master
074    UTIL.getMiniHBaseCluster().stopMaster(0).join();
075    UTIL.getMiniHBaseCluster().getConf().set(MasterRegionFactory.TRACKER_IMPL,
076      StoreFileTrackerFactory.Trackers.FILE.name());
077    UTIL.getMiniHBaseCluster().startMaster();
078    // make sure that the table still exists
079    UTIL.waitTableAvailable(NAME);
080    // confirm that we have changed the SFT to FILE
081    TableDescriptor td =
082      UTIL.getMiniHBaseCluster().getMaster().getMasterRegion().region.getTableDescriptor();
083    assertEquals(StoreFileTrackerFactory.Trackers.FILE.name(),
084      td.getValue(StoreFileTrackerFactory.TRACKER_IMPL));
085  }
086}