TestTimeout.java 738 Bytes
Newer Older
yanzg's avatar
yanzg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import com.yanzuoguang.cloud.aop.Timeout;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.junit.Test;

public class TestTimeout {

    @Test
    public void testTimeout() {
        Timeout<Integer> timeout = new Timeout<>(1);
        long maxTime = 1000;
        long start = System.currentTimeMillis();
        long prev = start;
        while (maxTime > 0) {
            long now = System.currentTimeMillis();
            long runTime = now - start;
            long waitTime = now - prev;
            prev = now;
            maxTime -= waitTime;

            if (timeout.isMaxTime(10, 20)) {
                System.out.println("执行时间" + runTime);
            }
            ThreadHelper.sleep(10);
        }

    }
}