Skip to content

Commit 5270448

Browse files
committed
Fix lock manager tests: replace lambda assertions with named methods
Extract lambda bodies in lock manager tests to named private/package methods so that stack-trace assertions target a stable, meaningful method name rather than a compiler-generated lambda identifier (e.g. `lambda$deadlockTest$0`), which changed format in JDK 25. Affected tests: ExclusiveLockManagerTest, ExclusiveReentrantLockManagerTest, AbstractReadWriteLockManagerTest, TestHelper.
1 parent 84a98af commit 5270448

4 files changed

Lines changed: 60 additions & 58 deletions

File tree

core/sail/api/src/test/java/org/eclipse/rdf4j/common/concurrent/locks/AbstractReadWriteLockManagerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void deadlockTestReadWrite() throws InterruptedException {
346346
assertThat(memoryAppender.countEventsForLogger(className)).isEqualTo(1);
347347
memoryAppender.assertContains("is possibly deadlocked waiting on \"_READ\" with id ", Level.WARN);
348348
memoryAppender.assertContains(
349-
"at org.eclipse.rdf4j.common.concurrent.locks.TestHelper.lambda$getStartedDaemonThread", Level.WARN);
349+
"at org.eclipse.rdf4j.common.concurrent.locks.TestHelper.acquireTwoLocks(", Level.WARN);
350350

351351
}
352352

@@ -370,7 +370,7 @@ void deadlockTestWriteRead() throws InterruptedException {
370370
assertThat(memoryAppender.countEventsForLogger(className)).isEqualTo(1);
371371
memoryAppender.assertContains("is possibly deadlocked waiting on \"_WRITE\" with id ", Level.WARN);
372372
memoryAppender.assertContains(
373-
"at org.eclipse.rdf4j.common.concurrent.locks.TestHelper.lambda$getStartedDaemonThread", Level.WARN);
373+
"at org.eclipse.rdf4j.common.concurrent.locks.TestHelper.acquireTwoLocks(", Level.WARN);
374374

375375
}
376376

@@ -394,7 +394,7 @@ void deadlockTestWriteWrite() throws InterruptedException {
394394
assertThat(memoryAppender.countEventsForLogger(className)).isEqualTo(1);
395395
memoryAppender.assertContains("is possibly deadlocked waiting on \"_WRITE\" with id ", Level.WARN);
396396
memoryAppender.assertContains(
397-
"at org.eclipse.rdf4j.common.concurrent.locks.TestHelper.lambda$getStartedDaemonThread", Level.WARN);
397+
"at org.eclipse.rdf4j.common.concurrent.locks.TestHelper.acquireTwoLocks(", Level.WARN);
398398

399399
}
400400

