ResourceLeakDetectorTest Class — netty Architecture
Architecture documentation for the ResourceLeakDetectorTest class in ResourceLeakDetectorTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b9315c3d_21bb_7c58_f151_90c8040eed69["ResourceLeakDetectorTest"] 2fccec07_7249_763a_4cb2_2f948c47b346["ResourceLeakDetectorTest.java"] b9315c3d_21bb_7c58_f151_90c8040eed69 -->|defined in| 2fccec07_7249_763a_4cb2_2f948c47b346 69f7b95b_cc0c_5af2_9649_3616894c3ecd["testConcurrentUsage()"] b9315c3d_21bb_7c58_f151_90c8040eed69 -->|method| 69f7b95b_cc0c_5af2_9649_3616894c3ecd 40eac971_57ce_a823_9aa4_d286a3352324["testLeakSetupHints()"] b9315c3d_21bb_7c58_f151_90c8040eed69 -->|method| 40eac971_57ce_a823_9aa4_d286a3352324 cd45a9fe_3d5b_c674_1444_9b2369e80678["testLeakBrokenHint()"] b9315c3d_21bb_7c58_f151_90c8040eed69 -->|method| cd45a9fe_3d5b_c674_1444_9b2369e80678 9e543dfe_5122_4300_2978_1c4fe82e51f6["leakResource()"] b9315c3d_21bb_7c58_f151_90c8040eed69 -->|method| 9e543dfe_5122_4300_2978_1c4fe82e51f6 bea399c2_041c_146d_4bb8_c499ee67b437["assertNoErrors()"] b9315c3d_21bb_7c58_f151_90c8040eed69 -->|method| bea399c2_041c_146d_4bb8_c499ee67b437
Relationship Graph
Source Code
common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java lines 33–305
public class ResourceLeakDetectorTest {
@SuppressWarnings("unused")
private static volatile int sink;
@Test
@Timeout(value = 60000, unit = TimeUnit.MILLISECONDS)
public void testConcurrentUsage() throws Throwable {
final AtomicBoolean finished = new AtomicBoolean();
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
// With 50 threads issue #6087 is reproducible on every run.
Thread[] threads = new Thread[50];
final CyclicBarrier barrier = new CyclicBarrier(threads.length);
for (int i = 0; i < threads.length; i++) {
Thread t = new Thread(new Runnable() {
final Queue<LeakAwareResource> resources = new ArrayDeque<LeakAwareResource>(100);
@Override
public void run() {
try {
barrier.await();
// Run 10000 times or until the test is marked as finished.
for (int b = 0; b < 1000 && !finished.get(); b++) {
// Allocate 100 LeakAwareResource per run and close them after it.
for (int a = 0; a < 100; a++) {
DefaultResource resource = new DefaultResource();
ResourceLeakTracker<Resource> leak = DefaultResource.detector.track(resource);
LeakAwareResource leakAwareResource = new LeakAwareResource(resource, leak);
resources.add(leakAwareResource);
}
if (closeResources(true)) {
finished.set(true);
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Throwable e) {
error.compareAndSet(null, e);
} finally {
// Just close all resource now without assert it to eliminate more reports.
closeResources(false);
}
}
private boolean closeResources(boolean checkClosed) {
for (;;) {
LeakAwareResource r = resources.poll();
if (r == null) {
return false;
}
boolean closed = r.close();
if (checkClosed && !closed) {
error.compareAndSet(null,
new AssertionError("ResourceLeak.close() returned 'false' but expected 'true'"));
return true;
}
}
}
});
threads[i] = t;
t.start();
}
// Just wait until all threads are done.
for (Thread t: threads) {
t.join();
}
// Check if we had any leak reports in the ResourceLeakDetector itself
DefaultResource.detector.assertNoErrors();
assertNoErrors(error);
}
@Timeout(10)
@Test
public void testLeakSetupHints() throws Throwable {
DefaultResource.detectorWithSetupHint.initialise();
leakResource();
Source
Frequently Asked Questions
What is the ResourceLeakDetectorTest class?
ResourceLeakDetectorTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java.
Where is ResourceLeakDetectorTest defined?
ResourceLeakDetectorTest is defined in common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java at line 33.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free