Skip to content

Commit

Permalink
Workaround commons-lang incompatible changes in version 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
rpost committed Nov 24, 2023
1 parent 48cc79c commit 737acf9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/main/java/de/cronn/testutils/ThreadLeakCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -125,8 +126,10 @@ private static boolean stackTraceContainsClassName(Thread thread, String classNa
}

private static Map<Long, Thread> getAllLivingThreadNamesById() {
return ThreadUtils.findThreads(Thread::isAlive)
return ThreadUtils.getAllThreads()
.stream()
.filter(Objects::nonNull)
.filter(Thread::isAlive)
.sorted(Comparator.comparingLong(Thread::getId))
.collect(Collectors.toMap(Thread::getId, thread -> thread, (t, t2) -> { throw new IllegalStateException(); }, LinkedHashMap::new ));
}
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/de/cronn/testutils/ThreadLeakCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.assertj.core.api.Assertions.*;

import java.util.List;
import java.util.function.Predicate;

import org.apache.commons.lang3.ThreadUtils;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -87,10 +88,12 @@ void testInvalidUsageInNestedClass() throws Exception {
);
}

private void joinThreads(ThreadUtils.ThreadPredicate criteria) throws InterruptedException {
for (Thread thread : ThreadUtils.findThreads(criteria)) {
thread.interrupt();
thread.join(10_000L);
private void joinThreads(Predicate<Thread> criteria) throws InterruptedException {
for (Thread thread : ThreadUtils.getAllThreads()) {
if (thread != null && criteria.test(thread)) {
thread.interrupt();
thread.join(10_000L);
}
}
}

Expand Down

0 comments on commit 737acf9

Please sign in to comment.