@@ -0,0 +1,1994 @@
+package alluxio.heartbeat;%0A%0Aimport alluxio.util.CommonUtils;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mockito;%0Aimport org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;%0Aimport org.powermock.reflect.Whitebox;%0Aimport org.slf4j.Logger;%0A%0A%0A/**%0A * Created by shayne on 5/17/16.%0A *%0A * Unit tests for %7B@link SleepingTimer%7D.%0A *%0A * 1. Sleep more than the interval of SleepingTimer and see if the SleepingTimer warns correctly%0A * 2. Tick continuously for several time and see if the time interval is correct%0A * 3. Sleep less than the interval of SleepingTimer and see if the time interval is correct%0A */%0A%0A@RunWith(PowerMockRunner.class)%0A@PrepareForTest(%7BSleepingTimer.class%7D)%0Apublic class SleepingTimerTest %7B%0A    private static final String THREAD_NAME = %22sleepingtimer-test-thread-name%22;%0A    private static final long INTERVAL_MS = 500;%0A%0A    @Test%0A    public void test() throws Exception %7B%0A        SleepingTimer stimer =new SleepingTimer(THREAD_NAME, INTERVAL_MS);%0A%0A        Logger logger= Mockito.mock(Logger.class);%0A        long PreTickMs = 0;%0A%0A        Whitebox.setInternalState(SleepingTimer.class,%22LOG%22,logger);%0A%0A        Whitebox.setInternalState(stimer,%22mPreviousTickMs%22,PreTickMs);%0A%0A%0A        stimer.tick();%0A        CommonUtils.sleepMs(5 * INTERVAL_MS);%0A        stimer.tick();%0A%0A        Mockito.verify(logger).warn(Mockito.anyString(), Mockito.anyString(), Mockito.anyLong(), Mockito.anyLong());%0A%0A        long timeBeforeMs = PreTickMs;%0A        stimer.tick();%0A        stimer.tick();%0A        stimer.tick();%0A        long timeIntervalMs = System.currentTimeMillis() - timeBeforeMs;%0A        Assert.assertTrue(timeIntervalMs %3E= 3 * INTERVAL_MS);%0A%0A%0A%0A        timeBeforeMs = PreTickMs;%0A        CommonUtils.sleepMs(INTERVAL_MS / 2);%0A        stimer.tick();%0A        timeIntervalMs = System.currentTimeMillis() - timeBeforeMs;%0A        Assert.assertTrue(timeIntervalMs %3E= INTERVAL_MS);%0A%0A    %7D%0A%7D%0A

add unit test for sleepingtimer