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 java.io.IOException; 023import java.nio.file.FileSystems; 024import java.nio.file.Files; 025import java.nio.file.Path; 026import java.nio.file.StandardCopyOption; 027import org.apache.hadoop.conf.Configuration; 028import org.apache.hadoop.hbase.HBaseClassTestRule; 029import org.apache.hadoop.hbase.HBaseTestingUtility; 030import org.apache.hadoop.hbase.ServerName; 031import org.apache.hadoop.hbase.StartMiniClusterOption; 032import org.apache.hadoop.hbase.testclassification.MediumTests; 033import org.junit.BeforeClass; 034import org.junit.ClassRule; 035import org.junit.Test; 036import org.junit.experimental.categories.Category; 037import org.slf4j.Logger; 038import org.slf4j.LoggerFactory; 039 040@Category({MediumTests.class}) 041public class TestUpdateConfiguration { 042 043 @ClassRule 044 public static final HBaseClassTestRule CLASS_RULE = 045 HBaseClassTestRule.forClass(TestUpdateConfiguration.class); 046 047 private static final Logger LOG = LoggerFactory.getLogger(TestUpdateConfiguration.class); 048 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 049 050 @BeforeClass 051 public static void setup() throws Exception { 052 // Set master number and use default values for other options. 053 StartMiniClusterOption option = StartMiniClusterOption.builder().numMasters(2).build(); 054 TEST_UTIL.startMiniCluster(option); 055 } 056 057 @Test 058 public void testOnlineConfigChange() throws IOException { 059 LOG.debug("Starting the test"); 060 Admin admin = TEST_UTIL.getAdmin(); 061 ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName(); 062 admin.updateConfiguration(server); 063 } 064 065 @Test 066 public void testMasterOnlineConfigChange() throws IOException { 067 LOG.debug("Starting the test"); 068 Path cnfPath = FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml"); 069 Path cnf2Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml"); 070 Path cnf3Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml"); 071 // make a backup of hbase-site.xml 072 Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING); 073 // update hbase-site.xml by overwriting it 074 Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING); 075 076 Admin admin = TEST_UTIL.getAdmin(); 077 ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName(); 078 admin.updateConfiguration(server); 079 Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration(); 080 int custom = conf.getInt("hbase.custom.config", 0); 081 assertEquals(1000, custom); 082 // restore hbase-site.xml 083 Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING); 084 } 085 086 @Test 087 public void testAllOnlineConfigChange() throws IOException { 088 LOG.debug("Starting the test"); 089 Admin admin = TEST_UTIL.getAdmin(); 090 admin.updateConfiguration(); 091 } 092 093 @Test 094 public void testAllCustomOnlineConfigChange() throws IOException { 095 LOG.debug("Starting the test"); 096 Path cnfPath = FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml"); 097 Path cnf2Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml"); 098 Path cnf3Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml"); 099 // make a backup of hbase-site.xml 100 Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING); 101 // update hbase-site.xml by overwriting it 102 Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING); 103 104 Admin admin = TEST_UTIL.getAdmin(); 105 admin.updateConfiguration(); 106 107 // Check the configuration of the Masters 108 Configuration masterConfiguration = 109 TEST_UTIL.getMiniHBaseCluster().getMaster(0).getConfiguration(); 110 int custom = masterConfiguration.getInt("hbase.custom.config", 0); 111 assertEquals(1000, custom); 112 Configuration backupMasterConfiguration = 113 TEST_UTIL.getMiniHBaseCluster().getMaster(1).getConfiguration(); 114 custom = backupMasterConfiguration.getInt("hbase.custom.config", 0); 115 assertEquals(1000, custom); 116 117 // Check the configuration of the RegionServer 118 Configuration regionServerConfiguration = 119 TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getConfiguration(); 120 custom = regionServerConfiguration.getInt("hbase.custom.config", 0); 121 assertEquals(1000, custom); 122 123 // restore hbase-site.xml 124 Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING); 125 } 126}