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