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.jupiter.api.Assertions.assertNotNull;
021import static org.junit.jupiter.api.Assertions.fail;
022
023import java.io.IOException;
024import org.apache.hadoop.conf.Configuration;
025import org.apache.hadoop.hbase.HBaseTestingUtil;
026import org.apache.hadoop.hbase.TableName;
027import org.apache.hadoop.hbase.client.Get;
028import org.apache.hadoop.hbase.client.Put;
029import org.apache.hadoop.hbase.client.Result;
030import org.apache.hadoop.hbase.client.Table;
031import org.apache.hadoop.hbase.testclassification.MediumTests;
032import org.apache.hadoop.hbase.testclassification.RegionServerTests;
033import org.apache.hadoop.hbase.util.Bytes;
034import org.junit.jupiter.api.AfterAll;
035import org.junit.jupiter.api.AfterEach;
036import org.junit.jupiter.api.BeforeAll;
037import org.junit.jupiter.api.BeforeEach;
038import org.junit.jupiter.api.Tag;
039import org.junit.jupiter.api.Test;
040import org.junit.jupiter.api.TestInfo;
041import org.slf4j.Logger;
042import org.slf4j.LoggerFactory;
043
044@Tag(RegionServerTests.TAG)
045@Tag(MediumTests.TAG)
046public class TestDisabledWAL {
047
048  private static final Logger LOG = LoggerFactory.getLogger(TestDisabledWAL.class);
049  static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
050  private Table table;
051  private TableName tableName;
052  private byte[] fam = Bytes.toBytes("f1");
053
054  @BeforeAll
055  public static void beforeClass() throws Exception {
056    Configuration conf = TEST_UTIL.getConfiguration();
057    conf.setBoolean("hbase.regionserver.hlog.enabled", false);
058    try {
059      TEST_UTIL.startMiniCluster();
060    } catch (RuntimeException | IOException e) {
061      LOG.error("Master failed to start.", e);
062      fail("Failed to start cluster. Reason being: " + e.getCause().getMessage());
063    }
064  }
065
066  @AfterAll
067  public static void afterClass() throws Exception {
068    TEST_UTIL.shutdownMiniCluster();
069  }
070
071  @BeforeEach
072  public void setup(TestInfo testInfo) throws Exception {
073    tableName =
074      TableName.valueOf(testInfo.getTestMethod().get().getName().replaceAll("[^a-zA-Z0-9]", "_"));
075    LOG.info("Creating table " + tableName);
076    table = TEST_UTIL.createTable(tableName, fam);
077  }
078
079  @AfterEach
080  public void cleanup() throws Exception {
081    LOG.info("Deleting table " + tableName);
082    TEST_UTIL.deleteTable(tableName);
083  }
084
085  @Test
086  public void testDisabledWAL() throws Exception {
087    LOG.info("Writing data to table " + tableName);
088    Put p = new Put(Bytes.toBytes("row"));
089    p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val"));
090    table.put(p);
091
092    LOG.info("Flushing table " + tableName);
093    TEST_UTIL.flush(tableName);
094
095    LOG.info("Getting data from table " + tableName);
096    Get get = new Get(Bytes.toBytes("row"));
097
098    Result result = table.get(get);
099    assertNotNull(result.getValue(fam, Bytes.toBytes("qual")));
100  }
101}