begin_unit|revision:0.9.5;language:Java;cregit-version:0.0.1
begin_comment
comment|/**  * 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.  */
end_comment

begin_package
package|package
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
package|;
end_package

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertEquals
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertFalse
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertTrue
import|;
end_import

begin_import
import|import
name|java
operator|.
name|io
operator|.
name|IOException
import|;
end_import

begin_import
import|import
name|java
operator|.
name|io
operator|.
name|InputStream
import|;
end_import

begin_import
import|import
name|java
operator|.
name|net
operator|.
name|URL
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|commons
operator|.
name|io
operator|.
name|IOUtils
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Admin
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|testclassification
operator|.
name|MediumTests
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|testclassification
operator|.
name|MiscTests
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|util
operator|.
name|Bytes
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|AfterClass
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|BeforeClass
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|ClassRule
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|Rule
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|Test
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|experimental
operator|.
name|categories
operator|.
name|Category
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|rules
operator|.
name|TestName
import|;
end_import

begin_import
import|import
name|org
operator|.
name|slf4j
operator|.
name|Logger
import|;
end_import

begin_import
import|import
name|org
operator|.
name|slf4j
operator|.
name|LoggerFactory
import|;
end_import

begin_comment
comment|/**  * Testing, info servers are disabled.  This test enables then and checks that  * they serve pages.  */
end_comment

