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(2, 1);
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  
78    @Test
79    public void testAllOnlineConfigChange() throws IOException {
80      LOG.debug("Starting the test");
81      Admin admin = TEST_UTIL.getHBaseAdmin();
82      admin.updateConfiguration();
83    }
84  
85    @Test
86    public void testAllCustomOnlineConfigChange() throws IOException {
87      LOG.debug("Starting the test");
88      Path cnfPath = FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml");
89      Path cnf2Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml");
90      Path cnf3Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml");
91      // make a backup of hbase-site.xml
92      Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING);
93      // update hbase-site.xml by overwriting it
94      Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
95  
96      Admin admin = TEST_UTIL.getHBaseAdmin();
97      admin.updateConfiguration();
98  
99      // Check the configuration of the Masters
100     Configuration masterConfiguration = TEST_UTIL.getMiniHBaseCluster().getMaster(0).getConfiguration();
101     int custom = masterConfiguration.getInt("hbase.custom.config", 0);
102     assertEquals(custom, 1000);
103     Configuration backupMasterConfiguration = TEST_UTIL.getMiniHBaseCluster().getMaster(1).getConfiguration();
104     custom = backupMasterConfiguration.getInt("hbase.custom.config", 0);
105     assertEquals(custom, 1000);
106 
107     // Check the configuration of the RegionServer
108     Configuration regionServerConfiguration = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getConfiguration();
109     custom = regionServerConfiguration.getInt("hbase.custom.config", 0);
110     assertEquals(custom, 1000);
111 
112     // restore hbase-site.xml
113     Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
114   }
115 }