1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
64 Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING);
65
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
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
92 Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING);
93
94 Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
95
96 Admin admin = TEST_UTIL.getHBaseAdmin();
97 admin.updateConfiguration();
98
99
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
108 Configuration regionServerConfiguration = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getConfiguration();
109 custom = regionServerConfiguration.getInt("hbase.custom.config", 0);
110 assertEquals(custom, 1000);
111
112
113 Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING);
114 }
115 }