View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.wal;
19  
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.fail;
22  
23  import java.io.IOException;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.hbase.HBaseTestingUtility;
28  import org.apache.hadoop.hbase.TableName;
29  import org.apache.hadoop.hbase.client.Get;
30  import org.apache.hadoop.hbase.client.Put;
31  import org.apache.hadoop.hbase.client.Result;
32  import org.apache.hadoop.hbase.client.Table;
33  import org.apache.hadoop.hbase.testclassification.MediumTests;
34  import org.apache.hadoop.hbase.testclassification.RegionServerTests;
35  import org.apache.hadoop.hbase.util.Bytes;
36  import org.junit.After;
37  import org.junit.AfterClass;
38  import org.junit.Before;
39  import org.junit.BeforeClass;
40  import org.junit.Rule;
41  import org.junit.Test;
42  import org.junit.experimental.categories.Category;
43  import org.junit.rules.TestName;
44  
45  @Category({ RegionServerTests.class, MediumTests.class })
46  public class TestDisabledWAL {
47  
48    @Rule
49    public TestName name = new TestName();
50  
51    private static final Log LOG = LogFactory.getLog(TestDisabledWAL.class);
52    static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
53    private Table table;
54    private TableName tableName;
55    private byte[] fam = Bytes.toBytes("f1");
56  
57    @BeforeClass
58    public static void beforeClass() throws Exception {
59      Configuration conf = TEST_UTIL.getConfiguration();
60      conf.setBoolean("hbase.regionserver.hlog.enabled", false);
61      try {
62        TEST_UTIL.startMiniCluster();
63      } catch (RuntimeException | IOException e) {
64        LOG.error("Master failed to start.", e);
65        fail("Failed to start cluster. Reason being: " + e.getCause().getMessage());
66      }
67    }
68  
69    @AfterClass
70    public static void afterClass() throws Exception {
71      TEST_UTIL.shutdownMiniCluster();
72    }
73  
74    @Before
75    public void setup() throws Exception {
76      tableName = TableName.valueOf(name.getMethodName().replaceAll("[^a-zA-Z0-9]", "_"));
77      LOG.info("Creating table " + tableName);
78      table = TEST_UTIL.createTable(tableName, fam);
79    }
80  
81    @After
82    public void cleanup() throws Exception {
83      LOG.info("Deleting table " + tableName);
84      TEST_UTIL.deleteTable(tableName);
85    }
86  
87    @Test
88    public void testDisabledWAL() throws Exception {
89      LOG.info("Writing data to table " + tableName);
90      Put p = new Put(Bytes.toBytes("row"));
91      p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val"));
92      table.put(p);
93  
94      LOG.info("Flushing table " + tableName);
95      TEST_UTIL.flush(tableName);
96  
97      LOG.info("Getting data from table " + tableName);
98      Get get = new Get(Bytes.toBytes("row"));
99  
100     Result result = table.get(get);
101     assertNotNull(result.getValue(fam, Bytes.toBytes("qual")));
102   }
103 }