1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }