1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util.hbck;
19
20 import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.assertErrors;
21 import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.doFsck;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Arrays;
26
27 import org.apache.hadoop.hbase.HTableDescriptor;
28 import org.apache.hadoop.hbase.MediumTests;
29 import org.apache.hadoop.hbase.client.HConnectionManager;
30 import org.apache.hadoop.hbase.util.HBaseFsck;
31 import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE;
32 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
36 import org.apache.hadoop.hbase.HBaseTestingUtility;
37
38
39
40 @Category(MediumTests.class)
41 public class TestOfflineMetaRebuildBase extends OfflineMetaRebuildTestCore {
42
43 @Test(timeout = 120000)
44 public void testMetaRebuild() throws Exception {
45 wipeOutMeta();
46
47
48 assertEquals(0, scanMeta());
49 assertErrors(doFsck(conf, false),
50 new ERROR_CODE[] { ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
51 ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
52 ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
53 ERROR_CODE.NOT_IN_META_OR_DEPLOYED, });
54
55
56
57
58 TEST_UTIL.shutdownMiniHBaseCluster();
59 TEST_UTIL.shutdownMiniZKCluster();
60 HConnectionManager.deleteConnection(conf);
61
62
63 HBaseFsck fsck = new HBaseFsck(conf);
64 assertTrue(fsck.rebuildMeta(false));
65
66
67 TEST_UTIL.startMiniZKCluster();
68 TEST_UTIL.restartHBaseCluster(3);
69
70 ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);
71
72 LOG.info("Waiting for no more RIT");
73 ZKAssign.blockUntilNoRIT(zkw);
74 LOG.info("No more RIT in ZK, now doing final test verification");
75
76
77 assertEquals(4, scanMeta());
78 HTableDescriptor[] htbls = TEST_UTIL.getHBaseAdmin().listTables();
79 LOG.info("Tables present after restart: " + Arrays.toString(htbls));
80
81 assertEquals(1, htbls.length);
82 assertErrors(doFsck(conf, false), new ERROR_CODE[] {});
83 LOG.info("Table " + table + " has " + tableRowCount(conf, table)
84 + " entries.");
85 assertEquals(16, tableRowCount(conf, table));
86 }
87
88
89 @org.junit.Rule
90 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
91 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
92 }
93