@@ -89,15 +89,11 @@ public class ControlPlaneRule extends TestWatcher {
89
89
private XdsTestControlPlaneService controlPlaneService ;
90
90
private XdsTestLoadReportingService loadReportingService ;
91
91
private XdsNameResolverProvider nameResolverProvider ;
92
- private final int port ;
92
+ private int port ; // Only change from 0 to actual port used in the server.
93
93
94
94
public ControlPlaneRule () {
95
- this (0 );
96
- }
97
-
98
- public ControlPlaneRule (int port ) {
99
95
serverHostName = "test-server" ;
100
- this .port = port ;
96
+ this .port = 0 ;
101
97
}
102
98
103
99
public ControlPlaneRule setServerHostName (String serverHostName ) {
@@ -153,9 +149,9 @@ public Server getServer() {
153
149
* Will shutdown existing server if needed.
154
150
* Then creates a new server in the same way as {@link #starting(Description)} and starts it.
155
151
*/
156
- public void restartTdServer () {
152
+ public void restartXdsServer () {
157
153
158
- if (getServer () != null && !getServer ().isShutdown ()) {
154
+ if (getServer () != null && !getServer ().isTerminated ()) {
159
155
getServer ().shutdownNow ();
160
156
try {
161
157
if (!getServer ().awaitTermination (5 , TimeUnit .SECONDS )) {
@@ -179,6 +175,10 @@ private void createAndStartXdsServer() throws IOException {
179
175
.addService (loadReportingService )
180
176
.build ()
181
177
.start ();
178
+
179
+ if (port == 0 ) {
180
+ port = server .getPort ();
181
+ }
182
182
}
183
183
184
184
/**
0 commit comments