3939import org .junit .jupiter .api .BeforeAll ;
4040import org .junit .jupiter .api .BeforeEach ;
4141import org .testcontainers .containers .DockerComposeContainer ;
42+ import org .testcontainers .containers .output .OutputFrame ;
4243import org .testcontainers .containers .wait .strategy .Wait ;
4344import org .testcontainers .junit .jupiter .Testcontainers ;
4445
4546@ Testcontainers
4647abstract class ServingEnvironment {
4748 static DockerComposeContainer environment ;
48-
49+ static int serverPort = getFreePort ();
4950 ServingServiceGrpc .ServingServiceBlockingStub servingStub ;
5051 Injector injector ;
5152 String serverName ;
5253 ManagedChannel channel ;
5354 Server server ;
5455 MutableHandlerRegistry serviceRegistry ;
5556
56- static int serverPort = getFreePort ();
57-
5857 @ BeforeAll
5958 static void globalSetup () {
6059 environment =
6160 new DockerComposeContainer (
6261 new File ("src/test/resources/docker-compose/docker-compose-redis-it.yml" ))
6362 .withExposedService ("redis" , 6379 )
6463 .withExposedService ("feast" , 8080 )
65- .waitingFor ("feast" , Wait .forListeningPort ());
64+ .waitingFor ("feast" , Wait .forListeningPort ())
65+ .withLogConsumer ("feast" , f -> System .out .print (((OutputFrame ) f ).getUtf8String ()));
6666 environment .start ();
6767 }
6868
@@ -71,6 +71,20 @@ static void globalTeardown() {
7171 environment .stop ();
7272 }
7373
74+ private static int getFreePort () {
75+ ServerSocket serverSocket ;
76+ try {
77+ serverSocket = new ServerSocket (0 );
78+ } catch (IOException e ) {
79+ throw new RuntimeException ("Couldn't allocate port" );
80+ }
81+
82+ assertThat (serverSocket , is (notNullValue ()));
83+ assertThat (serverSocket .getLocalPort (), greaterThan (0 ));
84+
85+ return serverSocket .getLocalPort ();
86+ }
87+
7488 @ BeforeEach
7589 public void envSetUp () throws Exception {
7690 AbstractModule appPropertiesModule =
@@ -155,18 +169,4 @@ public void envTeardown() throws Exception {
155169 AbstractModule registryConfig () {
156170 return null ;
157171 }
158-
159- private static int getFreePort () {
160- ServerSocket serverSocket ;
161- try {
162- serverSocket = new ServerSocket (0 );
163- } catch (IOException e ) {
164- throw new RuntimeException ("Couldn't allocate port" );
165- }
166-
167- assertThat (serverSocket , is (notNullValue ()));
168- assertThat (serverSocket .getLocalPort (), greaterThan (0 ));
169-
170- return serverSocket .getLocalPort ();
171- }
172172}
0 commit comments