1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase;
19
20 import java.io.IOException;
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.client.TestMetaWithReplicas;
26 import org.apache.hadoop.hbase.regionserver.StorefileRefresherChore;
27 import org.apache.hadoop.hbase.testclassification.IntegrationTests;
28 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
29 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
30 import org.apache.hadoop.util.ToolRunner;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36
37
38
39
40
41
42
43 @Category(IntegrationTests.class)
44 public class IntegrationTestMetaReplicas {
45 private static final Log LOG = LogFactory.getLog(IntegrationTestMetaReplicas.class);
46
47
48
49 private static IntegrationTestingUtility util;
50
51 @BeforeClass
52 public static void setUp() throws Exception {
53
54 if (util == null) {
55 util = new IntegrationTestingUtility();
56 }
57 util.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3);
58 util.getConfiguration().setInt(
59 StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 1000);
60
61 util.initializeCluster(3);
62 ZooKeeperWatcher zkw = util.getZooKeeperWatcher();
63 Configuration conf = util.getConfiguration();
64 String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
65 HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
66 String primaryMetaZnode = ZKUtil.joinZNode(baseZNode,
67 conf.get("zookeeper.znode.metaserver", "meta-region-server"));
68
69 byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
70 ServerName.parseFrom(data);
71 waitUntilZnodeAvailable(1);
72 waitUntilZnodeAvailable(2);
73 }
74
75 @AfterClass
76 public static void teardown() throws Exception {
77
78 util.restoreCluster();
79 util = null;
80 }
81
82 private static void waitUntilZnodeAvailable(int replicaId) throws Exception {
83 String znode = util.getZooKeeperWatcher().getZNodeForReplica(replicaId);
84 int i = 0;
85 while (i < 1000) {
86 if (ZKUtil.checkExists(util.getZooKeeperWatcher(), znode) == -1) {
87 Thread.sleep(100);
88 i++;
89 } else break;
90 }
91 if (i == 1000) throw new IOException("znode for meta replica " + replicaId + " not available");
92 }
93
94 @Test
95 public void testShutdownHandling() throws Exception {
96
97
98
99
100 TestMetaWithReplicas.shutdownMetaAndDoValidations(util);
101 }
102
103 public static void main(String[] args) throws Exception {
104 setUp();
105 new IntegrationTestMetaReplicas().testShutdownHandling();
106 teardown();
107 }
108 }