Skip to content

Commit 2c29a69

Browse files
author
Davide Melfi
committed
revert: move test fixes and JDK matrix to improve-action-speed
ClasspathLoaderTest (JDK 25 split), UnsafeUtilTest (Unsafe.getObjectVolatile rewrite), and the JDK version matrix in the RIC PR workflow are moved to the dmelfi/improve-action-speed branch. This branch keeps only CI/workflow improvements and the JUnit 5.14.3 upgrade.
1 parent 7946ec4 commit 2c29a69

File tree

3 files changed

+38
-67
lines changed

3 files changed

+38
-67
lines changed

.github/workflows/runtime-interface-client_pr.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ jobs:
2121

2222
smoke-test:
2323
runs-on: ubuntu-latest
24-
strategy:
25-
matrix:
26-
java-version: [8, 11, 17, 21, 25]
2724
steps:
2825
- uses: actions/checkout@v5
2926

30-
- name: Set up JDK ${{ matrix.java-version }}
27+
- name: Set up JDK 1.8
3128
uses: actions/setup-java@v4
3229
with:
33-
java-version: ${{ matrix.java-version }}
30+
java-version: 8
3431
distribution: corretto
3532
cache: maven
3633

@@ -46,7 +43,7 @@ jobs:
4643
working-directory: ./aws-lambda-java-runtime-interface-client
4744
run: make pr
4845
env:
49-
IS_JAVA_8: ${{ matrix.java-version == 8 }}
46+
IS_JAVA_8: true
5047

5148
build:
5249
runs-on: ubuntu-latest

aws-lambda-java-runtime-interface-client/src/test/java/com/amazonaws/services/lambda/runtime/api/client/ClasspathLoaderTest.java

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
package com.amazonaws.services.lambda.runtime.api.client;
77

88
import org.junit.jupiter.api.Test;
9-
import org.junit.jupiter.api.condition.DisabledForJreRange;
10-
import org.junit.jupiter.api.condition.EnabledForJreRange;
11-
import org.junit.jupiter.api.condition.JRE;
129
import org.junit.jupiter.api.io.TempDir;
1310
import java.io.File;
1411
import java.io.FileNotFoundException;
1512
import java.io.FileOutputStream;
1613
import java.io.IOException;
1714
import java.nio.file.Path;
15+
import java.util.Collections;
16+
import java.util.Enumeration;
1817
import java.util.jar.JarEntry;
18+
import java.util.jar.JarFile;
1919
import java.util.jar.JarOutputStream;
2020

2121
import static org.junit.jupiter.api.Assertions.*;
@@ -27,38 +27,21 @@ void testLoadAllClassesWithNoClasspath() throws IOException {
2727
String originalClasspath = System.getProperty("java.class.path");
2828
try {
2929
System.clearProperty("java.class.path");
30-
ClasspathLoader.main(new String[] {});
30+
ClasspathLoader.main(new String[]{});
3131
} finally {
3232
if (originalClasspath != null) {
3333
System.setProperty("java.class.path", originalClasspath);
3434
}
3535
}
3636
}
3737

