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.testclassification.LargeTests;
27  import org.apache.hadoop.hbase.util.Bytes;
28  import org.junit.After;
29  import org.junit.AfterClass;
30  import org.junit.Before;
31  import org.junit.BeforeClass;
32  import org.junit.Test;
33  import org.junit.experimental.categories.Category;
34  
35  @Category(LargeTests.class)
36  public class TestFullLogReconstruction {
37  
38    private final static HBaseTestingUtility
39        TEST_UTIL = new HBaseTestingUtility();
40  
41    private final static TableName TABLE_NAME = TableName.valueOf("tabletest");
42    private final static byte[] FAMILY = Bytes.toBytes("family");
43  
44    /**
45     * @throws java.lang.Exception
46     */
47    @BeforeClass
48    public static void setUpBeforeClass() throws Exception {
49      Configuration c = TEST_UTIL.getConfiguration();
50      c.setBoolean("dfs.support.append", true);
51      // quicker heartbeat interval for faster DN death notification
52      c.setInt("dfs.namenode.heartbeat.recheck-interval", 5000);
53      c.setInt("dfs.heartbeat.interval", 1);
54      c.setInt("dfs.client.socket-timeout", 5000);
55      // faster failover with cluster.shutdown();fs.close() idiom
56      c.setInt("hbase.ipc.client.connect.max.retries", 1);
57      c.setInt("dfs.client.block.recovery.retries", 1);
58      c.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
59      TEST_UTIL.startMiniCluster(3);
60    }
61  
62    /**
63     * @throws java.lang.Exception
64     */
65    @AfterClass
66    public static void tearDownAfterClass() throws Exception {
67      TEST_UTIL.shutdownMiniCluster();
68    }
69  
70    /**
71     * @throws java.lang.Exception
72     */
73    @Before
74    public void setUp() throws Exception {
75    }
76  
77    /**
78     * @throws java.lang.Exception
79     */
80    @After
81    public void tearDown() throws Exception {
82    }
83  
84    /**
85     * Test the whole reconstruction loop. Build a table with regions aaa to zzz
86     * and load every one of them multiple times with the same date and do a flush
87     * at some point. Kill one of the region servers and scan the table. We should
88     * see all the rows.
89     * @throws Exception
90     */
91    @Test (timeout=300000)
92    public void testReconstruction() throws Exception {
93      HTable table = TEST_UTIL.createMultiRegionTable(TABLE_NAME, FAMILY);
94  
95      // Load up the table with simple rows and count them
96      int initialCount = TEST_UTIL.loadTable(table, FAMILY);
97      int count = TEST_UTIL.countRows(table);
98  
99      assertEquals(initialCount, count);
100 
101     for(int i = 0; i < 4; i++) {
102       TEST_UTIL.loadTable(table, FAMILY);
103     }
104 
105     TEST_UTIL.expireRegionServerSession(0);
106     int newCount = TEST_UTIL.countRows(table);
107     assertEquals(count, newCount);
108     table.close();
109   }
110 }