1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.client.HTable;
27 import org.apache.hadoop.hbase.client.Result;
28 import org.apache.hadoop.hbase.client.ResultScanner;
29 import org.apache.hadoop.hbase.client.Scan;
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.junit.*;
32 import static org.junit.Assert.assertEquals;
33
34 public class TestFullLogReconstruction {
35
36 private final static HBaseTestingUtility
37 TEST_UTIL = new HBaseTestingUtility();
38
39 private final static byte[] TABLE_NAME = Bytes.toBytes("tabletest");
40 private final static byte[] FAMILY = Bytes.toBytes("family");
41
42
43
44
45 @BeforeClass
46 public static void setUpBeforeClass() throws Exception {
47 Configuration c = TEST_UTIL.getConfiguration();
48 c.setInt("hbase.regionserver.flushlogentries", 1);
49 c.setBoolean("dfs.support.append", true);
50
51 c.setInt("heartbeat.recheck.interval", 5000);
52 c.setInt("dfs.heartbeat.interval", 1);
53 c.setInt("dfs.socket.timeout", 5000);
54
55 c.setInt("ipc.client.connect.max.retries", 1);
56 c.setInt("dfs.client.block.recovery.retries", 1);
57 c.setInt("hbase.regionserver.flushlogentries", 1);
58 TEST_UTIL.startMiniCluster(2);
59 }
60
61
62
63
64 @AfterClass
65 public static void tearDownAfterClass() throws Exception {
66 TEST_UTIL.shutdownMiniCluster();
67 }
68
69
70
71
72 @Before
73 public void setUp() throws Exception {
74 }
75
76
77
78
79 @After
80 public void tearDown() throws Exception {
81 }
82
83
84
85
86
87
88
89
90 @Test
91 public void testReconstruction() throws Exception {
92
93 TEST_UTIL.createTable(TABLE_NAME, FAMILY);
94
95 HTable table = new HTable(TABLE_NAME);
96
97 TEST_UTIL.createMultiRegions(table, Bytes.toBytes("family"));
98
99
100 int initialCount = TEST_UTIL.loadTable(table, FAMILY);
101 Scan scan = new Scan();
102 ResultScanner results = table.getScanner(scan);
103 int count = 0;
104 for (Result res : results) {
105 count++;
106 }
107 results.close();
108
109 assertEquals(initialCount, count);
110
111 for(int i = 0; i < 4; i++) {
112 TEST_UTIL.loadTable(table, FAMILY);
113 }
114
115 TEST_UTIL.expireRegionServerSession(0);
116 scan = new Scan();
117 results = table.getScanner(scan);
118 int newCount = 0;
119 for (Result res : results) {
120 newCount++;
121 }
122 assertEquals(count, newCount);
123 }
124 }