org.mockito.internal.verification.AtLeast Java Examples

The following examples show how to use org.mockito.internal.verification.AtLeast. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectionReaperTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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());
    }

}
 
Example #2
Source File: ConnectionReaperTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example #3
Source File: MutexableOneThreadTaskExecutorTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: OneThreadTaskExecutorTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: TimeoutTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: TimeoutTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@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);
}