Home / Function/ testConcurrentUsage() — netty Function Reference

testConcurrentUsage() — netty Function Reference

Architecture documentation for the testConcurrentUsage() function in ResourceLeakDetectorTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  69f7b95b_cc0c_5af2_9649_3616894c3ecd["testConcurrentUsage()"]
  b9315c3d_21bb_7c58_f151_90c8040eed69["ResourceLeakDetectorTest"]
  69f7b95b_cc0c_5af2_9649_3616894c3ecd -->|defined in| b9315c3d_21bb_7c58_f151_90c8040eed69
  f30b219e_34a3_bcac_382f_66a311dabb20["LeakAwareResource()"]
  69f7b95b_cc0c_5af2_9649_3616894c3ecd -->|calls| f30b219e_34a3_bcac_382f_66a311dabb20
  5361c9f6_00c0_29a2_93b3_ee60aeb8a5d9["close()"]
  69f7b95b_cc0c_5af2_9649_3616894c3ecd -->|calls| 5361c9f6_00c0_29a2_93b3_ee60aeb8a5d9
  bea399c2_041c_146d_4bb8_c499ee67b437["assertNoErrors()"]
  69f7b95b_cc0c_5af2_9649_3616894c3ecd -->|calls| bea399c2_041c_146d_4bb8_c499ee67b437
  style 69f7b95b_cc0c_5af2_9649_3616894c3ecd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java lines 37–106

    @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);
    }

Domain

Subdomains

Frequently Asked Questions

What does testConcurrentUsage() do?
testConcurrentUsage() is a function in the netty codebase, defined in common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java.
Where is testConcurrentUsage() defined?
testConcurrentUsage() is defined in common/src/test/java/io/netty/util/ResourceLeakDetectorTest.java at line 37.
What does testConcurrentUsage() call?
testConcurrentUsage() calls 3 function(s): LeakAwareResource, assertNoErrors, close.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free