View Javadoc

1   /**
2    * Copyright The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.rsgroup;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.hbase.IntegrationTestingUtility;
25  import org.apache.hadoop.hbase.Waiter;
26  import org.apache.hadoop.hbase.testclassification.IntegrationTests;
27  import org.junit.After;
28  import org.junit.Before;
29  import org.junit.experimental.categories.Category;
30  
31  /**
32   * Runs all of the units tests defined in TestGroupBase
33   * as an integration test.
34   * Requires TestRSGroupBase.NUM_SLAVE_BASE servers to run.
35   */
36  @Category(IntegrationTests.class)
37  public class IntegrationTestRSGroup extends TestRSGroupsBase {
38    //Integration specific
39    private final static Log LOG = LogFactory.getLog(IntegrationTestRSGroup.class);
40    private static boolean initialized = false;
41  
42    @Before
43    public void beforeMethod() throws Exception {
44      if(!initialized) {
45        LOG.info("Setting up IntegrationTestGroup");
46        LOG.info("Initializing cluster with " + NUM_SLAVES_BASE + " servers");
47        TEST_UTIL = new IntegrationTestingUtility();
48        ((IntegrationTestingUtility)TEST_UTIL).initializeCluster(NUM_SLAVES_BASE);
49        //set shared configs
50        admin = TEST_UTIL.getHBaseAdmin();
51        cluster = TEST_UTIL.getHBaseClusterInterface();
52        rsGroupAdmin = new VerifyingRSGroupAdminClient(rsGroupAdmin.newClient(TEST_UTIL.getConnection()),
53            TEST_UTIL.getConfiguration());
54        LOG.info("Done initializing cluster");
55        initialized = true;
56        //cluster may not be clean
57        //cleanup when initializing
58        afterMethod();
59      }
60    }
61  
62    @After
63    public void afterMethod() throws Exception {
64      LOG.info("Cleaning up previous test run");
65      //cleanup previous artifacts
66      deleteTableIfNecessary();
67      deleteNamespaceIfNecessary();
68      deleteGroups();
69      admin.setBalancerRunning(true, true);
70  
71      LOG.info("Restoring the cluster");
72      ((IntegrationTestingUtility)TEST_UTIL).restoreCluster();
73      LOG.info("Done restoring the cluster");
74  
75      TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
76        @Override
77        public boolean evaluate() throws Exception {
78          LOG.info("Waiting for cleanup to finish "+ rsGroupAdmin.listRSGroups());
79          //Might be greater since moving servers back to default
80          //is after starting a server
81          return rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size()
82              >= NUM_SLAVES_BASE;
83        }
84      });
85  
86      TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
87        @Override
88        public boolean evaluate() throws Exception {
89          LOG.info("Waiting for regionservers to be registered "+ rsGroupAdmin.listRSGroups());
90          //Might be greater since moving servers back to default
91          //is after starting a server
92          return rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size()
93              == getNumServers();
94        }
95      });
96  
97      LOG.info("Done cleaning up previous test run");
98    }
99  }