-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add register to CleanupReferenceProcessor #6213
Merged
devinrsmith
merged 2 commits into
deephaven:main
from
devinrsmith:cleanup-ref-processor-register
Oct 22, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Util/src/test/java/io/deephaven/util/reference/CleanupReferenceProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
// | ||
package io.deephaven.util.reference; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.function.BiFunction; | ||
|
||
public class CleanupReferenceProcessorTest { | ||
|
||
@Test | ||
public void registerPhantom() throws InterruptedException, TimeoutException { | ||
register(CleanupReferenceProcessor.getDefault()::registerPhantom); | ||
} | ||
|
||
@Test | ||
public void registerWeak() throws InterruptedException, TimeoutException { | ||
register(CleanupReferenceProcessor.getDefault()::registerWeak); | ||
} | ||
|
||
@Ignore("Soft references are harder to test, as they are cleared out at the discretion of the garbage collector based on memory pressure") | ||
@Test | ||
public void registerSoft() throws InterruptedException, TimeoutException { | ||
register(CleanupReferenceProcessor.getDefault()::registerSoft); | ||
} | ||
|
||
private static void register(BiFunction<Object, Runnable, ?> bf) throws InterruptedException, TimeoutException { | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
{ | ||
final Object obj = new Object(); | ||
bf.apply(obj, latch::countDown); | ||
} | ||
for (int i = 0; i < 20; ++i) { | ||
System.gc(); | ||
if (latch.await(100, TimeUnit.MILLISECONDS)) { | ||
break; | ||
} | ||
} | ||
if (latch.getCount() != 0) { | ||
throw new TimeoutException(); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use interface defaulting to avoid this duplication....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there was more complex logic, I would consider it. In this case, I think per-impl is pretty straightforward.