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.assertEquals;
021
022import java.util.stream.Stream;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
025import org.apache.hadoop.hbase.testclassification.MediumTests;
026import org.apache.hadoop.hbase.testclassification.RegionServerTests;
027import org.junit.jupiter.api.Tag;
028import org.junit.jupiter.api.TestTemplate;
029import org.junit.jupiter.params.provider.Arguments;
030
031/**
032 * Tests for TestBoundedRegionGroupingStrategy which use WALPerformanceEvaluation for WAL data
033 * creation. This class was created as part of refactoring for hbase-diagnostics module creation in
034 * HBASE-28432 to break cyclic dependency.
035 */
036@Tag(RegionServerTests.TAG)
037@Tag(MediumTests.TAG)
038@HBaseParameterizedTestTemplate
039public class TestBoundedRegionGroupingStrategyUsingWPETool
040  extends TestBoundedRegionGroupingStrategy {
041
042  public TestBoundedRegionGroupingStrategyUsingWPETool(String walProvider) {
043    super(walProvider);
044  }
045
046  public static Stream<Arguments> parameters() {
047    return TestBoundedRegionGroupingStrategy.parameters();
048  }
049
050  /**
051   * Write to a log file with three concurrent threads and verifying all data is written.
052   */
053  @TestTemplate
054  public void testConcurrentWrites() throws Exception {
055    // Run the WPE tool with three threads writing 3000 edits each concurrently.
056    // When done, verify that all edits were written.
057    int errCode = WALPerformanceEvaluation.innerMain(new Configuration(CONF),
058      new String[] { "-threads", "3", "-verify", "-noclosefs", "-iterations", "3000" });
059    assertEquals(0, errCode);
060  }
061
062  /**
063   * Make sure we can successfully run with more regions then our bound.
064   */
065  @TestTemplate
066  public void testMoreRegionsThanBound() throws Exception {
067    final String parallelism =
068      Integer.toString(BoundedGroupingStrategy.DEFAULT_NUM_REGION_GROUPS * 2);
069    int errCode =
070      WALPerformanceEvaluation.innerMain(new Configuration(CONF), new String[] { "-threads",
071        parallelism, "-verify", "-noclosefs", "-iterations", "3000", "-regions", parallelism });
072    assertEquals(0, errCode);
073  }
074
075  @TestTemplate
076  public void testBoundsGreaterThanDefault() throws Exception {
077    final int temp = CONF.getInt(BoundedGroupingStrategy.NUM_REGION_GROUPS,
078      BoundedGroupingStrategy.DEFAULT_NUM_REGION_GROUPS);
079    try {
080      CONF.setInt(BoundedGroupingStrategy.NUM_REGION_GROUPS, temp * 4);
081      final String parallelism = Integer.toString(temp * 4);
082      int errCode =
083        WALPerformanceEvaluation.innerMain(new Configuration(CONF), new String[] { "-threads",
084          parallelism, "-verify", "-noclosefs", "-iterations", "3000", "-regions", parallelism });
085      assertEquals(0, errCode);
086    } finally {
087      CONF.setInt(BoundedGroupingStrategy.NUM_REGION_GROUPS, temp);
088    }
089  }
090
091  @TestTemplate
092  public void testMoreRegionsThanBoundWithBoundsGreaterThanDefault() throws Exception {
093    final int temp = CONF.getInt(BoundedGroupingStrategy.NUM_REGION_GROUPS,
094      BoundedGroupingStrategy.DEFAULT_NUM_REGION_GROUPS);
095    try {
096      CONF.setInt(BoundedGroupingStrategy.NUM_REGION_GROUPS, temp * 4);
097      final String parallelism = Integer.toString(temp * 4 * 2);
098      int errCode =
099        WALPerformanceEvaluation.innerMain(new Configuration(CONF), new String[] { "-threads",
100          parallelism, "-verify", "-noclosefs", "-iterations", "3000", "-regions", parallelism });
101      assertEquals(0, errCode);
102    } finally {
103      CONF.setInt(BoundedGroupingStrategy.NUM_REGION_GROUPS, temp);
104    }
105  }
106}