diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java index 9d56f771cdf..dd4ad0b7732 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationThrottler.java @@ -65,8 +65,15 @@ public class TestReplicationThrottler { // sleep 1000/100 = 10 cycles = 1s and make throttler2 sleep 1000/10 // = 100 cycles = 10s before the second push occurs -- amortize case // after amortizing, both cycleStartTick and cyclePushSize are reset - assertTrue(ticks1 == 1000 || ticks1 == 999); - assertTrue(ticks2 == 10000 || ticks2 == 9999); + // + // Note: in a slow machine, the sleep interval might be less than ideal ticks. + // If it is 75% of expected value, its is still acceptable. + if (ticks1 != 1000 && ticks1 != 999) { + assertTrue(ticks1 >= 750 && ticks1 <=1000); + } + if (ticks2 != 10000 && ticks2 != 9999) { + assertTrue(ticks1 >= 7500 && ticks1 <=10000); + } throttler1.resetStartTick(); throttler2.resetStartTick(); @@ -83,7 +90,9 @@ public class TestReplicationThrottler { // note: in real case, sleep time should cover time elapses during push // operation assertTrue(ticks1 == 0); - assertTrue(ticks2 == 100 || ticks2 == 99); + if (ticks2 != 100 && ticks2 != 99) { + assertTrue(ticks1 >= 75 && ticks1 <=100); + } throttler2.resetStartTick(); @@ -96,9 +105,13 @@ public class TestReplicationThrottler { // 4. when the fourth push(60) arrives and throttling(60) is called, throttler1 // delay to next cycle since 45+60 == 105; and throttler2 should firstly sleep // ceiling(45/10)= 5 cycles = 500ms to amortize previous push - // note: in real case, sleep time should cover time elapses during push - // operation - assertTrue(ticks1 == 100 || ticks1 == 99); - assertTrue(ticks2 == 500 || ticks2 == 499); + // + // Note: in real case, sleep time should cover time elapses during push operation + if (ticks1 != 100 && ticks1 != 99) { + assertTrue(ticks1 >= 75 && ticks1 <=100); + } + if (ticks2 != 500 && ticks2 != 499) { + assertTrue(ticks1 >= 375 && ticks1 <=500); + } } }