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.conf.Configuration;
25  import org.apache.hadoop.hbase.IntegrationTestingUtility;
26  import org.apache.hadoop.hbase.Waiter;
27  import org.apache.hadoop.hbase.testclassification.IntegrationTests;
28  import org.junit.After;
29  import org.junit.Before;
30  import org.junit.experimental.categories.Category;
31  
32  /**
33   * Runs all of the units tests defined in TestGroupBase
34   * as an integration test.
35   * Requires TestRSGroupBase.NUM_SLAVE_BASE servers to run.
36   */
37  @Category(IntegrationTests.class)
38  public class IntegrationTestRSGroup extends TestRSGroupsBase {
39    //Integration specific
40    private final static Log LOG = LogFactory.getLog(IntegrationTestRSGroup.class);
41    private static boolean initialized = false;
42  
43    @Before
44    public void beforeMethod() throws Exception {
45      if(!initialized) {
46        LOG.info("Setting up IntegrationTestGroup");
47        TEST_UTIL = new IntegrationTestingUtility();
48        conf = new Configuration(TEST_UTIL.getConfiguration());
49        final int numSlaves = conf.getInt(NUM_SLAVES_BASE_KEY, DEFAULT_NUM_SLAVES_BASE);
50        LOG.info("Initializing cluster with " + numSlaves + " servers");
51        ((IntegrationTestingUtility)TEST_UTIL).initializeCluster(numSlaves);
52        //set shared configs
53        admin = TEST_UTIL.getHBaseAdmin();
54        cluster = TEST_UTIL.getHBaseClusterInterface();
55        rsGroupAdmin = new VerifyingRSGroupAdminClient(rsGroupAdmin.newClient(TEST_UTIL.getConnection()),
56            TEST_UTIL.getConfiguration());
57        LOG.info("Done initializing cluster");
58        initialized = true;
59        //cluster may not be clean
60        //cleanup when initializing
61        afterMethod();
62      }
63    }
64  
65    @After
66    public void afterMethod() throws Exception {
67      LOG.info("Cleaning up previous test run");
68      //cleanup previous artifacts
69      deleteTableIfNecessary();
70      deleteNamespaceIfNecessary();
71      deleteGroups();
72      admin.setBalancerRunning(true, true);
73  
74      LOG.info("Restoring the cluster");
75      ((IntegrationTestingUtility)TEST_UTIL).restoreCluster();
76      LOG.info("Done restoring the cluster");
77  
78      final long waitTimeout = conf.getLong(WAIT_TIMEOUT_KEY, DEFAULT_WAIT_TIMEOUT);
79      final int numSlaves = conf.getInt(NUM_SLAVES_BASE_KEY, DEFAULT_NUM_SLAVES_BASE);
80      TEST_UTIL.waitFor(waitTimeout, new Waiter.Predicate<Exception>() {
81        @Override
82        public boolean evaluate() throws Exception {
83          LOG.info("Waiting for cleanup to finish "+ rsGroupAdmin.listRSGroups());
84          //Might be greater since moving servers back to default
85          //is after starting a server
86          return rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size()
87              >= numSlaves;
88        }
89      });
90  
91      TEST_UTIL.waitFor(waitTimeout, new Waiter.Predicate<Exception>() {
92        @Override
93        public boolean evaluate() throws Exception {
94          LOG.info("Waiting for regionservers to be registered "+ rsGroupAdmin.listRSGroups());
95          //Might be greater since moving servers back to default
96          //is after starting a server
97          return rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().size()
98              == getNumServers();
99        }
100     });
101 
102     LOG.info("Done cleaning up previous test run");
103   }
104 }