001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.wal;
019
020import static org.junit.Assert.assertNotNull;
021import static org.junit.Assert.fail;
022
023import java.io.IOException;
024
025import org.apache.hadoop.conf.Configuration;
026import org.apache.hadoop.hbase.HBaseClassTestRule;
027import org.apache.hadoop.hbase.HBaseTestingUtil;
028import org.apache.hadoop.hbase.TableName;
029import org.apache.hadoop.hbase.client.Get;
030import org.apache.hadoop.hbase.client.Put;
031import org.apache.hadoop.hbase.client.Result;
032import org.apache.hadoop.hbase.client.Table;
033import org.apache.hadoop.hbase.testclassification.MediumTests;
034import org.apache.hadoop.hbase.testclassification.RegionServerTests;
035import org.apache.hadoop.hbase.util.Bytes;
036import org.junit.After;
037import org.junit.AfterClass;
038import org.junit.Before;
039import org.junit.BeforeClass;
040import org.junit.ClassRule;
041import org.junit.Rule;
042import org.junit.Test;
043import org.junit.experimental.categories.Category;
044import org.junit.rules.TestName;
045
046import org.slf4j.Logger;
047import org.slf4j.LoggerFactory;
048
049@Category({ RegionServerTests.class, MediumTests.class })
050public class TestDisabledWAL {
051
052  @ClassRule
053  public static final HBaseClassTestRule CLASS_RULE =
054      HBaseClassTestRule.forClass(TestDisabledWAL.class);
055
056  @Rule
057  public TestName name = new TestName();
058
059  private static final Logger LOG = LoggerFactory.getLogger(TestDisabledWAL.class);
060  static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
061  private Table table;
062  private TableName tableName;
063  private byte[] fam = Bytes.toBytes("f1");
064
065  @BeforeClass
066  public static void beforeClass() throws Exception {
067    Configuration conf = TEST_UTIL.getConfiguration();
068    conf.setBoolean("hbase.regionserver.hlog.enabled", false);
069    try {
070      TEST_UTIL.startMiniCluster();
071    } catch (RuntimeException | IOException e) {
072      LOG.error("Master failed to start.", e);
073      fail("Failed to start cluster. Reason being: " + e.getCause().getMessage());
074    }
075  }
076
077  @AfterClass
078  public static void afterClass() throws Exception {
079    TEST_UTIL.shutdownMiniCluster();
080  }
081
082  @Before
083  public void setup() throws Exception {
084    tableName = TableName.valueOf(name.getMethodName().replaceAll("[^a-zA-Z0-9]", "_"));
085    LOG.info("Creating table " + tableName);
086    table = TEST_UTIL.createTable(tableName, fam);
087  }
088
089  @After
090  public void cleanup() throws Exception {
091    LOG.info("Deleting table " + tableName);
092    TEST_UTIL.deleteTable(tableName);
093  }
094
095  @Test
096  public void testDisabledWAL() throws Exception {
097    LOG.info("Writing data to table " + tableName);
098    Put p = new Put(Bytes.toBytes("row"));
099    p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val"));
100    table.put(p);
101
102    LOG.info("Flushing table " + tableName);
103    TEST_UTIL.flush(tableName);
104
105    LOG.info("Getting data from table " + tableName);
106    Get get = new Get(Bytes.toBytes("row"));
107
108    Result result = table.get(get);
109    assertNotNull(result.getValue(fam, Bytes.toBytes("qual")));
110  }
111}