Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void testBlockAndUnblock() {
blockerInspector.awaitBlockAwaited();
assertTrue(thread.isAlive());

blockerInspector.awaitThreadParked(thread);
recordProcessorBlocker.unblock();
blockerInspector.awaitBlockExited();
}
Expand Down Expand Up @@ -96,6 +97,7 @@ public void testBlockAndUnblock() {
blockerInspector.awaitBlockAwaited();
assertTrue(thread.isAlive());

blockerInspector.awaitThreadParked(thread);
recordProcessorBlocker.unblock();
blockerInspector.awaitBlockExited();
}
Expand Down Expand Up @@ -163,8 +165,8 @@ private static Runnable createRunnableWithInspector(final StandardRecordProcesso

private static class TestThreadInspector {
private static final Duration BUSY_WAIT_MAX_DURATION = Duration.ofSeconds(5);
private boolean blockAwaited = false;
private boolean blockExited = false;
private volatile boolean blockAwaited = false;
private volatile boolean blockExited = false;

public void onBlockAwaited() {
blockAwaited = true;
Expand All @@ -182,6 +184,10 @@ public void awaitBlockExited() {
busyWait(() -> !blockExited);
}

public void awaitThreadParked(final Thread thread) {
busyWait(() -> thread.getState() != Thread.State.WAITING);
}

private void busyWait(final Supplier<Boolean> condition) {
final long maxWait = System.currentTimeMillis() + BUSY_WAIT_MAX_DURATION.toMillis();
do {
Expand Down
Loading