1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
34
35
36
37 @Category(IntegrationTests.class)
38 public class IntegrationTestRSGroup extends TestRSGroupsBase {
39
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
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
60
61 afterMethod();
62 }
63 }
64
65 @After
66 public void afterMethod() throws Exception {
67 LOG.info("Cleaning up previous test run");
68
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
85
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
96
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 }