HBASE-25014 ScheduledChore is never triggered when initalDelay > 1.5*period (#2395)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
XinSun 2020-09-16 09:00:21 +08:00 committed by GitHub
parent 325317ff9e
commit ca96f96461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -270,7 +270,7 @@ public abstract class ScheduledChore implements Runnable {
choreServicer.cancelChore(this, false);
}
choreServicer = service;
timeOfThisRun = System.currentTimeMillis();
timeOfThisRun = -1;
}
public synchronized void cancel() {

View File

@ -29,9 +29,12 @@ import org.apache.hadoop.hbase.TestChoreService.ScheduledChoreSamples.SampleStop
import org.apache.hadoop.hbase.TestChoreService.ScheduledChoreSamples.SleepingChore;
import org.apache.hadoop.hbase.TestChoreService.ScheduledChoreSamples.SlowChore;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Threads;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,6 +47,9 @@ public class TestChoreService {
public static final Logger log = LoggerFactory.getLogger(TestChoreService.class);
@Rule
public TestName name = new TestName();
/**
* A few ScheduledChore samples that are useful for testing with ChoreService
*/
@ -570,7 +576,7 @@ public class TestChoreService {
ChoreService service = new ChoreService("testNumberOfChoresMissingStartTime");
final int period = 100;
final int sleepTime = 5 * period;
final int sleepTime = 20 * period;
try {
// Slow chores sleep for a length of time LONGER than their period. Thus, SlowChores
@ -835,4 +841,21 @@ public class TestChoreService {
assertFalse(service.scheduleChore(failChore3));
assertFalse(failChore3.isScheduled());
}
/**
* for HBASE-25014
*/
@Test(timeout = 10000)
public void testInitialDelay() {
ChoreService service = new ChoreService(name.getMethodName());
SampleStopper stopper = new SampleStopper();
service.scheduleChore(new ScheduledChore("chore", stopper, 1000, 2000) {
@Override protected void chore() {
stopper.stop("test");
}
});
while (!stopper.isStopped()) {
Threads.sleep(1000);
}
}
}