begin_class
annotation|@
name|Category
argument_list|(
block|{
name|MiscTests
operator|.
name|class
block|,
name|MediumTests
operator|.
name|class
block|}
argument_list|)
specifier|public
class|class
name|TestInfoServers
block|{
annotation|@
name|ClassRule
specifier|public
specifier|static
specifier|final
name|HBaseClassTestRule
name|CLASS_RULE
init|=
name|HBaseClassTestRule
operator|.
name|forClass
argument_list|(
name|TestInfoServers
operator|.
name|class
argument_list|)
decl_stmt|;
specifier|private
specifier|static
specifier|final
name|Logger
name|LOG
init|=
name|LoggerFactory
operator|.
name|getLogger
argument_list|(
name|TestInfoServers
operator|.
name|class
argument_list|)
decl_stmt|;
specifier|private
specifier|final
specifier|static
name|HBaseTestingUtility
name|UTIL
init|=
operator|new
name|HBaseTestingUtility
argument_list|()
decl_stmt|;
annotation|@
name|Rule
specifier|public
name|TestName
name|name
init|=
operator|new
name|TestName
argument_list|()
decl_stmt|;
annotation|@
name|BeforeClass
specifier|public
specifier|static
name|void
name|beforeClass
parameter_list|()
throws|throws
name|Exception
block|{
comment|// The info servers do not run in tests by default.
comment|// Set them to ephemeral ports so they will start
name|UTIL
operator|.
name|getConfiguration
argument_list|()
operator|.
name|setInt
argument_list|(
name|HConstants
operator|.
name|MASTER_INFO_PORT
argument_list|,
literal|0
argument_list|)
expr_stmt|;
name|UTIL
operator|.
name|getConfiguration
argument_list|()
operator|.
name|setInt
argument_list|(
name|HConstants
operator|.
name|REGIONSERVER_INFO_PORT
argument_list|,
literal|0
argument_list|)
expr_stmt|;
comment|//We need to make sure that the server can be started as read only.
name|UTIL
operator|.
name|getConfiguration
argument_list|()
operator|.
name|setBoolean
argument_list|(
literal|"hbase.master.ui.readonly"
argument_list|,
literal|true
argument_list|)
expr_stmt|;
name|UTIL
operator|.
name|startMiniCluster
argument_list|()
expr_stmt|;
if|if
condition|(
operator|!
name|UTIL
operator|.
name|getHBaseCluster
argument_list|()
operator|.
name|waitForActiveAndReadyMaster
argument_list|(
literal|30000
argument_list|)
condition|)
block|{
throw|throw
operator|new
name|RuntimeException
argument_list|(
literal|"Active master not ready"
argument_list|)
throw|;
block|}
block|}
annotation|@
name|AfterClass
specifier|public
specifier|static
name|void
name|afterClass
parameter_list|()
throws|throws
name|Exception
block|{
name|UTIL
operator|.
name|shutdownMiniCluster
argument_list|()
expr_stmt|;
block|}
annotation|@
name|Test
specifier|public
name|void
name|testGetMasterInfoPort
parameter_list|()
throws|throws
name|Exception
block|{
try|try
init|(
name|Admin
name|admin
init|=
name|UTIL
operator|.
name|getAdmin
argument_list|()
init|)
block|{
name|assertEquals
argument_list|(
name|UTIL
operator|.
name|getHBaseCluster
argument_list|()
operator|.
name|getMaster
argument_list|()
operator|.
name|getInfoServer
argument_list|()
operator|.
name|getPort
argument_list|()
argument_list|,
name|admin
operator|.
name|getMasterInfoPort
argument_list|()
argument_list|)
expr_stmt|;
block|}
block|}
comment|/**    * Ensure when we go to top level index pages that we get redirected to an info-server specific status    * page.    */
annotation|@
name|Test
specifier|public
name|void
name|testInfoServersRedirect
parameter_list|()
throws|throws
name|Exception
block|{
comment|// give the cluster time to start up
name|UTIL
operator|.
name|getConnection
argument_list|()
operator|.
name|getTable
argument_list|(
name|TableName
operator|.
name|META_TABLE_NAME
argument_list|)
operator|.
name|close
argument_list|()
expr_stmt|;
name|int
name|port
init|=
name|UTIL
operator|.
name|getHBaseCluster
argument_list|()
operator|.
name|getMaster
argument_list|()
operator|.
name|getInfoServer
argument_list|()
operator|.
name|getPort
argument_list|()
decl_stmt|;
name|assertContainsContent
argument_list|(
operator|new
name|URL
argument_list|(
literal|"http://localhost:"
operator|+
name|port
operator|+
literal|"/index.html"
argument_list|)
argument_list|,
literal|"master-status"
argument_list|)
expr_stmt|;
name|port
operator|=
name|UTIL
operator|.
name|getHBaseCluster
argument_list|()
operator|.
name|getRegionServerThreads
argument_list|()
operator|.
name|get
argument_list|(
literal|0
argument_list|)
operator|.
name|getRegionServer
argument_list|()
operator|.
name|getInfoServer
argument_list|()
operator|.
name|getPort
argument_list|()
expr_stmt|;
name|assertContainsContent
argument_list|(
operator|new
name|URL
argument_list|(
literal|"http://localhost:"
operator|+
name|port
operator|+
literal|"/index.html"
argument_list|)
argument_list|,
literal|"rs-status"
argument_list|)
expr_stmt|;
block|}
comment|/**    * Test that the status pages in the minicluster load properly.    *    * This is somewhat a duplicate of TestRSStatusServlet and    * TestMasterStatusServlet, but those are true unit tests    * whereas this uses a cluster.    */
annotation|@
name|Test
specifier|public
name|void
name|testInfoServersStatusPages
parameter_list|()
throws|throws
name|Exception
block|{
name|int
name|port
init|=
name|UTIL
operator|.
name|getHBaseCluster
argument_list|()
operator|.
name|getMaster
argument_list|()
operator|.
name|getInfoServer
argument_list|()
operator|.
name|getPort
argument_list|()
decl_stmt|;
name|assertContainsContent
argument_list|(
operator|new
name|URL
argument_list|(
literal|"http://localhost:"
operator|+
name|port
operator|+
literal|"/master-status"
argument_list|)
argument_list|,
literal|"meta"
argument_list|)
expr_stmt|;
name|port
operator|=
name|UTIL
operator|.
name|getHBaseCluster
argument_list|()
operator|.
name|getRegionServerThreads
argument_list|()
operator|.
name|get
argument_list|(
literal|0
argument_list|)
operator|.
name|getRegionServer
argument_list|()
operator|.
name|getInfoServer
argument_list|()
operator|.
name|getPort
argument_list|()
expr_stmt|;
name|assertContainsContent
argument_list|(
operator|new
name|URL
argument_list|(
literal|"http://localhost:"
operator|+
name|port
operator|+
literal|"/rs-status"
argument_list|)
argument_list|,
literal|"meta"
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
specifier|public
name|void
name|testMasterServerReadOnly
parameter_list|()
throws|throws
name|Exception
block|{
specifier|final
name|TableName
name|tableName
init|=
name|TableName
operator|.
name|valueOf
argument_list|(
name|name
operator|.
name|getMethodName
argument_list|()
argument_list|)
decl_stmt|;
name|byte
index|[]
name|cf
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"d"
argument_list|)
decl_stmt|;
name|UTIL
operator|.
name|createTable
argument_list|(
name|tableName
argument_list|,
name|cf
argument_list|)
expr_stmt|;
name|UTIL
operator|.
name|waitTableAvailable
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|int
name|port
init|=
name|UTIL
operator|.
name|getHBaseCluster
argument_list|()
operator|.
name|getMaster
argument_list|()
operator|.
name|getInfoServer
argument_list|()
operator|.
name|getPort
argument_list|()
decl_stmt|;
name|assertDoesNotContainContent
argument_list|(
operator|new
name|URL
argument_list|(
literal|"http://localhost:"
operator|+
name|port
operator|+
literal|"/table.jsp?name="
operator|+
name|tableName
operator|+
literal|"&action=split&key="
argument_list|)
argument_list|,
literal|"Table action request accepted"
argument_list|)
expr_stmt|;
name|assertDoesNotContainContent
argument_list|(
operator|new
name|URL
argument_list|(
literal|"http://localhost:"
operator|+
name|port
operator|+
literal|"/table.jsp?name="
operator|+
name|tableName
argument_list|)
argument_list|,
literal|"Actions:"
argument_list|)
expr_stmt|;
block|}
specifier|private
name|void
name|assertContainsContent
parameter_list|(
specifier|final
name|URL
name|u
parameter_list|,
specifier|final
name|String
name|expected
parameter_list|)
throws|throws
name|IOException
block|{
name|LOG
operator|.
name|info
argument_list|(
literal|"Testing "
operator|+
name|u
operator|.
name|toString
argument_list|()
operator|+
literal|" has "
operator|+
name|expected
argument_list|)
expr_stmt|;
name|String
name|content
init|=
name|getUrlContent
argument_list|(
name|u
argument_list|)
decl_stmt|;
name|assertTrue
argument_list|(
literal|"expected="
operator|+
name|expected
operator|+
literal|", content="
operator|+
name|content
argument_list|,
name|content
operator|.
name|contains
argument_list|(
name|expected
argument_list|)
argument_list|)
expr_stmt|;
block|}
specifier|private
name|void
name|assertDoesNotContainContent
parameter_list|(
specifier|final
name|URL
name|u
parameter_list|,
specifier|final
name|String
name|expected
parameter_list|)
throws|throws
name|IOException
block|{
name|LOG
operator|.
name|info
argument_list|(
literal|"Testing "
operator|+
name|u
operator|.
name|toString
argument_list|()
operator|+
literal|" does not have "
operator|+
name|expected
argument_list|)
expr_stmt|;
name|String
name|content
init|=
name|getUrlContent
argument_list|(
name|u
argument_list|)
decl_stmt|;
name|assertFalse
argument_list|(
literal|"Does Not Contain ="
operator|+
name|expected
operator|+
literal|", content="
operator|+
name|content
argument_list|,
name|content
operator|.
name|contains
argument_list|(
name|expected
argument_list|)
argument_list|)
expr_stmt|;
block|}
specifier|private
name|String
name|getUrlContent
parameter_list|(
name|URL
name|u
parameter_list|)
throws|throws
name|IOException
block|{
name|java
operator|.
name|net
operator|.
name|URLConnection
name|c
init|=
name|u
operator|.
name|openConnection
argument_list|()
decl_stmt|;
name|c
operator|.
name|setConnectTimeout
argument_list|(
literal|2000
argument_list|)
expr_stmt|;
name|c
operator|.
name|setReadTimeout
argument_list|(
literal|2000
argument_list|)
expr_stmt|;
name|c
operator|.
name|connect
argument_list|()
expr_stmt|;
try|try
init|(
name|InputStream
name|in
init|=
name|c
operator|.
name|getInputStream
argument_list|()
init|)
block|{
return|return
name|IOUtils
operator|.
name|toString
argument_list|(
name|in
argument_list|)
return|;
block|}
block|}
block|}
end_class

end_unit

