HBASE-22002 Remove the deprecated methods in Admin interface
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestUpdateConfiguration.java
blobeae56fdd53c68b06ab7a8bd1105d6aba35ed39c1
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.client;
20 import static org.junit.Assert.assertEquals;
22 import java.io.IOException;
23 import java.nio.file.FileSystems;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.nio.file.StandardCopyOption;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.hbase.HBaseClassTestRule;
29 import org.apache.hadoop.hbase.HBaseTestingUtility;
30 import org.apache.hadoop.hbase.ServerName;
31 import org.apache.hadoop.hbase.StartMiniClusterOption;
32 import org.apache.hadoop.hbase.testclassification.MediumTests;
33 import org.junit.BeforeClass;
34 import org.junit.ClassRule;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 @Category({MediumTests.class})
41 public class TestUpdateConfiguration {
43 @ClassRule
44 public static final HBaseClassTestRule CLASS_RULE =
45 HBaseClassTestRule.forClass(TestUpdateConfiguration.class);
47 private static final Logger LOG = LoggerFactory.getLogger(TestUpdateConfiguration.class);
48 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
50 @BeforeClass
51 public static void setup() throws Exception {
52 // Set master number and use default values for other options.
53 StartMiniClusterOption option = StartMiniClusterOption.builder().numMasters(2).build();
54 TEST_UTIL.startMiniCluster(option);
57 @Test
58 public void testOnlineConfigChange() throws IOException {
59 LOG.debug("Starting the test");
60 Admin admin = TEST_UTIL.getAdmin();
61 ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
62 admin.updateConfiguration(server);
65 @Test
66 public void testMasterOnlineConfigChange() throws IOException {
67 LOG.debug("Starting the test");
68 Path cnfPath = FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml");
69 Path cnf2Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml");
70 Path cnf3Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml");
71 // make a backup of hbase-site.xml
72 Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING);
73 // update hbase-site.xml by overwriting it
74 Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
76 Admin admin = TEST_UTIL.getAdmin();
77 ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName();
78 admin.updateConfiguration(server);
79 Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
80 int custom = conf.getInt("hbase.custom.config", 0);
81 assertEquals(1000, custom);
82 // restore hbase-site.xml
83 Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
86 @Test
87 public void testAllOnlineConfigChange() throws IOException {
88 LOG.debug("Starting the test");
89 Admin admin = TEST_UTIL.getAdmin();
90 admin.updateConfiguration();
93 @Test
94 public void testAllCustomOnlineConfigChange() throws IOException {
95 LOG.debug("Starting the test");
96 Path cnfPath = FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml");
97 Path cnf2Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml");
98 Path cnf3Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml");
99 // 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);
104 Admin admin = TEST_UTIL.getAdmin();
105 admin.updateConfiguration();
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);
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);
123 // restore hbase-site.xml
124 Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);