From f5b90fcc442d031af5793b7d57f4c2c4ae5a652c Mon Sep 17 00:00:00 2001 From: Bharath Vissapragada Date: Sun, 31 May 2020 22:45:31 -0700 Subject: [PATCH] HBASE-24479: Deflake TestCompaction#testStopStartCompaction (#1820) Polling of active compaction count is racy. Tightened the asserts to be more reliable. Signed-off-by: Reid Chan --- .../hbase/regionserver/TestCompaction.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java index 584dc234fff..1a97067b0f3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java @@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestCase; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Durability; @@ -448,7 +449,7 @@ public class TestCompaction { // setup a compact/split thread on a mock server HRegionServer mockServer = Mockito.mock(HRegionServer.class); Mockito.when(mockServer.getConfiguration()).thenReturn(r.getBaseConf()); - CompactSplit thread = new CompactSplit(mockServer); + final CompactSplit thread = new CompactSplit(mockServer); Mockito.when(mockServer.getCompactSplitThread()).thenReturn(thread); // setup a region/store with some files HStore store = r.getStore(COLUMN_FAMILY); @@ -459,19 +460,26 @@ public class TestCompaction { thread.switchCompaction(false); thread.requestCompaction(r, store, "test", Store.PRIORITY_USER, CompactionLifeCycleTracker.DUMMY, null); - assertEquals(false, thread.isCompactionsEnabled()); + assertFalse(thread.isCompactionsEnabled()); int longCompactions = thread.getLongCompactions().getActiveCount(); int shortCompactions = thread.getShortCompactions().getActiveCount(); assertEquals("longCompactions=" + longCompactions + "," + "shortCompactions=" + shortCompactions, 0, longCompactions + shortCompactions); thread.switchCompaction(true); - assertEquals(true, thread.isCompactionsEnabled()); + assertTrue(thread.isCompactionsEnabled()); + // Make sure no compactions have run. + assertEquals(0, thread.getLongCompactions().getCompletedTaskCount() + + thread.getShortCompactions().getCompletedTaskCount()); + // Request a compaction and make sure it is submitted successfully. thread.requestCompaction(r, store, "test", Store.PRIORITY_USER, - CompactionLifeCycleTracker.DUMMY, null); - longCompactions = thread.getLongCompactions().getActiveCount(); - shortCompactions = thread.getShortCompactions().getActiveCount(); - assertEquals("longCompactions=" + longCompactions + "," + - "shortCompactions=" + shortCompactions, 1, longCompactions + shortCompactions); + CompactionLifeCycleTracker.DUMMY, null); + // Wait until the compaction finishes. + Waiter.waitFor(UTIL.getConfiguration(), 5000, + (Waiter.Predicate) () -> thread.getLongCompactions().getCompletedTaskCount() + + thread.getShortCompactions().getCompletedTaskCount() == 1); + // Make sure there are no compactions running. + assertEquals(0, thread.getLongCompactions().getActiveCount() + + thread.getShortCompactions().getActiveCount()); } @Test public void testInterruptingRunningCompactions() throws Exception {