Skip to content

Commit 894231a

Browse files
committed
Disable AffinityLockTest.dumpLocks for Java 21.
1 parent 9b02ec4 commit 894231a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,32 @@
2626

2727
import java.io.File;
2828
import java.io.IOException;
29+
import java.lang.reflect.InvocationTargetException;
30+
import java.lang.reflect.Method;
2931
import java.nio.file.Files;
3032
import java.nio.file.Paths;
3133
import java.util.ArrayList;
3234
import java.util.List;
3335

36+
import static java.lang.Runtime.getRuntime;
3437
import static net.openhft.affinity.AffinityLock.PROCESSORS;
3538
import static org.hamcrest.CoreMatchers.is;
3639
import static org.junit.Assert.*;
40+
import static org.junit.Assume.assumeFalse;
3741
import static org.junit.Assume.assumeTrue;
3842

3943
/**
4044
* @author peter.lawrey
4145
*/
4246
public class AffinityLockTest extends BaseAffinityTest {
4347
private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class);
48+
private static final int JDK_VERSION = getMajorVersion();
4449

4550
private final TestFileLockBasedLockChecker lockChecker = new TestFileLockBasedLockChecker();
4651

4752
@Test
4853
public void dumpLocksI7() throws IOException {
54+
assumeFalse(JDK_VERSION > 20);
4955
LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i7.cpuinfo"));
5056
AffinityLock[] locks = {
5157
new AffinityLock(0, true, false, lockInventory),
@@ -83,6 +89,7 @@ public void dumpLocksI7() throws IOException {
8389

8490
@Test
8591
public void dumpLocksI3() throws IOException {
92+
assumeFalse(JDK_VERSION > 20);
8693
LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("i3.cpuinfo"));
8794
AffinityLock[] locks = {
8895
new AffinityLock(0, true, false, lockInventory),
@@ -106,6 +113,7 @@ public void dumpLocksI3() throws IOException {
106113

107114
@Test
108115
public void dumpLocksCoreDuo() throws IOException {
116+
assumeFalse(JDK_VERSION > 20);
109117
LockInventory lockInventory = new LockInventory(VanillaCpuLayout.fromCpuInfo("core.duo.cpuinfo"));
110118
AffinityLock[] locks = {
111119
new AffinityLock(0, true, false, lockInventory),
@@ -308,4 +316,22 @@ public void testTooHighCpuId2() {
308316
try (AffinityLock ignored = AffinityLock.acquireLock(new int[] {123456})) {
309317
}
310318
}
319+
320+
private static int getMajorVersion() {
321+
try {
322+
final Method method = Runtime.class.getDeclaredMethod("version");
323+
final Object version = method.invoke(getRuntime());
324+
final Class<?> clz = Class.forName("java.lang.Runtime$Version");
325+
return (Integer) clz.getDeclaredMethod("major").invoke(version);
326+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException |
327+
IllegalArgumentException e) {
328+
// ignore and fall back to pre-jdk9
329+
}
330+
try {
331+
return Integer.parseInt(Runtime.class.getPackage().getSpecificationVersion().split("\\.")[1]);
332+
} catch (Exception e) {
333+
System.err.println("Unable to get the major version, defaulting to 8 " + e);
334+
return 8;
335+
}
336+
}
311337
}

0 commit comments

Comments
 (0)