类org.mockito.internal.verification.AtLeast源码实例Demo

下面列出了怎么用org.mockito.internal.verification.AtLeast的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: aws-sdk-java-v2   文件: ConnectionReaperTest.java
@Test
public void idleConnectionReaperDoesNotReapActiveConnections() throws InterruptedException {
    Duration maxIdleTime = Duration.ofSeconds(2);

    try(SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder()
                                                           .connectionMaxIdleTime(maxIdleTime)
                                                           .buildWithDefaults(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)) {
        Instant end = Instant.now().plus(maxIdleTime.plusSeconds(1));

        // Send requests for longer than the max-idle time, ensuring no connections are closed.
        while (Instant.now().isBefore(end)) {
            makeRequest(client);
            Thread.sleep(100);
            verify(TRAFFIC_LISTENER, new Times(0)).closed(any());
        }

        // Do nothing for longer than the max-idle time, ensuring connections are closed.
        Thread.sleep(maxIdleTime.plusSeconds(1).toMillis());

        verify(TRAFFIC_LISTENER, new AtLeast(1)).closed(any());
    }

}
 
源代码2 项目: aws-sdk-java-v2   文件: ConnectionReaperTest.java
@Test
public void oldConnectionReaperReapsActiveConnections() throws InterruptedException {
    Duration connectionTtl = Duration.ofMillis(200);

    try (SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder()
                                                            .connectionTimeToLive(connectionTtl)
                                                            .buildWithDefaults(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)) {

        Instant end = Instant.now().plus(Duration.ofSeconds(5));

        verify(TRAFFIC_LISTENER, new Times(0)).closed(any());

        // Send requests frequently, validating that connections are still being closed.
        while (Instant.now().isBefore(end)) {
            makeRequest(client);
            Thread.sleep(100);
        }

        verify(TRAFFIC_LISTENER, new AtLeast(20)).closed(any());
    }
}
 
@Test
public void testClose() throws Exception {

    CommandFuture<Void> future = new DefaultCommandFuture<>();
    when(command.execute()).thenReturn(future);
    future.setFailure(new Exception());

    RetryCommandFactory<Void> retryCommandFactory = DefaultRetryCommandFactory.retryForever(scheduled, 0);

    OneThreadTaskExecutor oneThreadTaskExecutor = new OneThreadTaskExecutor(retryCommandFactory, executors);

    oneThreadTaskExecutor.executeCommand(command);
    sleep(100);

    logger.info("[testClose][destroy]");
    oneThreadTaskExecutor.destroy();
    retryCommandFactory.destroy();

    sleep(50);
    verify(command, new AtLeast(1)).execute();
    verify(command, new AtLeast(1)).reset();

    logger.info("[testClose][sleep verify no more interactions]");
    sleep(100);
    verifyNoMoreInteractions(command);
}
 
源代码4 项目: x-pipe   文件: OneThreadTaskExecutorTest.java
@Test
public void testClose() throws Exception {

    CommandFuture<Void> future = new DefaultCommandFuture<>();
    when(command.execute()).thenReturn(future);
    future.setFailure(new Exception());

    RetryCommandFactory<Void> retryCommandFactory = DefaultRetryCommandFactory.retryForever(scheduled, 0);

    OneThreadTaskExecutor oneThreadTaskExecutor = new OneThreadTaskExecutor(retryCommandFactory, executors);

    oneThreadTaskExecutor.executeCommand(command);
    sleep(100);

    logger.info("[testClose][destroy]");
    oneThreadTaskExecutor.destroy();
    retryCommandFactory.destroy();

    sleep(50);
    verify(command, new AtLeast(1)).execute();
    verify(command, new AtLeast(1)).reset();

    logger.info("[testClose][sleep verify no more interactions]");
    sleep(100);
    verifyNoMoreInteractions(command);
}
 
源代码5 项目: astor   文件: TimeoutTest.java
@Test
public void shouldCreateCorrectType() {
    Timeout t = new Timeout(25, 50, mode);
    
    assertCorrectMode(t.atLeastOnce(), Timeout.class, 50, 25, AtLeast.class);
    assertCorrectMode(t.atLeast(5), Timeout.class, 50, 25, AtLeast.class);
    assertCorrectMode(t.times(5), Timeout.class, 50, 25, Times.class);
    assertCorrectMode(t.never(), Timeout.class, 50, 25, Times.class);
    assertCorrectMode(t.only(), Timeout.class, 50, 25, Only.class);
    assertCorrectMode(t.atMost(10), Timeout.class, 50, 25, AtMost.class);
}
 
源代码6 项目: astor   文件: TimeoutTest.java
@Test
public void should_create_correctly_configured_timeout() {
    Timeout t = new Timeout(25, 50, mode);
    
    assertTimeoutCorrectlyConfigured(t.atLeastOnce(), Timeout.class, 50, 25, AtLeast.class);
    assertTimeoutCorrectlyConfigured(t.atLeast(5), Timeout.class, 50, 25, AtLeast.class);
    assertTimeoutCorrectlyConfigured(t.times(5), Timeout.class, 50, 25, Times.class);
    assertTimeoutCorrectlyConfigured(t.only(), Timeout.class, 50, 25, Only.class);
}
 
 类所在包
 同包方法