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);
        }

    }
}