Skip to content

Commit 9d63cbc

Browse files
ludochgae-java-bot
authored andcommitted
Refactor DevAppServer and Runtime tests for parameterized java versions to pick the one used in our github actions to optimize build and test time.
Our actions have 3 jdk used in .github/workflows/maven.yml This change introduces parameterized testing to `DevAppServerTestBase` and `JavaRuntimeViaHttpBase`. Tests will now run across various combinations of Java runtime versions (java17, java21, java25), Jetty versions (9.4, 12.0, 12.1), and Jakarta EE versions (EE6, EE8, EE10, EE11). The test execution is filtered to only run with the Java version matching the current test environment. `JavaRuntimeViaHttpBase` also parameterizes on the use of the HTTP connector. DevAppServerMainTest.java is changed to a single test method to avoid multiple start and stop of the server. We could have used @BeforeClass but seems more complicated for static fields needed. PiperOrigin-RevId: 806707657 Change-Id: Iebb74077ad23644b0677533086a08493b86e3c36
1 parent 22d0d8e commit 9d63cbc

3 files changed

Lines changed: 96 additions & 29 deletions

File tree

e2etests/devappservertests/src/test/java/com/google/appengine/tools/development/DevAppServerMainTest.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void setUpClass() throws IOException, InterruptedException {
4646
}
4747

