Skip to content

Commit

Permalink
Wait until the connect process is fully completed before asserting state
Browse files Browse the repository at this point in the history
Related issue: logfellow#560
  • Loading branch information
brenuart committed Jul 8, 2021
1 parent b1ec1db commit 3e2d526
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -46,17 +47,19 @@
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;

import javax.net.SocketFactory;

import net.logstash.logback.appender.destination.RandomDestinationConnectionStrategy;
import net.logstash.logback.appender.destination.RoundRobinDestinationConnectionStrategy;
import net.logstash.logback.appender.listener.TcpAppenderListener;
import net.logstash.logback.encoder.SeparatorParser;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.encoder.Encoder;
import ch.qos.logback.core.status.StatusManager;
import ch.qos.logback.core.util.Duration;
import net.logstash.logback.appender.destination.RandomDestinationConnectionStrategy;
import net.logstash.logback.appender.destination.RoundRobinDestinationConnectionStrategy;
import net.logstash.logback.appender.listener.TcpAppenderListener;
import net.logstash.logback.encoder.SeparatorParser;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -173,7 +176,7 @@ public void testReconnectOnOpen() throws Exception {

appender.stop();

verify(listener).connectionClosed(appender, socket);
verify(listener, timeout(VERIFICATION_TIMEOUT)).connectionClosed(appender, socket);

assertThat(appender.getConnectedDestination()).isNotPresent();
}
Expand Down Expand Up @@ -234,14 +237,16 @@ public void testConnectOnPrimary() throws Exception {
appender.start();
verify(encoder).start();

// Wait for the connection process to be fully completed
verify(listener, timeout(VERIFICATION_TIMEOUT)).connectionOpened(appender, socket);

// Only one socket should have been created
verify(socket, timeout(VERIFICATION_TIMEOUT).times(1)).connect(any(SocketAddress.class), anyInt());
verify(socket, times(1)).connect(any(SocketAddress.class), anyInt());

// The only socket should be connected to primary
verify(socket).connect(host("localhost", 10000), anyInt());

assertThat(appender.getConnectedDestination()).isPresent();

}


Expand Down

0 comments on commit 3e2d526

Please sign in to comment.