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