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 static org.junit.Assert.assertFalse;
23
24 import com.google.common.collect.Sets;
25
26 import java.util.Set;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.hadoop.hbase.HColumnDescriptor;
31 import org.apache.hadoop.hbase.HTableDescriptor;
32 import org.apache.hadoop.hbase.NamespaceDescriptor;
33 import org.apache.hadoop.hbase.ServerName;
34 import org.apache.hadoop.hbase.TableName;
35 import org.apache.hadoop.hbase.Waiter;
36 import org.apache.hadoop.hbase.net.Address;
37 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
38 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos;
39 import org.apache.hadoop.hbase.testclassification.MediumTests;
40 import org.junit.After;
41 import org.junit.AfterClass;
42 import org.junit.Assert;
43 import org.junit.Before;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
46 import org.junit.experimental.categories.Category;
47
48 @Category({MediumTests.class})
49 public class TestRSGroupsKillRS extends TestRSGroupsBase {
50 protected static final Log LOG = LogFactory.getLog(TestRSGroupsKillRS.class);
51
52 @BeforeClass
53 public static void setUp() throws Exception {
54 setUpTestBeforeClass();
55 }
56
57 @AfterClass
58 public static void tearDown() throws Exception {
59 tearDownAfterClass();
60 }
61
62 @Before
63 public void beforeMethod() throws Exception {
64 setUpBeforeMethod();
65 }
66
67 @After
68 public void afterMethod() throws Exception {
69 tearDownAfterMethod();
70 }
71
72 @Test
73 public void testKillRS() throws Exception {
74 LOG.info("testKillRS");
75 RSGroupInfo appInfo = addGroup(rsGroupAdmin, "appInfo", 1);
76
77 final TableName tableName = TableName.valueOf(tablePrefix+"_ns", "_testKillRS");
78 admin.createNamespace(
79 NamespaceDescriptor.create(tableName.getNamespaceAsString())
80 .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, appInfo.getName()).build());
81 final HTableDescriptor desc = new HTableDescriptor(tableName);
82 desc.addFamily(new HColumnDescriptor("f"));
83 admin.createTable(desc);
84
85 TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
86 @Override
87 public boolean evaluate() throws Exception {
88 return getTableRegionMap().get(desc.getTableName()) != null;
89 }
90 });
91
92 ServerName targetServer = ServerName.parseServerName(
93 appInfo.getServers().iterator().next().toString());
94 AdminProtos.AdminService.BlockingInterface targetRS =
95 admin.getConnection().getAdmin(targetServer);
96 Assert.assertEquals(1, ProtobufUtil.getOnlineRegions(targetRS).size());
97
98 try {
99
100
101 targetRS.stopServer(null,
102 AdminProtos.StopServerRequest.newBuilder().setReason("Die").build());
103 } catch(Exception e) {
104 }
105 assertFalse(cluster.getClusterStatus().getServers().contains(targetServer));
106
107
108 TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
109 @Override
110 public boolean evaluate() throws Exception {
111 return cluster.getClusterStatus().getRegionsInTransition().size() == 0;
112 }
113 });
114 Set<Address> newServers = Sets.newHashSet();
115 newServers.add(
116 rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP).getServers().iterator().next());
117 rsGroupAdmin.moveServers(newServers, appInfo.getName());
118
119
120
121 admin.disableTable(tableName);
122 admin.enableTable(tableName);
123
124
125 TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
126 @Override
127 public boolean evaluate() throws Exception {
128 return cluster.getClusterStatus().getRegionsInTransition().size() == 0;
129 }
130 });
131
132 targetServer = ServerName.parseServerName(
133 newServers.iterator().next().toString());
134 targetRS =
135 admin.getConnection().getAdmin(targetServer);
136 Assert.assertEquals(1, ProtobufUtil.getOnlineRegions(targetRS).size());
137 Assert.assertEquals(tableName,
138 ProtobufUtil.getOnlineRegions(targetRS).get(0).getTable());
139 }
140
141 }