ObjectCleanerTest Class — netty Architecture
Architecture documentation for the ObjectCleanerTest class in ObjectCleanerTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 6ab8958b_bdc7_6dbd_0fac_3c76aea02daf["ObjectCleanerTest"] 392c9b19_5793_b246_a370_bbf8daafd434["ObjectCleanerTest.java"] 6ab8958b_bdc7_6dbd_0fac_3c76aea02daf -->|defined in| 392c9b19_5793_b246_a370_bbf8daafd434 f059c2fd_a36d_abca_c249_ecd542b89464["testCleanup()"] 6ab8958b_bdc7_6dbd_0fac_3c76aea02daf -->|method| f059c2fd_a36d_abca_c249_ecd542b89464 3e50e3be_f721_6ed4_5011_ee5aa675253f["testCleanupContinuesDespiteThrowing()"] 6ab8958b_bdc7_6dbd_0fac_3c76aea02daf -->|method| 3e50e3be_f721_6ed4_5011_ee5aa675253f b05d574c_d27b_6224_1d8d_112652c6fdb7["testCleanerThreadIsDaemon()"] 6ab8958b_bdc7_6dbd_0fac_3c76aea02daf -->|method| b05d574c_d27b_6224_1d8d_112652c6fdb7
Relationship Graph
Source Code
common/src/test/java/io/netty/util/internal/ObjectCleanerTest.java lines 31–142
public class ObjectCleanerTest {
private Thread temporaryThread;
private Object temporaryObject;
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testCleanup() throws Exception {
final AtomicBoolean freeCalled = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1);
temporaryThread = new Thread(new Runnable() {
@Override
public void run() {
try {
latch.await();
} catch (InterruptedException ignore) {
// just ignore
}
}
});
temporaryThread.start();
ObjectCleaner.register(temporaryThread, new Runnable() {
@Override
public void run() {
freeCalled.set(true);
}
});
latch.countDown();
temporaryThread.join();
assertFalse(freeCalled.get());
// Null out the temporary object to ensure it is enqueued for GC.
temporaryThread = null;
while (!freeCalled.get()) {
System.gc();
System.runFinalization();
Thread.sleep(100);
}
}
@Test
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
public void testCleanupContinuesDespiteThrowing() throws InterruptedException {
final AtomicInteger freeCalledCount = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1);
temporaryThread = new Thread(new Runnable() {
@Override
public void run() {
try {
latch.await();
} catch (InterruptedException ignore) {
// just ignore
}
}
});
temporaryThread.start();
temporaryObject = new Object();
ObjectCleaner.register(temporaryThread, new Runnable() {
@Override
public void run() {
freeCalledCount.incrementAndGet();
throw new RuntimeException("expected");
}
});
ObjectCleaner.register(temporaryObject, new Runnable() {
@Override
public void run() {
freeCalledCount.incrementAndGet();
throw new RuntimeException("expected");
}
});
latch.countDown();
temporaryThread.join();
assertEquals(0, freeCalledCount.get());
// Null out the temporary object to ensure it is enqueued for GC.
temporaryThread = null;
temporaryObject = null;
Source
Frequently Asked Questions
What is the ObjectCleanerTest class?
ObjectCleanerTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/internal/ObjectCleanerTest.java.
Where is ObjectCleanerTest defined?
ObjectCleanerTest is defined in common/src/test/java/io/netty/util/internal/ObjectCleanerTest.java at line 31.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free