• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TimeoutException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testLimitExecutionsAndGetResult

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

    int[] testWindow = new int[1];
    int[] lastValue = new int[1];

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

    try {
        Timeouts.getWithTimeout(2, TimeUnit.SECONDS, ()-> {
            //noinspection InfiniteLoopStatement
            while (true) {
                lastValue[0] = rateLimiter.getWhenReady(() -> {
                    return ++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);

    assertEquals("The rate limiter returns a result", testWindow[0], lastValue[0]);
}
 
开发者ID:rnorth,项目名称:duct-tape,代码行数:31,代码来源:RateLimiterTest.java


示例17: VncRecordingContainer

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
/**
 * Create a sidekick container and attach it to another container. The VNC output of that container will be recorded.
 */
public VncRecordingContainer(@NonNull Network network, @NonNull String targetNetworkAlias) throws IllegalStateException {
    super(TestcontainersConfiguration.getInstance().getVncRecordedContainerImage());

    this.targetNetworkAlias = targetNetworkAlias;
    withNetwork(network);

    waitingFor(new AbstractWaitStrategy() {

        @Override
        protected void waitUntilReady() {
            try {
                Unreliables.retryUntilTrue((int) startupTimeout.toMillis(), TimeUnit.MILLISECONDS, () -> {
                    CountDownLatch latch = new CountDownLatch(1);

                    FrameConsumerResultCallback callback = new FrameConsumerResultCallback() {
                        @Override
                        public void onNext(Frame frame) {
                            if (frame != null && new String(frame.getPayload()).contains("Connected")) {
                                latch.countDown();
                            }
                        }
                    };

                    try (
                            Closeable __ = dockerClient.logContainerCmd(containerId)
                                    .withFollowStream(true)
                                    .withSince(0)
                                    .withStdErr(true)
                                    .exec(callback)
                    ) {
                        return latch.await(1, TimeUnit.SECONDS);
                    }
                });
            } catch (TimeoutException e) {
                throw new ContainerLaunchException("Timed out waiting for log output", e);
            }
        }
    });
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:43,代码来源:VncRecordingContainer.java


示例18: waitUntilReady

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
@Override
protected void waitUntilReady() {
    final Set<Integer> externalLivenessCheckPorts = getLivenessCheckPorts();
    if (externalLivenessCheckPorts.isEmpty()) {
        log.debug("Liveness check ports of {} is empty. Not waiting.", container.getContainerName());
        return;
    }

    @SuppressWarnings("unchecked")
    List<Integer> exposedPorts = container.getExposedPorts();

    final Set<Integer> internalPorts = getInternalPorts(externalLivenessCheckPorts, exposedPorts);

    Callable<Boolean> internalCheck = new InternalCommandPortListeningCheck(container, internalPorts);

    Callable<Boolean> externalCheck = new ExternalPortListeningCheck(container, externalLivenessCheckPorts);

    try {
        Unreliables.retryUntilTrue((int) startupTimeout.getSeconds(), TimeUnit.SECONDS, () -> {
            return getRateLimiter().getWhenReady(() -> internalCheck.call() && externalCheck.call());
        });

    } catch (TimeoutException e) {
        throw new ContainerLaunchException("Timed out waiting for container port to open (" +
                container.getContainerIpAddress() +
                " ports: " +
                externalLivenessCheckPorts +
                " should be listening)");
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:31,代码来源:HostPortWaitStrategy.java


示例19: ping

import org.rnorth.ducttape.TimeoutException; //导入依赖的package包/类
protected void ping(DockerClient client, int timeoutInSeconds) {
    try {
        Unreliables.retryUntilSuccess(timeoutInSeconds, TimeUnit.SECONDS, () -> {
            return PING_RATE_LIMITER.getWhenReady(() -> {
                LOGGER.debug("Pinging docker daemon...");
                client.pingCmd().exec();
                return true;
            });
        });
    } catch (TimeoutException e) {
        IOUtils.closeQuietly(client);
        throw e;
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:15,代码来源:DockerClientProviderStrategy.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HtmlData类代码示例发布时间:2022-05-22
下一篇:
Java CacheableOperation类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap