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