View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase;
21  
22  import static org.junit.Assert.assertEquals;
23  
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.hbase.client.HTable;
26  import org.apache.hadoop.hbase.util.Bytes;
27  import org.junit.After;
28  import org.junit.AfterClass;
29  import org.junit.Before;
30  import org.junit.BeforeClass;
31  import org.junit.Test;
32  import org.junit.experimental.categories.Category;
33  
34  @Category(LargeTests.class)
35  public class TestFullLogReconstruction {
36  
37    private final static HBaseTestingUtility
38        TEST_UTIL = new HBaseTestingUtility();
39  
40    private final static byte[] TABLE_NAME = Bytes.toBytes("tabletest");
41    private final static byte[] FAMILY = Bytes.toBytes("family");
42  
43    /**
44     * @throws java.lang.Exception
45     */
46    @BeforeClass
47    public static void setUpBeforeClass() throws Exception {
48      Configuration c = TEST_UTIL.getConfiguration();
49      c.setBoolean("dfs.support.append", true);
50      // quicker heartbeat interval for faster DN death notification
51      c.setInt("heartbeat.recheck.interval", 5000);
52      c.setInt("dfs.heartbeat.interval", 1);
53      c.setInt("dfs.socket.timeout", 5000);
54      // faster failover with cluster.shutdown();fs.close() idiom
55      c.setInt("hbase.ipc.client.connect.max.retries", 1);
56      c.setInt("dfs.client.block.recovery.retries", 1);
57      c.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
58      TEST_UTIL.startMiniCluster(3);
59    }
60  
61    /**
62     * @throws java.lang.Exception
63     */
64    @AfterClass
65    public static void tearDownAfterClass() throws Exception {
66      TEST_UTIL.shutdownMiniCluster();
67    }
68  
69    /**
70     * @throws java.lang.Exception
71     */
72    @Before
73    public void setUp() throws Exception {
74    }
75  
76    /**
77     * @throws java.lang.Exception
78     */
79    @After
80    public void tearDown() throws Exception {
81    }
82  
83    /**
84     * Test the whole reconstruction loop. Build a table with regions aaa to zzz
85     * and load every one of them multiple times with the same date and do a flush
86     * at some point. Kill one of the region servers and scan the table. We should
87     * see all the rows.
88     * @throws Exception
89     */
90    @Test (timeout=300000)
91    public void testReconstruction() throws Exception {
92  
93      HTable table = TEST_UTIL.createTable(TABLE_NAME, FAMILY);
94  
95      TEST_UTIL.createMultiRegions(table, Bytes.toBytes("family"));
96  
97      // Load up the table with simple rows and count them
98      int initialCount = TEST_UTIL.loadTable(table, FAMILY);
99      int count = TEST_UTIL.countRows(table);
100 
101     assertEquals(initialCount, count);
102 
103     for(int i = 0; i < 4; i++) {
104       TEST_UTIL.loadTable(table, FAMILY);
105     }
106 
107     TEST_UTIL.expireRegionServerSession(0);
108     int newCount = TEST_UTIL.countRows(table);
109     assertEquals(count, newCount);
110     table.close();
111   }
112 }