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.Assert.assertEquals;
021import static org.junit.Assert.fail;
022
023import java.io.IOException;
024import java.util.Arrays;
025import org.apache.hadoop.conf.Configuration;
026import org.apache.hadoop.fs.FileSystem;
027import org.apache.hadoop.hbase.HBaseClassTestRule;
028import org.apache.hadoop.hbase.HBaseTestingUtility;
029import org.apache.hadoop.hbase.TableName;
030import org.apache.hadoop.hbase.testclassification.RegionServerTests;
031import org.apache.hadoop.hbase.testclassification.SmallTests;
032import org.apache.hadoop.hbase.wal.WAL;
033import org.apache.hadoop.hbase.wal.WALFactory;
034import org.apache.hadoop.hbase.wal.WALProvider;
035import org.junit.Before;
036import org.junit.ClassRule;
037import org.junit.Rule;
038import org.junit.Test;
039import org.junit.experimental.categories.Category;
040import org.junit.rules.TestName;
041import org.junit.runner.RunWith;
042import org.junit.runners.Parameterized;
043import org.slf4j.Logger;
044import org.slf4j.LoggerFactory;
045
046/**
047 * Ensure configuration changes are having an effect on WAL. There is a lot of reflection around WAL
048 * setup; could be skipping Configuration changes.
049 */
050@RunWith(Parameterized.class)
051@Category({ RegionServerTests.class, SmallTests.class })
052public class TestWALConfiguration {
053  private static final Logger LOG = LoggerFactory.getLogger(TestWALConfiguration.class);
054  static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
055  @ClassRule
056  public static final HBaseClassTestRule CLASS_RULE =
057    HBaseClassTestRule.forClass(TestWALConfiguration.class);
058
059  @Rule
060  public TestName name = new TestName();
061
062  @Parameterized.Parameter
063  public String walProvider;
064
065  @Parameterized.Parameters(name = "{index}: provider={0}")
066  public static Iterable<Object[]> data() {
067    return Arrays.asList(new Object[] { "filesystem" }, new Object[] { "asyncfs" });
068  }
069
070  @Before
071  public void before() {
072    TEST_UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, walProvider);
073  }
074
075  /**
076   * Test blocksize change from HBASE-20520 takes on both asycnfs and old wal provider. Hard to
077   * verify more than this given the blocksize is passed down to HDFS on create -- not kept local to
078   * the streams themselves.
079   */
080  @Test
081  public void testBlocksizeDefaultsToTwiceHDFSBlockSize() throws IOException {
082    TableName tableName = TableName.valueOf("test");
083    final WALFactory walFactory = new WALFactory(TEST_UTIL.getConfiguration(), this.walProvider);
084    Configuration conf = TEST_UTIL.getConfiguration();
085    WALProvider provider = walFactory.getWALProvider();
086    // Get a WAL instance from the provider. Check its blocksize.
087    WAL wal = provider.getWAL(null);
088    if (wal instanceof AbstractFSWAL) {
089      long expectedDefaultBlockSize =
090        WALUtil.getWALBlockSize(conf, FileSystem.get(conf), TEST_UTIL.getDataTestDir());
091      long blocksize = ((AbstractFSWAL) wal).blocksize;
092      assertEquals(expectedDefaultBlockSize, blocksize);
093      LOG.info("Found blocksize of {} on {}", blocksize, wal);
094    } else {
095      fail("Unknown provider " + provider);
096    }
097  }
098}