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.hamcrest.MatcherAssert.assertThat; 021import static org.hamcrest.Matchers.containsString; 022import static org.junit.jupiter.api.Assertions.assertEquals; 023import static org.junit.jupiter.api.Assertions.assertFalse; 024import static org.junit.jupiter.api.Assertions.assertNotEquals; 025import static org.junit.jupiter.api.Assertions.assertThrows; 026import static org.junit.jupiter.api.Assertions.assertTrue; 027 028import java.io.IOException; 029import java.util.ArrayList; 030import java.util.List; 031import org.apache.hadoop.hbase.ServerName; 032import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 033import org.apache.hadoop.hbase.testclassification.ClientTests; 034import org.apache.hadoop.hbase.testclassification.MediumTests; 035import org.apache.hadoop.hbase.zookeeper.ZKUtil; 036import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 037import org.apache.hadoop.hbase.zookeeper.ZNodePaths; 038import org.junit.jupiter.api.Tag; 039import org.junit.jupiter.api.Test; 040 041@Tag(MediumTests.TAG) 042@Tag(ClientTests.TAG) 043public class TestAdmin4 extends TestAdminBase { 044 045 // For HBASE-24208 046 @Test 047 public void testDecommissionAndStopRegionServers() throws Exception { 048 List<ServerName> decommissionedRegionServers = ADMIN.listDecommissionedRegionServers(); 049 assertTrue(decommissionedRegionServers.isEmpty()); 050 051 ArrayList<ServerName> clusterRegionServers = new ArrayList<>(ADMIN.getRegionServers(true)); 052 053 List<ServerName> serversToDecommission = new ArrayList<ServerName>(); 054 serversToDecommission.add(clusterRegionServers.get(0)); 055 056 // Decommission 057 ADMIN.decommissionRegionServers(serversToDecommission, true); 058 assertEquals(1, ADMIN.listDecommissionedRegionServers().size()); 059 060 // Stop decommissioned region server and verify it is removed from draining znode 061 ServerName serverName = serversToDecommission.get(0); 062 ADMIN.stopRegionServer(serverName.getHostname() + ":" + serverName.getPort()); 063 assertNotEquals(-1, 064 TEST_UTIL.waitFor(10000, () -> ADMIN.listDecommissionedRegionServers().isEmpty()), 065 "RS not removed from decommissioned list"); 066 ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher(); 067 assertEquals(-1, ZKUtil.checkExists(zkw, 068 ZNodePaths.joinZNode(zkw.getZNodePaths().drainingZNode, serverName.getServerName()))); 069 } 070 071 @Test 072 public void testReplicationPeerModificationSwitch() throws Exception { 073 assertTrue(ADMIN.isReplicationPeerModificationEnabled()); 074 try { 075 // disable modification, should returns true as it is enabled by default and the above 076 // assertion has confirmed it 077 assertTrue(ADMIN.replicationPeerModificationSwitch(false)); 078 IOException error = 079 assertThrows(IOException.class, () -> ADMIN.addReplicationPeer("peer", ReplicationPeerConfig 080 .newBuilder().setClusterKey(TEST_UTIL.getRpcConnnectionURI()).build())); 081 assertThat(error.getCause().getMessage(), 082 containsString("Replication peer modification disabled")); 083 // enable again, and the previous value should be false 084 assertFalse(ADMIN.replicationPeerModificationSwitch(true)); 085 } finally { 086 // always reset to avoid mess up other tests 087 ADMIN.replicationPeerModificationSwitch(true); 088 } 089 } 090}