39
39
import org .junit .jupiter .api .BeforeAll ;
40
40
import org .junit .jupiter .api .BeforeEach ;
41
41
import org .testcontainers .containers .DockerComposeContainer ;
42
+ import org .testcontainers .containers .output .OutputFrame ;
42
43
import org .testcontainers .containers .wait .strategy .Wait ;
43
44
import org .testcontainers .junit .jupiter .Testcontainers ;
44
45
45
46
@ Testcontainers
46
47
abstract class ServingEnvironment {
47
48
static DockerComposeContainer environment ;
48
-
49
+ static int serverPort = getFreePort ();
49
50
ServingServiceGrpc .ServingServiceBlockingStub servingStub ;
50
51
Injector injector ;
51
52
String serverName ;
52
53
ManagedChannel channel ;
53
54
Server server ;
54
55
MutableHandlerRegistry serviceRegistry ;
55
56
56
- static int serverPort = getFreePort ();
57
-
58
57
@ BeforeAll
59
58
static void globalSetup () {
60
59
environment =
61
60
new DockerComposeContainer (
62
61
new File ("src/test/resources/docker-compose/docker-compose-redis-it.yml" ))
63
62
.withExposedService ("redis" , 6379 )
64
63
.withExposedService ("feast" , 8080 )
65
- .waitingFor ("feast" , Wait .forListeningPort ());
64
+ .waitingFor ("feast" , Wait .forListeningPort ())
65
+ .withLogConsumer ("feast" , f -> System .out .print (((OutputFrame ) f ).getUtf8String ()));
66
66
environment .start ();
67
67
}
68
68
@@ -71,6 +71,20 @@ static void globalTeardown() {
71
71
environment .stop ();
72
72
}
73
73
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
+
74
88
@ BeforeEach
75
89
public void envSetUp () throws Exception {
76
90
AbstractModule appPropertiesModule =
@@ -155,18 +169,4 @@ public void envTeardown() throws Exception {
155
169
AbstractModule registryConfig () {
156
170
return null ;
157
171
}
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
- }
172
172
}
0 commit comments