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.regionserver.wal;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.fail;
022
023import java.io.IOException;
024import java.util.stream.Stream;
025import org.apache.hadoop.conf.Configuration;
026import org.apache.hadoop.fs.FileSystem;
027import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
028import org.apache.hadoop.hbase.HBaseTestingUtil;
029import org.apache.hadoop.hbase.testclassification.RegionServerTests;
030import org.apache.hadoop.hbase.testclassification.SmallTests;
031import org.apache.hadoop.hbase.wal.WAL;
032import org.apache.hadoop.hbase.wal.WALFactory;
033import org.apache.hadoop.hbase.wal.WALProvider;
034import org.junit.jupiter.api.BeforeEach;
035import org.junit.jupiter.api.Tag;
036import org.junit.jupiter.api.TestTemplate;
037import org.junit.jupiter.params.provider.Arguments;
038import org.slf4j.Logger;
039import org.slf4j.LoggerFactory;
040
041/**
042 * Ensure configuration changes are having an effect on WAL. There is a lot of reflection around WAL
043 * setup; could be skipping Configuration changes.
044 */
045@Tag(RegionServerTests.TAG)
046@Tag(SmallTests.TAG)
047@HBaseParameterizedTestTemplate(name = "{index}: provider={0}")
048public class TestWALConfiguration {
049  private static final Logger LOG = LoggerFactory.getLogger(TestWALConfiguration.class);
050  static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
051
052  private final String walProvider;
053
054  public static Stream<Arguments> parameters() {
055    return Stream.of(Arguments.of("filesystem"), Arguments.of("asyncfs"));
056  }
057
058  public TestWALConfiguration(String walProvider) {
059    this.walProvider = walProvider;
060  }
061
062  @BeforeEach
063  public void before() {
064    TEST_UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, walProvider);
065  }
066
067  /**
068   * Test blocksize change from HBASE-20520 takes on both asycnfs and old wal provider. Hard to
069   * verify more than this given the blocksize is passed down to HDFS on create -- not kept local to
070   * the streams themselves.
071   */
072  @TestTemplate
073  public void testBlocksizeDefaultsToTwiceHDFSBlockSize() throws IOException {
074    final WALFactory walFactory = new WALFactory(TEST_UTIL.getConfiguration(), this.walProvider);
075    Configuration conf = TEST_UTIL.getConfiguration();
076    WALProvider provider = walFactory.getWALProvider();
077    // Get a WAL instance from the provider. Check its blocksize.
078    WAL wal = provider.getWAL(null);
079    if (wal instanceof AbstractFSWAL) {
080      long expectedDefaultBlockSize =
081        WALUtil.getWALBlockSize(conf, FileSystem.get(conf), TEST_UTIL.getDataTestDir());
082      long blocksize = ((AbstractFSWAL) wal).blocksize;
083      assertEquals(expectedDefaultBlockSize, blocksize);
084      LOG.info("Found blocksize of {} on {}", blocksize, wal);
085    } else {
086      fail("Unknown provider " + provider);
087    }
088  }
089}