38-
// On JDK 8-24, new File("").exists() returns false → FileNotFoundException.
3938
@Test
40-
@DisabledForJreRange(min = JRE.JAVA_25)
4139
void testLoadAllClassesWithEmptyClasspath() {
4240
String originalClasspath = System.getProperty("java.class.path");
4341
try {
4442
System.setProperty("java.class.path", "");
45-
assertThrows(FileNotFoundException.class, () -> ClasspathLoader.main(new String[] {}));
46-
} finally {
47-
if (originalClasspath != null) {
48-
System.setProperty("java.class.path", originalClasspath);
49-
}
50-
}
51-
}
52-
53-
// On JDK 25+, new File("") resolves to cwd (exists=true, isDirectory=true) →
54-
// skipped with warning, no exception.
55-
@Test
56-
@EnabledForJreRange(min = JRE.JAVA_25)
57-
void testLoadAllClassesWithEmptyClasspathJdk25Plus() throws IOException {
58-
String originalClasspath = System.getProperty("java.class.path");
59-
try {
60-
System.setProperty("java.class.path", "");
61-
ClasspathLoader.main(new String[] {});
43+
assertThrows(FileNotFoundException.class, () ->
44+
ClasspathLoader.main(new String[]{}));
6245
} finally {
6346
if (originalClasspath != null) {
6447
System.setProperty("java.class.path", originalClasspath);
@@ -71,7 +54,8 @@ void testLoadAllClassesWithInvalidPath() {
7154
String originalClasspath = System.getProperty("java.class.path");
7255
try {
7356
System.setProperty("java.class.path", "nonexistent/path");
74-
assertThrows(FileNotFoundException.class, () -> ClasspathLoader.main(new String[] {}));
57+
assertThrows(FileNotFoundException.class, () ->
58+
ClasspathLoader.main(new String[]{}));
7559
} finally {
7660
if (originalClasspath != null) {
7761
System.setProperty("java.class.path", originalClasspath);
@@ -85,7 +69,7 @@ void testLoadAllClassesWithValidJar(@TempDir Path tempDir) throws IOException {
8569
String originalClasspath = System.getProperty("java.class.path");
8670
try {
8771
System.setProperty("java.class.path", jarFile.getAbsolutePath());
88-
ClasspathLoader.main(new String[] {});
72+
ClasspathLoader.main(new String[]{});
8973
} finally {
9074
if (originalClasspath != null) {
9175
System.setProperty("java.class.path", originalClasspath);
@@ -98,7 +82,7 @@ void testLoadAllClassesWithDirectory(@TempDir Path tempDir) throws IOException {
9882
String originalClasspath = System.getProperty("java.class.path");
9983
try {
10084
System.setProperty("java.class.path", tempDir.toString());
101-
ClasspathLoader.main(new String[] {});
85+
ClasspathLoader.main(new String[]{});
10286
} finally {
10387
if (originalClasspath != null) {
10488
System.setProperty("java.class.path", originalClasspath);
@@ -110,14 +94,14 @@ void testLoadAllClassesWithDirectory(@TempDir Path tempDir) throws IOException {
11094
void testLoadAllClassesWithMultipleEntries(@TempDir Path tempDir) throws IOException {
11195
File jarFile1 = createSimpleJar(tempDir, "test1.jar", "TestClass1");
11296
File jarFile2 = createSimpleJar(tempDir, "test2.jar", "TestClass2");
113-
97+
11498
String originalClasspath = System.getProperty("java.class.path");
11599
try {
116-
String newClasspath = jarFile1.getAbsolutePath() +
117-
File.pathSeparator +
118-
jarFile2.getAbsolutePath();
100+
String newClasspath = jarFile1.getAbsolutePath() +
101+
File.pathSeparator +
102+
jarFile2.getAbsolutePath();
119103
System.setProperty("java.class.path", newClasspath);
120-
ClasspathLoader.main(new String[] {});
104+
ClasspathLoader.main(new String[]{});
121105
} finally {
122106
if (originalClasspath != null) {
123107
System.setProperty("java.class.path", originalClasspath);
@@ -128,7 +112,7 @@ void testLoadAllClassesWithMultipleEntries(@TempDir Path tempDir) throws IOExcep
128112
@Test
129113
void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOException {
130114
File jarFile = tempDir.resolve("blocklist-test.jar").toFile();
131-
115+
132116
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile))) {
133117
JarEntry blockedEntry = new JarEntry("META-INF/versions/9/module-info.class");
134118
jos.putNextEntry(blockedEntry);
@@ -144,9 +128,8 @@ void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOExce
144128
String originalClasspath = System.getProperty("java.class.path");
145129
try {
146130
System.setProperty("java.class.path", jarFile.getAbsolutePath());
147-
ClasspathLoader.main(new String[] {});
148-
// The test passes if no exception is thrown and the blocklisted class is
149-
// skipped
131+
ClasspathLoader.main(new String[]{});
132+
// The test passes if no exception is thrown and the blocklisted class is skipped
150133
} finally {
151134
if (originalClasspath != null) {
152135
System.setProperty("java.class.path", originalClasspath);
@@ -156,15 +139,15 @@ void testLoadAllClassesWithBlocklistedClass(@TempDir Path tempDir) throws IOExce
156139

157140
private File createSimpleJar(Path tempDir, String jarName, String className) throws IOException {
158141
File jarFile = tempDir.resolve(jarName).toFile();
159-
142+
160143
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile))) {
161144
// Add a simple non-class file to make it a valid jar
162145
JarEntry entry = new JarEntry("com/test/" + className + ".txt");
163146
jos.putNextEntry(entry);
164147
jos.write("test content".getBytes());
165148
jos.closeEntry();
166149
}
167-
150+
168151
return jarFile;
169152
}
170153
}

aws-lambda-java-runtime-interface-client/src/test/java/com/amazonaws/services/lambda/runtime/api/client/util/UnsafeUtilTest.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
package com.amazonaws.services.lambda.runtime.api.client.util;
77

88
import org.junit.jupiter.api.Test;
9-
import org.junit.jupiter.api.condition.EnabledForJreRange;
10-
import org.junit.jupiter.api.condition.JRE;
119
import java.lang.reflect.Field;
1210
import static org.junit.jupiter.api.Assertions.*;
1311

@@ -21,7 +19,7 @@ void testTheUnsafeIsInitialized() {
2119
@Test
2220
void testThrowException() {
2321
Exception testException = new Exception("Test exception");
24-
22+
2523
try {
2624
UnsafeUtil.throwException(testException);
2725
fail("Should have thrown an exception");
@@ -31,29 +29,22 @@ void testThrowException() {
3129
}
3230
}
3331

34-
// IllegalAccessLogger only exists on JDK 9-16; skipped on JDK 8 (no module
35-
// system) and JDK 17+ (class removed).
36-
@Test
37-
@EnabledForJreRange(min = JRE.JAVA_9, max = JRE.JAVA_16)
38-
void testDisableIllegalAccessWarning() throws Exception {
39-
// We disable the warning log for "jdk.internal.module.IllegalAccessLogger"
40-
UnsafeUtil.disableIllegalAccessWarning();
41-
42-
Class<?> illegalAccessLoggerClass = Class.forName("jdk.internal.module.IllegalAccessLogger");
43-
Field loggerField = illegalAccessLoggerClass.getDeclaredField("logger");
44-
45-
// Now we are getting it back with getObjectVolatile and verify that the logger
46-
// is null. We are not using default reflection because that will throw because
47-
// that field is private, defeating the point of the test.
48-
Object loggerValue = UnsafeUtil.TheUnsafe.getObjectVolatile(
49-
illegalAccessLoggerClass,
50-
UnsafeUtil.TheUnsafe.staticFieldOffset(loggerField));
51-
assertNull(loggerValue);
52-
}
53-
5432
@Test
55-
void testDisableIllegalAccessWarningDoesNotThrow() {
33+
void testDisableIllegalAccessWarning() {
5634
assertDoesNotThrow(() -> UnsafeUtil.disableIllegalAccessWarning());
35+
try {
36+
Class<?> illegalAccessLoggerClass = Class.forName("jdk.internal.module.IllegalAccessLogger");
37+
Field loggerField = illegalAccessLoggerClass.getDeclaredField("logger");
38+
loggerField.setAccessible(true);
39+
Object loggerValue = loggerField.get(null);
40+
assertNull(loggerValue);
41+
} catch (ClassNotFoundException e) {
42+
assertTrue(true);
43+
} catch (NoSuchFieldException e) {
44+
assertTrue(true);
45+
} catch (Exception e) {
46+
fail("Unexpected exception: " + e.getMessage());
47+
}
5748
}
5849

5950
@Test

0 commit comments

Comments
 (0)