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
.client
;
20 import static org
.apache
.hadoop
.hbase
.client
.AsyncConnectionConfiguration
.START_LOG_ERRORS_AFTER_COUNT_KEY
;
21 import static org
.junit
.Assert
.assertFalse
;
22 import static org
.junit
.Assert
.assertTrue
;
24 import java
.util
.concurrent
.TimeUnit
;
25 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
26 import org
.apache
.hadoop
.hbase
.HConstants
;
27 import org
.apache
.hadoop
.hbase
.master
.HMaster
;
28 import org
.apache
.hadoop
.hbase
.regionserver
.HRegionServer
;
29 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
31 import org
.junit
.After
;
32 import org
.junit
.AfterClass
;
33 import org
.junit
.Before
;
34 import org
.junit
.BeforeClass
;
35 import org
.junit
.ClassRule
;
36 import org
.junit
.Test
;
37 import org
.junit
.experimental
.categories
.Category
;
39 import org
.apache
.hbase
.thirdparty
.com
.google
.common
.io
.Closeables
;
42 * Only used to test stopMaster/stopRegionServer/shutdown methods.
44 @Category({ ClientTests
.class, MediumTests
.class })
45 public class TestAsyncClusterAdminApi2
extends TestAsyncAdminBase
{
48 public static final HBaseClassTestRule CLASS_RULE
=
49 HBaseClassTestRule
.forClass(TestAsyncClusterAdminApi2
.class);
52 public static void setUpBeforeClass() throws Exception
{
53 TEST_UTIL
.getConfiguration().setInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, 60000);
54 TEST_UTIL
.getConfiguration().setInt(HConstants
.HBASE_CLIENT_OPERATION_TIMEOUT
, 120000);
55 TEST_UTIL
.getConfiguration().setInt(HConstants
.HBASE_CLIENT_RETRIES_NUMBER
, 2);
56 TEST_UTIL
.getConfiguration().setInt(START_LOG_ERRORS_AFTER_COUNT_KEY
, 0);
60 public static void tearDownAfterClass() throws Exception
{
66 public void setUp() throws Exception
{
67 TEST_UTIL
.startMiniCluster(3);
68 ASYNC_CONN
= ConnectionFactory
.createAsyncConnection(TEST_UTIL
.getConfiguration()).get();
69 admin
= ASYNC_CONN
.getAdmin();
74 public void tearDown() throws Exception
{
75 Closeables
.close(ASYNC_CONN
, true);
76 TEST_UTIL
.shutdownMiniCluster();
80 public void testStop() throws Exception
{
81 HRegionServer rs
= TEST_UTIL
.getMiniHBaseCluster().getRegionServer(0);
82 assertFalse(rs
.isStopped());
83 admin
.stopRegionServer(rs
.getServerName()).join();
84 assertTrue(rs
.isStopped());
86 HMaster master
= TEST_UTIL
.getMiniHBaseCluster().getMaster();
87 assertFalse(master
.isStopped());
88 admin
.stopMaster().join();
89 assertTrue(master
.isStopped());
93 public void testShutdown() throws Exception
{
94 TEST_UTIL
.getMiniHBaseCluster().getMasterThreads().forEach(thread
-> {
95 assertFalse(thread
.getMaster().isStopped());
97 TEST_UTIL
.getMiniHBaseCluster().getRegionServerThreads().forEach(thread
-> {
98 assertFalse(thread
.getRegionServer().isStopped());
101 admin
.shutdown().join();
102 TEST_UTIL
.getMiniHBaseCluster().getMasterThreads().forEach(thread
-> {
103 while (!thread
.getMaster().isStopped()) {
104 trySleep(100, TimeUnit
.MILLISECONDS
);
107 TEST_UTIL
.getMiniHBaseCluster().getRegionServerThreads().forEach(thread
-> {
108 while (!thread
.getRegionServer().isStopped()) {
109 trySleep(100, TimeUnit
.MILLISECONDS
);
114 private void trySleep(long timeout
, TimeUnit unit
) {
117 } catch (InterruptedException e
) {