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.Assert.assertTrue;
021
022import org.apache.hadoop.fs.Path;
023import org.apache.hadoop.hbase.HBaseClassTestRule;
024import org.apache.hadoop.hbase.HBaseTestingUtility;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.regionserver.HRegionServer;
027import org.apache.hadoop.hbase.testclassification.MediumTests;
028import org.apache.hadoop.hbase.testclassification.RegionServerTests;
029import org.apache.hadoop.hbase.util.Bytes;
030import org.junit.AfterClass;
031import org.junit.BeforeClass;
032import org.junit.ClassRule;
033import org.junit.Test;
034import org.junit.experimental.categories.Category;
035
036/**
037 * Testcase for HBASE-21843. Used to confirm that we use the correct name for meta wal file when
038 * using {@link RegionGroupingProvider}.
039 */
040@Category({ RegionServerTests.class, MediumTests.class })
041public class TestWrongMetaWALFileName {
042
043  @ClassRule
044  public static final HBaseClassTestRule CLASS_RULE =
045    HBaseClassTestRule.forClass(TestWrongMetaWALFileName.class);
046
047  private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
048
049  @BeforeClass
050  public static void setUp() throws Exception {
051    UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, WALFactory.Providers.multiwal.name());
052    UTIL.startMiniCluster(1);
053  }
054
055  @AfterClass
056  public static void tearDown() throws Exception {
057    UTIL.shutdownMiniCluster();
058  }
059
060  @Test
061  public void test() throws Exception {
062    // create a table so that we will write some edits to meta
063    TableName tableName = TableName.valueOf("whatever");
064    UTIL.createTable(tableName, Bytes.toBytes("family"));
065    UTIL.waitTableAvailable(tableName);
066    HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(0);
067    Path walDir = new Path(rs.getWALRootDir(),
068      AbstractFSWALProvider.getWALDirectoryName(rs.getServerName().toString()));
069    // we should have meta wal files.
070    assertTrue(
071      rs.getWALFileSystem().listStatus(walDir, AbstractFSWALProvider::isMetaFile).length > 0);
072  }
073}