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 org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.hbase.HBaseTestingUtility;
28  import org.apache.hadoop.hbase.ServerName;
29  import org.apache.hadoop.hbase.testclassification.MediumTests;
30  import org.junit.BeforeClass;
31  import org.junit.Rule;
32  import org.junit.Test;
33  import org.junit.experimental.categories.Category;
34  import org.junit.rules.TestName;
35  
36  @Category({MediumTests.class})
37  public class TestUpdateConfiguration extends AbstractTestUpdateConfiguration {
38    private static final Log LOG = LogFactory.getLog(TestUpdateConfiguration.class);
39    private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
40  
41    @BeforeClass
42    public static void setup() throws Exception {
43      setUpConfigurationFiles(TEST_UTIL);
44      TEST_UTIL.startMiniCluster(2, 1);
45      addResourceToRegionServerConfiguration(TEST_UTIL);
46    }
47  
48    @Rule
49    public TestName name = new TestName();
50  
51    @Test
52    public void testOnlineConfigChange() throws IOException {
53      LOG.debug("Starting the test " + name.getMethodName());
54      Admin admin = TEST_UTIL.getHBaseAdmin();
55      ServerName server = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
56      admin.updateConfiguration(server);
57    }
58  
59    @Test
60    public void testMasterOnlineConfigChange() throws IOException {
61      LOG.debug("Starting the test " + name.getMethodName());
62      replaceHBaseSiteXML();
63      Admin admin = TEST_UTIL.getHBaseAdmin();
64  
65      ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName();
66      admin.updateConfiguration(server);
67      Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration();
68      int custom = conf.getInt("hbase.custom.config", 0);
69      assertEquals(1000, custom);
70      restoreHBaseSiteXML();
71    }
72  
73    @Test
74    public void testAllOnlineConfigChange() throws IOException {
75      LOG.debug("Starting the test " + name.getMethodName());
76      Admin admin = TEST_UTIL.getHBaseAdmin();
77      admin.updateConfiguration();
78    }
79  
80    @Test
81    public void testAllCustomOnlineConfigChange() throws IOException {
82      LOG.debug("Starting the test " + name.getMethodName());
83      replaceHBaseSiteXML();
84  
85      Admin admin = TEST_UTIL.getHBaseAdmin();
86      admin.updateConfiguration();
87  
88      // Check the configuration of the Masters
89      Configuration masterConfiguration = TEST_UTIL.getMiniHBaseCluster().getMaster(0).getConfiguration();
90      int custom = masterConfiguration.getInt("hbase.custom.config", 0);
91      assertEquals(custom, 1000);
92      Configuration backupMasterConfiguration = TEST_UTIL.getMiniHBaseCluster().getMaster(1).getConfiguration();
93      custom = backupMasterConfiguration.getInt("hbase.custom.config", 0);
94      assertEquals(custom, 1000);
95  
96      // Check the configuration of the RegionServer
97      Configuration regionServerConfiguration = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getConfiguration();
98      custom = regionServerConfiguration.getInt("hbase.custom.config", 0);
99      assertEquals(custom, 1000);
100 
101     restoreHBaseSiteXML();
102   }
103 }