View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.client;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  import java.io.IOException;
24  import java.nio.file.FileSystems;
25  import java.nio.file.Files;
26  import java.nio.file.Path;
27  import java.nio.file.StandardCopyOption;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  import org.apache.hadoop.conf.Configuration;
32  import org.apache.hadoop.hbase.HBaseTestingUtility;
33  import org.apache.hadoop.hbase.ServerName;
34  import org.apache.hadoop.hbase.testclassification.MediumTests;
35  import org.junit.BeforeClass;
36  import org.junit.Test;
37  import org.junit.experimental.categories.Category;
38  
39  @Category({MediumTests.class})
40  public class TestUpdateConfiguration {
41    private static final Log LOG = LogFactory.getLog(TestUpdateConfiguration.class);
42    private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
43  
44    @BeforeClass
45    public static void setup() throws Exception {
46      TEST_UTIL.startMiniCluster();
47    }
48  
49    @Test
50    public void testOnlineConfigChange() throws IOException {
51      LOG.debug("Starting the test");
52      Admin admin = TEST_UTIL.getHBaseAdmin();
53      ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
54      admin.updateConfiguration(server);
55    }
56  
57    @Test
58    public void testMasterOnlineConfigChange() throws IOException {
59      LOG.debug("Starting the test");
60      Path cnfPath = FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml");
61      Path cnf2Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml");
62      Path cnf3Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml");
63      // make a backup of hbase-site.xml
64      Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING);
65      // update hbase-site.xml by overwriting it
66      Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
67  
68      Admin admin = TEST_UTIL.getHBaseAdmin();
69      ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName();
70      admin.updateConfiguration(server);
71      Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
72      int custom = conf.getInt("hbase.custom.config", 0);
73      assertEquals(custom, 1000);
74      // restore hbase-site.xml
75      Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
76    }
77  }