Home / Function/ testThreadCacheDestroyed() — netty Function Reference

testThreadCacheDestroyed() — netty Function Reference

Architecture documentation for the testThreadCacheDestroyed() function in PooledByteBufAllocatorTest.java from the netty codebase.

Function java Buffer Telemetry calls 2 called by 2

Entity Profile

Dependency Diagram

graph TD
  158a4e7a_eea0_fa1f_3536_3e2c9a5517e8["testThreadCacheDestroyed()"]
  f8855572_2abf_1bf6_a32b_5cf6d1cf4947["PooledByteBufAllocatorTest"]
  158a4e7a_eea0_fa1f_3536_3e2c9a5517e8 -->|defined in| f8855572_2abf_1bf6_a32b_5cf6d1cf4947
  f1ea159f_a919_6ec8_8569_a71930cb793d["testThreadCacheDestroyedByThreadCleaner()"]
  f1ea159f_a919_6ec8_8569_a71930cb793d -->|calls| 158a4e7a_eea0_fa1f_3536_3e2c9a5517e8
  40cb1ff3_19f2_3ac2_2500_7a229ebf18f4["testThreadCacheDestroyedAfterExitRun()"]
  40cb1ff3_19f2_3ac2_2500_7a229ebf18f4 -->|calls| 158a4e7a_eea0_fa1f_3536_3e2c9a5517e8
  4e681469_9c14_67cb_5890_46b5d4b12dd2["PooledByteBufAllocator()"]
  158a4e7a_eea0_fa1f_3536_3e2c9a5517e8 -->|calls| 4e681469_9c14_67cb_5890_46b5d4b12dd2
  cedeec8b_9344_3cef_05a1_e0c94d65820e["run()"]
  158a4e7a_eea0_fa1f_3536_3e2c9a5517e8 -->|calls| cedeec8b_9344_3cef_05a1_e0c94d65820e
  style 158a4e7a_eea0_fa1f_3536_3e2c9a5517e8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java lines 371–424

    private static void testThreadCacheDestroyed(boolean useRunnable) throws InterruptedException {
        int numArenas = 11;
        final PooledByteBufAllocator allocator =
            new PooledByteBufAllocator(numArenas, numArenas, 8192, 1);

        final AtomicBoolean threadCachesCreated = new AtomicBoolean(true);

        final Runnable task = new Runnable() {
            @Override
            public void run() {
                ByteBuf buf = allocator.newHeapBuffer(1024, 1024);
                for (int i = 0; i < buf.capacity(); i++) {
                    buf.writeByte(0);
                }

                // Make sure that thread caches are actually created,
                // so that down below we are not testing for zero
                // thread caches without any of them ever having been initialized.
                if (allocator.metric().numThreadLocalCaches() == 0) {
                    threadCachesCreated.set(false);
                }

                buf.release();
            }
        };

        for (int i = 0; i < numArenas; i++) {
            final FastThreadLocalThread thread;
            if (useRunnable) {
                thread = new FastThreadLocalThread(task);
                assertTrue(thread.willCleanupFastThreadLocals());
            } else {
                thread = new FastThreadLocalThread() {
                    @Override
                    public void run() {
                        task.run();
                    }
                };
                assertFalse(thread.willCleanupFastThreadLocals());
            }
            thread.start();
            thread.join();
        }

        // Wait for the ThreadDeathWatcher to have destroyed all thread caches
        while (allocator.metric().numThreadLocalCaches() > 0) {
            // Signal we want to have a GC run to ensure we can process our ThreadCleanerReference
            System.gc();
            System.runFinalization();
            LockSupport.parkNanos(MILLISECONDS.toNanos(100));
        }

        assertTrue(threadCachesCreated.get());
    }

Domain

Subdomains

Frequently Asked Questions

What does testThreadCacheDestroyed() do?
testThreadCacheDestroyed() is a function in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java.
Where is testThreadCacheDestroyed() defined?
testThreadCacheDestroyed() is defined in buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java at line 371.
What does testThreadCacheDestroyed() call?
testThreadCacheDestroyed() calls 2 function(s): PooledByteBufAllocator, run.
What calls testThreadCacheDestroyed()?
testThreadCacheDestroyed() is called by 2 function(s): testThreadCacheDestroyedAfterExitRun, testThreadCacheDestroyedByThreadCleaner.

Analyze Your Own Codebase

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

Try Supermodel Free