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.chaos.actions;
019
020import org.apache.hadoop.hbase.HBaseClassTestRule;
021import org.apache.hadoop.hbase.IntegrationTestingUtility;
022import org.apache.hadoop.hbase.TableName;
023import org.apache.hadoop.hbase.client.Admin;
024import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
025import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
026import org.apache.hadoop.hbase.testclassification.MediumTests;
027import org.junit.AfterClass;
028import org.junit.Before;
029import org.junit.BeforeClass;
030import org.junit.ClassRule;
031import org.junit.Test;
032import org.junit.experimental.categories.Category;
033import org.mockito.Mockito;
034
035@Category({MediumTests.class})
036public class TestChangeSplitPolicyAction extends Action {
037
038  @ClassRule
039  public static final HBaseClassTestRule CLASS_RULE =
040      HBaseClassTestRule.forClass(TestChangeSplitPolicyAction.class);
041
042  private final static IntegrationTestingUtility TEST_UTIL = new IntegrationTestingUtility();
043  private static ChangeSplitPolicyAction action;
044  private Admin admin;
045  private TableName tableName = TableName.valueOf("ChangeSplitPolicyAction");
046
047  @BeforeClass
048  public static void setUpBeforeClass() throws Exception {
049    TEST_UTIL.startMiniCluster(2);
050  }
051  @AfterClass
052  public static void tearDownAfterClass() throws Exception {
053    TEST_UTIL.shutdownMiniCluster();
054  }
055  @Before
056  public void setUp() throws Exception {
057    this.admin = TEST_UTIL.getAdmin();
058    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
059    admin.createTable(builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam")).build());
060  }
061
062  @Test
063  public void testChangeSplitPolicyAction() throws Exception {
064    ActionContext ctx = Mockito.mock(ActionContext.class);
065    Mockito.when(ctx.getHBaseIntegrationTestingUtility()).thenReturn(TEST_UTIL);
066    Mockito.when(ctx.getHBaseCluster()).thenReturn(TEST_UTIL.getHBaseCluster());
067    action = new ChangeSplitPolicyAction(tableName);
068    action.init(ctx);
069    action.perform();
070  }
071}