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