Merge pull request #11937 from kwoyke/JAVA-10238

JAVA-10238: Use random port in the integration test
This commit is contained in:
Loredana Crusoveanu 2022-03-18 16:40:58 +02:00 committed by GitHub
commit ac99726577
1 changed files with 18 additions and 2 deletions

View File

@ -10,16 +10,23 @@ import com.twitter.util.Future;
import org.junit.Test;
import scala.runtime.BoxedUnit;
import java.io.IOException;
import java.net.ServerSocket;
import static org.junit.Assert.assertEquals;
public class FinagleIntegrationTest {
private static final int DEFAULT_PORT = 8079;
@Test
public void givenServerAndClient_whenRequestSent_thenClientShouldReceiveResponseFromServer() throws Exception {
// given
int port = randomPort();
Service serverService = new LogFilter().andThen(new GreetingService());
Http.serve(":8080", serverService);
Http.serve(":" + port, serverService);
Service<Request, Response> clientService = new LogFilter().andThen(Http.newService(":8080"));
Service<Request, Response> clientService = new LogFilter().andThen(Http.newService(":" + port));
// when
Request request = Request.apply(Method.Get(), "/?name=John");
@ -37,4 +44,13 @@ public class FinagleIntegrationTest {
})
);
}
private int randomPort() {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
} catch (IOException e) {
return DEFAULT_PORT;
}
}
}