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