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.assertEquals;
021
022import org.apache.hadoop.hbase.HBaseClassTestRule;
023import org.apache.hadoop.hbase.testclassification.ClientTests;
024import org.apache.hadoop.hbase.testclassification.MediumTests;
025import org.junit.ClassRule;
026import org.junit.Test;
027import org.junit.experimental.categories.Category;
028import org.junit.runner.RunWith;
029import org.junit.runners.Parameterized;
030
031/**
032 * Test the admin operations for Balancer, Normalizer, CleanerChore, and CatalogJanitor.
033 */
034@RunWith(Parameterized.class)
035@Category({ MediumTests.class, ClientTests.class })
036public class TestAsyncToolAdminApi extends TestAsyncAdminBase {
037
038  @ClassRule
039  public static final HBaseClassTestRule CLASS_RULE =
040      HBaseClassTestRule.forClass(TestAsyncToolAdminApi.class);
041
042  @Test
043  public void testBalancer() throws Exception {
044    boolean initialState = admin.isBalancerEnabled().get();
045
046    // Start the balancer, wait for it.
047    boolean prevState = admin.balancerSwitch(!initialState).get();
048
049    // The previous state should be the original state we observed
050    assertEquals(initialState, prevState);
051
052    // Current state should be opposite of the original
053    assertEquals(!initialState, admin.isBalancerEnabled().get());
054
055    // Reset it back to what it was
056    prevState = admin.balancerSwitch(initialState).get();
057
058    // The previous state should be the opposite of the initial state
059    assertEquals(!initialState, prevState);
060
061    // Current state should be the original state again
062    assertEquals(initialState, admin.isBalancerEnabled().get());
063  }
064
065  @Test
066  public void testNormalizer() throws Exception {
067    boolean initialState = admin.isNormalizerEnabled().get();
068
069    // flip state
070    boolean prevState = admin.normalizerSwitch(!initialState).get();
071
072    // The previous state should be the original state we observed
073    assertEquals(initialState, prevState);
074
075    // Current state should be opposite of the original
076    assertEquals(!initialState, admin.isNormalizerEnabled().get());
077
078    // Reset it back to what it was
079    prevState = admin.normalizerSwitch(initialState).get();
080
081    // The previous state should be the opposite of the initial state
082    assertEquals(!initialState, prevState);
083
084    // Current state should be the original state again
085    assertEquals(initialState, admin.isNormalizerEnabled().get());
086  }
087
088  @Test
089  public void testCleanerChore() throws Exception {
090    boolean initialState = admin.isCleanerChoreEnabled().get();
091
092    // flip state
093    boolean prevState = admin.cleanerChoreSwitch(!initialState).get();
094
095    // The previous state should be the original state we observed
096    assertEquals(initialState, prevState);
097
098    // Current state should be opposite of the original
099    assertEquals(!initialState, admin.isCleanerChoreEnabled().get());
100
101    // Reset it back to what it was
102    prevState = admin.cleanerChoreSwitch(initialState).get();
103
104    // The previous state should be the opposite of the initial state
105    assertEquals(!initialState, prevState);
106
107    // Current state should be the original state again
108    assertEquals(initialState, admin.isCleanerChoreEnabled().get());
109  }
110
111  @Test
112  public void testCatalogJanitor() throws Exception {
113    boolean initialState = admin.isCatalogJanitorEnabled().get();
114
115    // flip state
116    boolean prevState = admin.catalogJanitorSwitch(!initialState).get();
117
118    // The previous state should be the original state we observed
119    assertEquals(initialState, prevState);
120
121    // Current state should be opposite of the original
122    assertEquals(!initialState, admin.isCatalogJanitorEnabled().get());
123
124    // Reset it back to what it was
125    prevState = admin.catalogJanitorSwitch(initialState).get();
126
127    // The previous state should be the opposite of the initial state
128    assertEquals(!initialState, prevState);
129
130    // Current state should be the original state again
131    assertEquals(initialState, admin.isCatalogJanitorEnabled().get());
132  }
133}