@@ -48,6 +48,7 @@ public abstract class DevAppServerTestBase {
4848 int jettyPort ;
4949 private Process runtimeProc ;
5050 private CountDownLatch serverStarted ;
51+ protected final List <String > serverLogs = java .util .Collections .synchronizedList (new ArrayList <>());
5152
5253 static final int NUMBER_OF_RETRIES = 5 ;
5354
@@ -177,6 +178,7 @@ public void setUpClass(File appDir) throws IOException, InterruptedException {
177178 runtimeArgs .add ("-Dappengine.use.EE10=" + System .getProperty ("appengine.use.EE10" ));
178179 runtimeArgs .add ("-Dappengine.use.EE11=" + System .getProperty ("appengine.use.EE11" ));
179180 runtimeArgs .add ("-Dappengine.use.jetty121=" + System .getProperty ("appengine.use.jetty121" ));
181+ runtimeArgs .addAll (getExtraJvmArgs ());
180182 runtimeArgs .add ("-cp" );
181183 runtimeArgs .add (TOOLS_JAR );
182184 runtimeArgs .add ("com.google.appengine.tools.development.DevAppServerMain" );
@@ -185,10 +187,19 @@ public void setUpClass(File appDir) throws IOException, InterruptedException {
185187 runtimeArgs .add ("--allow_remote_shutdown" ); // Keep as used in Maven plugin
186188 runtimeArgs .add ("--disable_update_check" ); // Keep, as used in Maven plugin
187189
190+ runtimeArgs .addAll (getExtraAppArgs ());
188191 runtimeArgs .add (appDir .toString ());
189192 createRuntime (ImmutableList .copyOf (runtimeArgs ), ImmutableMap .of (), jettyPort );
190193 }
191194
195+ protected List <String > getExtraJvmArgs () {
196+ return ImmutableList .of ();
197+ }
198+
199+ protected List <String > getExtraAppArgs () {
200+ return ImmutableList .of ();
201+ }
202+
192203 void createRuntime (
193204 ImmutableList <String > runtimeArgs ,
194205 ImmutableMap <String , String > extraEnvironmentEntries ,
@@ -221,8 +232,8 @@ private Process launchRuntime(
221232 pb .environment ().putAll (extraEnvironmentEntries );
222233 Process process = pb .start ();
223234
224- OutputPump outPump = new OutputPump (process .getInputStream (), serverStarted );
225- OutputPump errPump = new OutputPump (process .getErrorStream (), serverStarted );
235+ OutputPump outPump = new OutputPump (process .getInputStream (), serverStarted , serverLogs );
236+ OutputPump errPump = new OutputPump (process .getErrorStream (), serverStarted , serverLogs );
226237 new Thread (outPump ).start ();
227238 new Thread (errPump ).start ();
228239 if (!serverStarted .await (120 , TimeUnit .SECONDS )) {
@@ -284,12 +295,28 @@ void executeHttpGetWithRetriesContains(
284295 assertThat (retCode ).isEqualTo (expectedReturnCode );
285296 }
286297
298+ protected boolean awaitLogContains (String expected , int timeoutSeconds ) throws InterruptedException {
299+ for (int i = 0 ; i < timeoutSeconds * 10 ; i ++) {
300+ synchronized (serverLogs ) {
301+ for (String logLine : serverLogs ) {
302+ if (logLine .contains (expected )) {
303+ return true ;
304+ }
305+ }
306+ }
307+ Thread .sleep (100 );
308+ }
309+ return false ;
310+ }
311+
287312 private static class OutputPump implements Runnable {
288313 private final BufferedReader stream ;
289314 private final CountDownLatch serverStarted ;
315+ private final List <String > serverLogs ;
290316
291- public OutputPump (InputStream instream , CountDownLatch serverStarted ) {
317+ public OutputPump (InputStream instream , CountDownLatch serverStarted , List < String > serverLogs ) {
292318 this .serverStarted = serverStarted ;
319+ this .serverLogs = serverLogs ;
293320 this .stream = new BufferedReader (new InputStreamReader (instream , UTF_8 ));
294321 }
295322
@@ -299,6 +326,7 @@ public void run() {
299326 try {
300327 while ((line = stream .readLine ()) != null ) {
301328 System .out .println (line );
329+ serverLogs .add (line );
302330 if (line .contains ("INFO: Dev App Server is now running" )) {
303331 serverStarted .countDown ();
304332 }
0 commit comments