Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.logging.Log4jUtils;
import org.apache.hadoop.hbase.regionserver.HStore;
Expand All @@ -36,25 +37,20 @@
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.ReflectionUtils;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.Arguments;

/**
* This is not a unit test. It is not run as part of the general unit test suite. It is for
* comparing compaction policies. You must run it explicitly; e.g. mvn test
* -Dtest=PerfTestCompactionPolicies
* This test compares compaction policy behavior with different generated store file lists and
* settings. It can be run explicitly; e.g. mvn test -Dtest=PerfTestCompactionPolicies
*/
@Category({ RegionServerTests.class, MediumTests.class })
@RunWith(Parameterized.class)
@Tag(RegionServerTests.TAG)
@Tag(MediumTests.TAG)
@HBaseParameterizedTestTemplate(
name = "{index}: policy={0}, fileGen={1}, max={2}, min={3}, " + "ratio={4}")
public class PerfTestCompactionPolicies extends MockStoreFileGenerator {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(PerfTestCompactionPolicies.class);

private final RatioBasedCompactionPolicy cp;
private final StoreFileListGenerator generator;
private final HStore store;
Expand All @@ -64,8 +60,7 @@ public class PerfTestCompactionPolicies extends MockStoreFileGenerator {
private final float ratio;
private long written = 0;

@Parameterized.Parameters
public static Collection<Object[]> data() {
public static Stream<Arguments> parameters() {

Class<?>[] policyClasses = new Class[] { EverythingPolicy.class,
RatioBasedCompactionPolicy.class, ExploringCompactionPolicy.class, };
Expand All @@ -79,30 +74,31 @@ public static Collection<Object[]> data() {
int[] minFilesValues = new int[] { 3 };
float[] ratioValues = new float[] { 1.2f };

List<Object[]> params = new ArrayList<>(maxFileValues.length * minFilesValues.length
List<Arguments> params = new ArrayList<>(maxFileValues.length * minFilesValues.length
* fileListGenClasses.length * policyClasses.length);

for (Class<?> policyClass : policyClasses) {
for (Class<?> genClass : fileListGenClasses) {
for (int maxFile : maxFileValues) {
for (int minFile : minFilesValues) {
for (float ratio : ratioValues) {
params.add(new Object[] { policyClass, genClass, maxFile, minFile, ratio });
params.add(Arguments.of(policyClass, genClass, maxFile, minFile, ratio));
}
}
}
}
}

return params;
return params.stream();
}

/**
* Test the perf of a CompactionPolicy with settings.
* @param cpClass The compaction policy to test
* @param inMmax The maximum number of file to compact
* @param inMin The min number of files to compact
* @param inRatio The ratio that files must be under to be compacted.
* @param cpClass The compaction policy to test
* @param fileGenClass The store file list generator to test with
* @param inMmax The maximum number of files to compact
* @param inMin The min number of files to compact
* @param inRatio The ratio that files must be under to be compacted.
*/
public PerfTestCompactionPolicies(final Class<? extends CompactionPolicy> cpClass,
final Class<? extends StoreFileListGenerator> fileGenClass, final int inMmax, final int inMin,
Expand Down Expand Up @@ -134,7 +130,7 @@ public PerfTestCompactionPolicies(final Class<? extends CompactionPolicy> cpClas
// Used for making paths
}

@Test
@TestTemplate
public final void testSelection() throws Exception {
long fileDiff = 0;
for (List<HStoreFile> storeFileList : generator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,21 @@

import static org.apache.hadoop.hbase.regionserver.compactions.CloseChecker.SIZE_LIMIT_KEY;
import static org.apache.hadoop.hbase.regionserver.compactions.CloseChecker.TIME_LIMIT_KEY;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.regionserver.Store;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category(SmallTests.class)
@Tag(SmallTests.TAG)
public class TestCloseChecker {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCloseChecker.class);

@Test
public void testIsClosed() {
Store enableWrite = mock(Store.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.regionserver.compactions;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

import java.io.IOException;
Expand All @@ -31,7 +31,6 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -51,20 +50,16 @@
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

@Category({ MediumTests.class, RegionServerTests.class })
@Tag(MediumTests.TAG)
@Tag(RegionServerTests.TAG)
public class TestCompactedHFilesDischarger {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCompactedHFilesDischarger.class);

private final HBaseTestingUtil testUtil = new HBaseTestingUtil();
private HRegion region;
private final static byte[] fam = Bytes.toBytes("cf_1");
Expand All @@ -75,7 +70,7 @@ public class TestCompactedHFilesDischarger {
private static AtomicInteger scanCompletedCounter = new AtomicInteger(0);
private RegionServerServices rss;

@Before
@BeforeEach
public void setUp() throws Exception {
TableName tableName = TableName.valueOf(getClass().getSimpleName());
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName)
Expand All @@ -90,7 +85,7 @@ public void setUp() throws Exception {
Mockito.doReturn(regions).when(rss).getRegions();
}

@After
@AfterEach
public void tearDown() throws IOException {
counter.set(0);
scanCompletedCounter.set(0);
Expand Down Expand Up @@ -217,12 +212,12 @@ public void testCleanerWithParallelScannersAfterCompaction() throws Exception {
}
compactedfiles = ((HStore) store).getStoreEngine().getStoreFileManager().getCompactedfiles();
for (HStoreFile file : compactedfiles) {
assertEquals("Refcount should be 3", 0, ((HStoreFile) file).getRefCount());
assertEquals(0, ((HStoreFile) file).getRefCount(), "Refcount should be 3");
unusedReaderCount++;
}
// Though there are files we are not using them for reads
assertEquals("unused reader count should be 3", 3, unusedReaderCount);
assertEquals("used reader count should be 1", 1, usedReaderCount);
assertEquals(3, unusedReaderCount, "unused reader count should be 3");
assertEquals(1, usedReaderCount, "used reader count should be 1");
// now run the cleaner
cleaner.chore();
countDown();
Expand Down Expand Up @@ -288,12 +283,12 @@ public void testCleanerWithParallelScanners() throws Exception {
}
compactedfiles = store.getStoreEngine().getStoreFileManager().getCompactedfiles();
for (HStoreFile file : compactedfiles) {
assertEquals("Refcount should be 3", 3, ((HStoreFile) file).getRefCount());
assertEquals(3, ((HStoreFile) file).getRefCount(), "Refcount should be 3");
usedReaderCount++;
}
// The newly compacted file will not be used by any scanner
assertEquals("unused reader count should be 1", 1, unusedReaderCount);
assertEquals("used reader count should be 3", 3, usedReaderCount);
assertEquals(1, unusedReaderCount, "unused reader count should be 1");
assertEquals(3, usedReaderCount, "used reader count should be 3");
// now run the cleaner
cleaner.chore();
countDown();
Expand All @@ -320,12 +315,12 @@ public void testCleanerWithParallelScanners() throws Exception {
}
compactedfiles = ((HStore) store).getStoreEngine().getStoreFileManager().getCompactedfiles();
for (HStoreFile file : compactedfiles) {
assertEquals("Refcount should be 0", 0, file.getRefCount());
assertEquals(0, file.getRefCount(), "Refcount should be 0");
unusedReaderCount++;
}
// Though there are files we are not using them for reads
assertEquals("unused reader count should be 3", 3, unusedReaderCount);
assertEquals("used reader count should be 1", 1, usedReaderCount);
assertEquals(3, unusedReaderCount, "unused reader count should be 3");
assertEquals(1, usedReaderCount, "used reader count should be 1");
countDown();
while (scanCompletedCounter.get() != 3) {
Thread.sleep(100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import static org.apache.hadoop.hbase.regionserver.StripeStoreFileManager.STRIPE_END_KEY;
import static org.apache.hadoop.hbase.regionserver.StripeStoreFileManager.STRIPE_START_KEY;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyCollection;
Expand Down Expand Up @@ -162,8 +162,8 @@ public void verifyKvs(KeyValue[][] kvss, boolean allFiles, boolean requireMetada
public void verifyBoundaries(byte[][] boundaries) {
assertEquals(boundaries.length - 1, writers.size());
for (int i = 0; i < writers.size(); ++i) {
assertArrayEquals("i = " + i, boundaries[i], writers.get(i).data.get(STRIPE_START_KEY));
assertArrayEquals("i = " + i, boundaries[i + 1], writers.get(i).data.get(STRIPE_END_KEY));
assertArrayEquals(boundaries[i], writers.get(i).data.get(STRIPE_START_KEY), "i = " + i);
assertArrayEquals(boundaries[i + 1], writers.get(i).data.get(STRIPE_END_KEY), "i = " + i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@
*/
package org.apache.hadoop.hbase.regionserver.compactions;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import org.apache.hbase.thirdparty.com.google.common.collect.Lists;

@Category({ RegionServerTests.class, SmallTests.class })
@Tag(RegionServerTests.TAG)
@Tag(SmallTests.TAG)
public class TestCurrentHourProvider {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCurrentHourProvider.class);

private static final List<String> ZONE_IDS = Lists.newArrayList("UTC", "US/Pacific", "Etc/GMT+8");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
import static org.apache.hadoop.hbase.regionserver.compactions.CustomTieredCompactor.TIERING_VALUE_PROVIDER;
import static org.apache.hadoop.hbase.regionserver.compactions.RowKeyDateTieringValueProvider.TIERING_KEY_DATE_FORMAT;
import static org.apache.hadoop.hbase.regionserver.compactions.RowKeyDateTieringValueProvider.TIERING_KEY_DATE_PATTERN;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter;
Expand All @@ -46,33 +45,29 @@
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category({ RegionServerTests.class, SmallTests.class })
@Tag(RegionServerTests.TAG)
@Tag(SmallTests.TAG)
public class TestCustomCellTieredCompactor {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCustomCellTieredCompactor.class);

public static final byte[] FAMILY = Bytes.toBytes("cf");

protected HBaseTestingUtil utility;

protected Admin admin;

@Before
@BeforeEach
public void setUp() throws Exception {
utility = new HBaseTestingUtil();
utility.getConfiguration().setInt("hbase.hfile.compaction.discharger.interval", 10);
utility.startMiniCluster();
}

@After
@AfterEach
public void tearDown() throws Exception {
utility.shutdownMiniCluster();
}
Expand Down
Loading