core/sail/api/src/test/java/org/eclipse/rdf4j/common/concurrent/locks/ExclusiveLockManagerTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,7 @@ void deadlockTest() throws InterruptedException {
9191

9292
Thread thread = null;
9393
try {
94-
thread = new Thread(() -> {
95-
Lock lock1 = null;
96-
Lock lock2 = null;
97-
try {
98-
lock1 = lockManagerTracking.getExclusiveLock();
99-
lock2 = lockManagerTracking.getExclusiveLock();
100-
} catch (InterruptedException ignored) {
101-
102-
} finally {
103-
if (lock1 != null) {
104-
lock1.release();
105-
}
106-
if (lock2 != null) {
107-
lock2.release();
108-
}
109-
}
110-
});
111-
94+
thread = new Thread(() -> acquireTwoLocks(lockManagerTracking));
11295
thread.setDaemon(true);
11396
thread.start();
11497

@@ -125,7 +108,7 @@ void deadlockTest() throws InterruptedException {
125108
assertThat(memoryAppender.countEventsForLogger(ExclusiveLockManager.class.getName())).isEqualTo(1);
126109
memoryAppender.assertContains("is possibly deadlocked waiting on \"ExclusiveLockManager\" with id", Level.WARN);
127110
memoryAppender.assertContains(
128-
"at org.eclipse.rdf4j.common.concurrent.locks.ExclusiveLockManagerTest.lambda$deadlockTest$0(ExclusiveLockManagerTest.",
111+
"at org.eclipse.rdf4j.common.concurrent.locks.ExclusiveLockManagerTest.acquireTwoLocks(",
129112
Level.WARN);
130113
}
131114

@@ -167,6 +150,23 @@ void stalledTest() throws InterruptedException {
167150

168151
}
169152

153+
private void acquireTwoLocks(ExclusiveLockManager lockManager) {
154+
Lock lock1 = null;
155+
Lock lock2 = null;
156+
try {
157+
lock1 = lockManager.getExclusiveLock();
158+
lock2 = lockManager.getExclusiveLock();
159+
} catch (InterruptedException ignored) {
160+
} finally {
161+
if (lock1 != null) {
162+
lock1.release();
163+
}
164+
if (lock2 != null) {
165+
lock2.release();
166+
}
167+
}
168+
}
169+
170170
private void lock(ExclusiveLockManager lockManager) throws InterruptedException {
171171
Lock lock = lockManager.getExclusiveLock();
172172
assertTrue(lock.isActive());

core/sail/api/src/test/java/org/eclipse/rdf4j/common/concurrent/locks/ExclusiveReentrantLockManagerTest.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void cleanupUnreleasedLocksWithTracking() throws InterruptedException {
8282

8383
assertThat(memoryAppender.countEventsForLogger(ExclusiveReentrantLockManager.class.getName())).isEqualTo(2);
8484
memoryAppender.assertContains(
85-
"at org.eclipse.rdf4j.common.concurrent.locks.ExclusiveReentrantLockManagerTest.lambda$lock$",
85+
"at org.eclipse.rdf4j.common.concurrent.locks.ExclusiveReentrantLockManagerTest.acquireExclusiveLockAndForget(",
8686
Level.WARN);
8787

8888
}
@@ -92,12 +92,7 @@ void cleanupUnreleasedLocksWithTracking() throws InterruptedException {
9292
void stalledTest() throws InterruptedException {
9393

9494
AtomicReference<Lock> exclusiveLock1 = new AtomicReference<>();
95-
Thread thread = new Thread(() -> {
96-
try {
97-
exclusiveLock1.set(lockManagerTracking.getExclusiveLock());
98-
} catch (InterruptedException ignored) {
99-
}
100-
});
95+
Thread thread = new Thread(() -> acquireExclusiveLock(lockManagerTracking, exclusiveLock1));
10196
thread.start();
10297
thread.join();
10398

@@ -131,18 +126,27 @@ void stalledTest() throws InterruptedException {
131126
memoryAppender.assertContains("is waiting on a possibly stalled lock \"ExclusiveReentrantLockManager\" with id",
132127
Level.INFO);
133128
memoryAppender.assertContains(
134-
"at org.eclipse.rdf4j.common.concurrent.locks.ExclusiveReentrantLockManagerTest.lambda$stalledTest$0(ExclusiveReentrantLockManagerTest.java:",
129+
"at org.eclipse.rdf4j.common.concurrent.locks.ExclusiveReentrantLockManagerTest.acquireExclusiveLock(",
135130
Level.INFO);
136131

137132
}
138133

134+
private void acquireExclusiveLockAndForget(ExclusiveReentrantLockManager lockManager) {
135+
try {
136+
lockManager.getExclusiveLock(); // intentionally not released
137+
} catch (InterruptedException ignored) {
138+
}
139+
}
140+
141+
private void acquireExclusiveLock(ExclusiveReentrantLockManager lockManager, AtomicReference<Lock> ref) {
142+
try {
143+
ref.set(lockManager.getExclusiveLock());
144+
} catch (InterruptedException ignored) {
145+
}
146+
}
147+
139148
private void lock(ExclusiveReentrantLockManager lockManager) throws InterruptedException {
140-
Thread thread = new Thread(() -> {
141-
try {
142-
lockManager.getExclusiveLock();
143-
} catch (InterruptedException ignored) {
144-
}
145-
});
149+
Thread thread = new Thread(() -> acquireExclusiveLockAndForget(lockManager));
146150
thread.start();
147151
thread.join(2000);
148152
assertThat(thread.isAlive()).isFalse();

core/sail/api/src/test/java/org/eclipse/rdf4j/common/concurrent/locks/TestHelper.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,34 +82,32 @@ public static Thread getStartedDaemonThread(Lock.Supplier supplier) throws Inter
8282
public static Thread getStartedDaemonThread(Lock.Supplier supplier1, Lock.Supplier supplier2)
8383
throws InterruptedException {
8484
CountDownLatch countDownLatch = new CountDownLatch(1);
85-
86-
Thread thread = new Thread(() -> {
87-
Lock lock1 = null;
88-
Lock lock2 = null;
89-
try {
90-
countDownLatch.countDown();
91-
lock1 = supplier1.getLock();
92-
lock2 = supplier2.getLock();
93-
94-
} catch (InterruptedException e) {
95-
Thread.currentThread().interrupt();
96-
} finally {
97-
if (lock1 != null) {
98-
lock1.release();
99-
}
100-
if (lock2 != null) {
101-
lock2.release();
102-
}
103-
}
104-
});
105-
85+
Thread thread = new Thread(() -> acquireTwoLocks(countDownLatch, supplier1, supplier2));
10686
thread.setDaemon(true);
10787
thread.start();
10888
countDownLatch.await();
109-
11089
return thread;
11190
}
11291

92+
static void acquireTwoLocks(CountDownLatch latch, Lock.Supplier supplier1, Lock.Supplier supplier2) {
93+
Lock lock1 = null;
94+
Lock lock2 = null;
95+
try {
96+
latch.countDown();
97+
lock1 = supplier1.getLock();
98+
lock2 = supplier2.getLock();
99+
} catch (InterruptedException e) {
100+
Thread.currentThread().interrupt();
101+
} finally {
102+
if (lock1 != null) {
103+
lock1.release();
104+
}
105+
if (lock2 != null) {
106+
lock2.release();
107+
}
108+
}
109+
}
110+
113111
public static Thread getStartedDaemonThread(InterruptibleRunnable runnable) throws InterruptedException {
114112
CountDownLatch countDownLatch = new CountDownLatch(1);
115113
Thread thread = new Thread(() -> {

0 commit comments

Comments
 (0)