HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestClusterId.java
blob4d8092c3f854c5915e892c27eb343ee318761839
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.regionserver;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.fs.FSDataOutputStream;
25 import org.apache.hadoop.fs.FileSystem;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseClassTestRule;
28 import org.apache.hadoop.hbase.HBaseCommonTestingUtil;
29 import org.apache.hadoop.hbase.HBaseTestingUtil;
30 import org.apache.hadoop.hbase.HConstants;
31 import org.apache.hadoop.hbase.StartTestingClusterOption;
32 import org.apache.hadoop.hbase.master.HMaster;
33 import org.apache.hadoop.hbase.testclassification.MediumTests;
34 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
35 import org.apache.hadoop.hbase.util.CommonFSUtils;
36 import org.apache.hadoop.hbase.util.JVMClusterUtil;
37 import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
38 import org.junit.After;
39 import org.junit.Before;
40 import org.junit.ClassRule;
41 import org.junit.Test;
42 import org.junit.experimental.categories.Category;
44 /**
45 * Test metrics incremented on region server operations.
47 @Category({RegionServerTests.class, MediumTests.class})
48 public class TestClusterId {
50 @ClassRule
51 public static final HBaseClassTestRule CLASS_RULE =
52 HBaseClassTestRule.forClass(TestClusterId.class);
54 private final HBaseTestingUtil TEST_UTIL =
55 new HBaseTestingUtil();
57 private JVMClusterUtil.RegionServerThread rst;
59 @Before
60 public void setUp() throws Exception {
61 TEST_UTIL.getConfiguration().setBoolean(ShutdownHook.RUN_SHUTDOWN_HOOK, false);
64 @After
65 public void tearDown() throws Exception {
66 TEST_UTIL.shutdownMiniCluster();
67 if(rst != null && rst.getRegionServer() != null) {
68 rst.getRegionServer().stop("end of test");
69 rst.join();
73 @Test
74 public void testClusterId() throws Exception {
75 TEST_UTIL.startMiniZKCluster();
76 TEST_UTIL.startMiniDFSCluster(1);
78 Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
79 //start region server, needs to be separate
80 //so we get an unset clusterId
81 rst = JVMClusterUtil.createRegionServerThread(conf, HRegionServer.class, 0);
82 rst.start();
83 //Make sure RS is in blocking state
84 Thread.sleep(10000);
86 StartTestingClusterOption option = StartTestingClusterOption.builder()
87 .numMasters(1).numRegionServers(0).build();
88 TEST_UTIL.startMiniHBaseCluster(option);
90 rst.waitForServerOnline();
92 String clusterId = ZKClusterId.readClusterIdZNode(TEST_UTIL.getZooKeeperWatcher());
93 assertNotNull(clusterId);
94 assertEquals(clusterId, rst.getRegionServer().getClusterId());
97 @Test
98 public void testRewritingClusterIdToPB() throws Exception {
99 TEST_UTIL.startMiniZKCluster();
100 TEST_UTIL.startMiniDFSCluster(1);
101 TEST_UTIL.createRootDir();
102 Path rootDir = CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration());
103 FileSystem fs = rootDir.getFileSystem(TEST_UTIL.getConfiguration());
104 Path filePath = new Path(rootDir, HConstants.CLUSTER_ID_FILE_NAME);
105 FSDataOutputStream s = null;
106 try {
107 s = fs.create(filePath);
108 s.writeUTF(HBaseCommonTestingUtil.getRandomUUID().toString());
109 } finally {
110 if (s != null) {
111 s.close();
114 TEST_UTIL.startMiniHBaseCluster();
115 HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
116 assertEquals(1, master.getServerManager().getOnlineServersList().size());