当前位置: 首页>>代码示例>>Java>>正文


Java TimeoutException类代码示例

本文整理汇总了Java中org.rnorth.ducttape.TimeoutException的典型用法代码示例。如果您正苦于以下问题:Java TimeoutException类的具体用法?Java TimeoutException怎么用?Java TimeoutException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TimeoutException类属于org.rnorth.ducttape包,在下文中一共展示了TimeoutException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: appliesOuterTimeout

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void appliesOuterTimeout() {

    final WaitStrategy underTest = new WaitAllStrategy()
            .withStrategy(strategy1)
            .withStartupTimeout(Duration.ofMillis(10));

    doAnswer(invocation -> {
        Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
        return null;
    }).when(strategy1).waitUntilReady(eq(container));

    assertThrows("The outer strategy timeout applies", TimeoutException.class, () -> {
        underTest.waitUntilReady(container);
    });
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:17,代码来源:WaitAllStrategyTest.java

示例2: testNeverConsistent

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testNeverConsistent() {
    try {
        Inconsistents.retryUntilConsistent(50, 1000, TimeUnit.MILLISECONDS, () -> {
            Thread.sleep(10L);
            return System.currentTimeMillis();
        });
    } catch (TimeoutException e) {
        Throwable cause = e.getCause();
        assertEquals("An exception is thrown if the result is never consistent", ResultsNeverConsistentException.class, cause.getClass());
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:13,代码来源:InconsistentsTest.java

示例3: testNotConsistentLongEnough

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testNotConsistentLongEnough() {
    try {
        Inconsistents.retryUntilConsistent(50, 1000, TimeUnit.MILLISECONDS, () -> {
            Thread.sleep(10L);
            return System.currentTimeMillis() / 49;
        });
    } catch (TimeoutException e) {
        Throwable cause = e.getCause();
        assertEquals("An exception is thrown if the result is never consistent", InconsistentResultsException.class, cause.getClass());
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:13,代码来源:InconsistentsTest.java

示例4: testRetryUntilTrueImmediateSuccess

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilTrueImmediateSuccess() throws Exception {
    try {
        Unreliables.retryUntilTrue(500, TimeUnit.MILLISECONDS, () -> true);
    } catch (TimeoutException e) {
        fail("When retrying until true, an immediate return true should be OK but timed out");
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:9,代码来源:UnreliablesTest.java

示例5: testRetryUntilTrueSuccessWithinTimeoutWindow

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilTrueSuccessWithinTimeoutWindow() throws Exception {
    try {
        Unreliables.retryUntilTrue(500, TimeUnit.MILLISECONDS, () -> {
            Thread.sleep(300L);
            return true;
        });
    } catch (TimeoutException e) {
        fail("When retrying until true, a return true within the timeout window should be OK but timed out");
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:12,代码来源:UnreliablesTest.java

示例6: testRetryUntilTrueSuccessWithinTimeoutWindowWithManyFailures

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilTrueSuccessWithinTimeoutWindowWithManyFailures() throws Exception {
    long start = System.currentTimeMillis();
    try {
        Unreliables.retryUntilTrue(500, TimeUnit.MILLISECONDS, () -> {
            return System.currentTimeMillis() - start > 300;
        });
    } catch (TimeoutException e) {
        fail("When retrying until true, a return true within the timeout window should be OK but timed out");
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:12,代码来源:UnreliablesTest.java

示例7: testRetryUntilTrueFailsWhenOutsideTimeoutWindow

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilTrueFailsWhenOutsideTimeoutWindow() throws Exception {
    try {
        Unreliables.retryUntilTrue(500, TimeUnit.MILLISECONDS, () -> {
            Thread.sleep(600L);
            return true;
        });
        fail("When retrying until true, a return true outside the timeout window should throw a timeout exception");
    } catch (TimeoutException e) {
        // ok
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:13,代码来源:UnreliablesTest.java

示例8: testRetryUntilSuccessImmediateSuccess

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilSuccessImmediateSuccess() throws Exception {
    try {
        String result = Unreliables.retryUntilSuccess(500, TimeUnit.MILLISECONDS, () -> "OK");
        assertEquals("A result can be returned using retryUntilSuccess", "OK", result);
    } catch (TimeoutException e) {
        fail("When retrying until true, an immediate return true should be OK but timed out");
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:10,代码来源:UnreliablesTest.java

示例9: testRetryUntilSuccessWithinTimeoutWindow

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilSuccessWithinTimeoutWindow() throws Exception {
    try {
        String result = Unreliables.retryUntilSuccess(500, TimeUnit.MILLISECONDS, () -> {
            Thread.sleep(300L);
            return "OK";
        });
        assertEquals("A result can be returned using retryUntilSuccess", "OK", result);
    } catch (TimeoutException e) {
        fail("When retrying until true, a return true within the timeout window should be OK but timed out");
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:13,代码来源:UnreliablesTest.java

示例10: testRetryUntilSuccessWithinTimeoutWindowWithManyFailures

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilSuccessWithinTimeoutWindowWithManyFailures() throws Exception {
    long start = System.currentTimeMillis();
    try {
        String result = Unreliables.retryUntilSuccess(500, TimeUnit.MILLISECONDS, () -> {
            if (System.currentTimeMillis() - start < 300) {
                throw new Exception("FAILURE");
            }
            return "OK";
        });
        assertEquals("A result can be returned using retryUntilSuccess", "OK", result);
    } catch (TimeoutException e) {
        fail("When retrying until true, a return true within the timeout window should be OK but timed out");
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:16,代码来源:UnreliablesTest.java

示例11: testRetryUntilSuccessFailsWhenOutsideTimeoutWindow

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilSuccessFailsWhenOutsideTimeoutWindow() throws Exception {
    String result = "NOT OK";
    try {
        result = Unreliables.retryUntilSuccess(500, TimeUnit.MILLISECONDS, () -> {
            Thread.sleep(600L);
            return "OK";
        });
        fail("When retrying until true, a return true outside the timeout window should throw a timeout exception");
    } catch (TimeoutException e) {
        // ok
        assertEquals("A result can be returned using retryUntilSuccess", "NOT OK", result);
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:15,代码来源:UnreliablesTest.java

示例12: testRetryUntilSuccessFailsWhenOutsideTimeoutWindowAndCapturesException

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testRetryUntilSuccessFailsWhenOutsideTimeoutWindowAndCapturesException() throws Exception {
    try {
        Unreliables.retryUntilSuccess(500, TimeUnit.MILLISECONDS, () -> {
            throw new IllegalStateException("This is the exception");
        });
        fail("When retrying until true, a return true outside the timeout window should throw a timeout exception");
    } catch (TimeoutException e) {
        // ok
        assertEquals("A result can be returned using retryUntilSuccess", "This is the exception", e.getCause().getMessage());
    }
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:13,代码来源:UnreliablesTest.java

示例13: timeoutThrowsException

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void timeoutThrowsException() {
    assertThrows("It throws a TimeoutException if execution time is exceeded", TimeoutException.class, () -> {
        Timeouts.doWithTimeout(1, TimeUnit.SECONDS, () -> {
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException ignored) { }
        });
    });
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:11,代码来源:TimeoutsTest.java

示例14: timeoutThrowsExceptionWithoutReturnValue

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void timeoutThrowsExceptionWithoutReturnValue() {
    assertThrows("It throws a TimeoutException if execution time is exceeded", TimeoutException.class, () -> {
        Timeouts.getWithTimeout(1, TimeUnit.SECONDS, () -> {
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException ignored) { }
            return "result";
        });
    });
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:12,代码来源:TimeoutsTest.java

示例15: testLimitExecutions

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Test
public void testLimitExecutions() {

    int[] testWindow = new int[1];

    RateLimiter rateLimiter = RateLimiterBuilder.newBuilder()
                                         .withRate(10, TimeUnit.SECONDS)
                                         .withConstantThroughput()
                                         .build();

    try {
        Timeouts.getWithTimeout(2, TimeUnit.SECONDS, ()-> {
            //noinspection InfiniteLoopStatement
            while (true) {
                rateLimiter.doWhenReady(() -> {
                    testWindow[0]++;
                });
            }
        });
    } catch (TimeoutException ignored) {
        // We're just using a timeout here to limit execution to a given time
    }

    // Approximate estimates
    assertTrue("The rate limiter should have kept executions at or below 21", testWindow[0] <= 21);
    assertTrue("The rate limiter should allowed at least 15 executions", testWindow[0] >= 15);
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:28,代码来源:RateLimiterTest.java


注:本文中的org.rnorth.ducttape.TimeoutException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。