4848
@Test
49-
public void useMemcache() throws Exception {
49+
public void globaltest() throws Exception {
5050
// App Engine Memcache access.
5151
executeHttpGet(
5252
"/?memcache_loops=10&memcache_size=10",
@@ -68,16 +68,10 @@ public void useMemcache() throws Exception {
6868
+ "Cache hits: 25\n"
6969
+ "Cache misses: 0\n",
7070
RESPONSE_200);
71-
}
7271

73-
@Test
74-
public void useUserApi() throws Exception {
7572
// App Engine User API access.
7673
executeHttpGet("/?user", "Sign in with /_ah/login?continue=%2F\n", RESPONSE_200);
77-
}
7874

79-
@Test
80-
public void useDatastoreAndTaskQueue() throws Exception {
8175
// First, populate Datastore entities
8276
executeHttpGet("/?datastore_entities=3", "Added 3 entities\n", RESPONSE_200);
8377

@@ -90,10 +84,7 @@ public void useDatastoreAndTaskQueue() throws Exception {
9084
// After a while, we should have 10 or more entities.
9185
executeHttpGetWithRetriesContains(
9286
"/?datastore_count", "Found ", RESPONSE_200, NUMBER_OF_RETRIES);
93-
}
9487

95-
@Test
96-
public void localAdminConsoleWorks() throws Exception {
9788
HttpGet get =
9889
new HttpGet(
9990
String.format(

e2etests/devappservertests/src/test/java/com/google/appengine/tools/development/DevAppServerTestBase.java

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package com.google.appengine.tools.development;
1717

1818
import static com.google.common.base.StandardSystemProperty.JAVA_HOME;
19+
import static com.google.common.base.StandardSystemProperty.JAVA_VERSION;
20+
import static com.google.common.collect.ImmutableList.toImmutableList;
1921
import static com.google.common.truth.Truth.assertThat;
2022
import static java.nio.charset.StandardCharsets.UTF_8;
2123

@@ -56,18 +58,54 @@ public abstract class DevAppServerTestBase {
5658

5759
@Parameterized.Parameters
5860
public static List<Object[]> version() {
59-
return Arrays.asList(
60-
new Object[][] {
61-
{"java17", "9.4", "EE6"},
62-
{"java17", "12.0", "EE8"},
63-
{"java17", "12.0", "EE10"},
64-
{"java17", "12.1", "EE11"},
65-
{"java21", "12.0", "EE8"},
66-
{"java21", "12.0", "EE10"},
67-
{"java21", "12.1", "EE11"},
68-
{"java25", "12.1", "EE8"},
69-
{"java25", "12.1", "EE11"}
70-
});
61+
List<Object[]> allVersions =
62+
Arrays.asList(
63+
new Object[][] {
64+
{"java17", "9.4", "EE6"},
65+
{"java17", "12.0", "EE8"},
66+
{"java17", "12.0", "EE10"},
67+
{"java17", "12.1", "EE11"},
68+
{"java21", "12.0", "EE8"},
69+
{"java21", "12.0", "EE10"},
70+
{"java21", "12.1", "EE11"},
71+
{"java25", "12.1", "EE8"},
72+
{"java25", "12.1", "EE11"}
73+
});
74+
String version = JAVA_VERSION.value();
75+
String majorVersion;
76+
// Major version parsing in java.version property can be "1.8.0_201" for java8, "11.0.17" for
77+
// java11+, or "25-ea+35" for early access versions.
78+
if (version.startsWith("1.")) {
79+
majorVersion = version.substring(2, 3);
80+
} else {
81+
int dash = version.indexOf("-");
82+
if (dash != -1) {
83+
majorVersion = version.substring(0, dash);
84+
} else {
85+
int dot = version.indexOf(".");
86+
if (dot != -1) {
87+
majorVersion = version.substring(0, dot);
88+
} else {
89+
majorVersion = version;
90+
}
91+
}
92+
}
93+
// We only run the tests for the current JDK version.
94+
// So we filter the list of versions based on the current `java.version` property.
95+
// We bucket versions into 17, 21, or 25.
96+
int numVersion = Integer.parseInt(majorVersion);
97+
if ((numVersion > 21) && (numVersion < 25)) {
98+
numVersion = 21;
99+
} else if ((numVersion > 25)) {
100+
numVersion = 25;
101+
} else if ((numVersion < 21)) {
102+
numVersion = 17;
103+
}
104+
String javaVersionForTest = "java" + numVersion;
105+
System.out.println("javaVersionForTest " + javaVersionForTest);
106+
return allVersions.stream()
107+
.filter(v -> v[0].toString().equals(javaVersionForTest))
108+
.collect(toImmutableList());
71109
}
72110

73111
public DevAppServerTestBase(String runtimeVersion, String jettyVersion, String jakartaVersion) {
@@ -268,5 +306,4 @@ public void run() {
268306
}
269307
}
270308
}
271-
272309
}

runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/JavaRuntimeViaHttpBase.java

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static com.google.common.base.StandardSystemProperty.FILE_SEPARATOR;
1919
import static com.google.common.base.StandardSystemProperty.JAVA_HOME;
20+
import static com.google.common.base.StandardSystemProperty.JAVA_VERSION;
21+
import static com.google.common.collect.ImmutableList.toImmutableList;
2022
import static com.google.common.collect.ImmutableSet.toImmutableSet;
2123
import static com.google.common.truth.Truth.assertThat;
2224
import static com.google.common.truth.Truth.assertWithMessage;
@@ -108,9 +110,10 @@ public interface ApiServerFactory<ApiServerT extends Closeable> {
108110
* 4. useHttpConnector: true or false
109111
*/
110112
public static List<Object[]> allVersions() {
111-
return Arrays.asList(
112-
new Object[][] {
113-
{"java17", "9.4", "EE6", true},
113+
List<Object[]> allVersions =
114+
Arrays.asList(
115+
new Object[][] {
116+
{"java17", "9.4", "EE6", true},
114117
{"java17", "12.0", "EE8", true},
115118
{"java17", "12.0", "EE10", true},
116119
{"java17", "12.1", "EE11", true},
@@ -133,7 +136,43 @@ public static List<Object[]> allVersions() {
133136
// A warning should be logged, but the runtime should behave identically to EE11.
134137
{"java17", "12.1", "EE10", true},
135138
{"java21", "12.1", "EE10", true},
136-
});
139+
});
140+
String version = JAVA_VERSION.value();
141+
String majorVersion;
142+
// Major version parsing in java.version property can be "1.8.0_201" for java8, "11.0.17" for
143+
// java11+, or "25-ea+35" for early access versions.
144+
if (version.startsWith("1.")) {
145+
majorVersion = version.substring(2, 3);
146+
} else {
147+
int dash = version.indexOf("-");
148+
if (dash != -1) {
149+
majorVersion = version.substring(0, dash);
150+
} else {
151+
int dot = version.indexOf(".");
152+
if (dot != -1) {
153+
majorVersion = version.substring(0, dot);
154+
} else {
155+
majorVersion = version;
156+
}
157+
}
158+
}
159+
// We only run the tests for the current JDK version.
160+
// So we filter the list of versions based on the current `java.version` property.
161+
// We bucket versions into 17, 21, or 25.
162+
int numVersion = Integer.parseInt(majorVersion);
163+
if ((numVersion > 21) && (numVersion < 25)) {
164+
numVersion = 21;
165+
} else if ((numVersion > 25)) {
166+
numVersion = 25;
167+
} else if ((numVersion < 21)) {
168+
numVersion = 17;
169+
}
170+
String javaVersionForTest = "java" + numVersion;
171+
System.out.println("javaVersionForTest " + javaVersionForTest);
172+
173+
return allVersions.stream()
174+
.filter(v -> v[0].toString().equals(javaVersionForTest))
175+
.collect(toImmutableList());
137176
}
138177

139178
@Before
@@ -519,8 +558,8 @@ public void run() {
519558
System.out.println(echoPrefix + line);
520559
outputQueue.add(line);
521560
}
522-
} catch (IOException e) {
523-
throw new RuntimeException(e);
561+
} catch (IOException ignored) {
562+
// ignored, spurious log when we kill the process
524563
}
525564
}
526565

0 commit comments

Comments
 (0)