PDavid commented on code in PR #6875: URL: https://github.com/apache/hbase/pull/6875#discussion_r2106182919
########## hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusPage.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.master.http; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtil; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.LocalHBaseCluster; +import org.apache.hadoop.hbase.testclassification.MasterTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.util.CommonFSUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; + +@Category({ MasterTests.class, MediumTests.class }) +public class TestMasterStatusPage { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestMasterStatusPage.class); + + private final static HBaseTestingUtil UTIL = new HBaseTestingUtil(); + + private static LocalHBaseCluster CLUSTER; + + @Rule + public TestName name = new TestName(); + + @BeforeClass + public static void beforeClass() throws Exception { + Configuration conf = UTIL.getConfiguration(); + UTIL.startMiniZKCluster(); + + UTIL.startMiniDFSCluster(1); + Path rootdir = UTIL.getDataTestDirOnTestFS("TestMasterStatusPage"); + CommonFSUtils.setRootDir(conf, rootdir); + + // The info servers do not run in tests by default. + // Set them to ephemeral ports so they will start + // setup configuration + conf.setInt(HConstants.MASTER_INFO_PORT, 0); + conf.setInt(HConstants.REGIONSERVER_INFO_PORT, 0); + + CLUSTER = new LocalHBaseCluster(conf, 1); + CLUSTER.startup(); + CLUSTER.getActiveMaster().waitForMetaOnline(); + } + + /** + * Helper method to shut down the cluster (if running) + */ + @AfterClass + public static void shutDownMiniCluster() throws Exception { + if (CLUSTER != null) { + CLUSTER.shutdown(); + CLUSTER.join(); + } + UTIL.shutdownMiniCluster(); + } + + @Test + public void testMasterStatusPage() throws Exception { + URL url = new URL(getInfoServerHostAndPort() + "/master-status"); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.connect(); + + assertEquals(200, conn.getResponseCode()); + assertEquals("text/html;charset=utf-8", conn.getContentType()); + + String responseBody = getResponseBody(conn); + assertTrue(responseBody.contains("<h1>Master")); + assertTrue(responseBody.contains("<h2><a name=\"regionservers\">Region Servers</a></h2>")); + assertTrue(responseBody.contains("<h2>Backup Masters</h2>")); + assertTrue(responseBody.contains("<h2><a name=\"tables\">Tables</a></h2>")); + assertTrue( + responseBody.contains("<h2><a name=\"region_visualizer\"></a>Region Visualizer</h2>")); + assertTrue(responseBody.contains("<h2><a name=\"peers\">Peers</a></h2>")); + assertTrue(responseBody.contains("<h2><a name=\"tasks\">Tasks</a></h2>")); + assertTrue(responseBody.contains("<h2><a name=\"attributes\">Software Attributes</a></h2>")); Review Comment: For now I only added these assertions on the HTML content of the Master Status page. But we can add more sophisticated asserts in the future. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
