Home / Function/ testDeadlockOnRemove() — netty Function Reference

testDeadlockOnRemove() — netty Function Reference

Architecture documentation for the testDeadlockOnRemove() function in FixedChannelPoolMapDeadlockTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  10e63c8e_806e_9941_8260_15f8ee304e73["testDeadlockOnRemove()"]
  936e1d02_0c7d_5eb4_5c95_f3c3602bf9bc["FixedChannelPoolMapDeadlockTest"]
  10e63c8e_806e_9941_8260_15f8ee304e73 -->|defined in| 936e1d02_0c7d_5eb4_5c95_f3c3602bf9bc
  986a7a39_d83c_2d42_3095_18726001540d["await()"]
  10e63c8e_806e_9941_8260_15f8ee304e73 -->|calls| 986a7a39_d83c_2d42_3095_18726001540d
  ec1d1d7e_3f2c_8b44_83e4_1cb7783a3206["shutdown()"]
  10e63c8e_806e_9941_8260_15f8ee304e73 -->|calls| ec1d1d7e_3f2c_8b44_83e4_1cb7783a3206
  style 10e63c8e_806e_9941_8260_15f8ee304e73 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/pool/FixedChannelPoolMapDeadlockTest.java lines 176–242

    @Test
    public void testDeadlockOnRemove() throws Exception {

        final EventLoop thread1 = new DefaultEventLoop();
        final Bootstrap bootstrap1 = new Bootstrap()
                .channel(LocalChannel.class).group(thread1).localAddress(new LocalAddress("#1"));
        final EventLoop thread2 = new DefaultEventLoop();
        final Bootstrap bootstrap2 = new Bootstrap()
                .channel(LocalChannel.class).group(thread2).localAddress(new LocalAddress("#2"));

        // pool1 runs on thread2, pool2 runs on thread1
        final FixedChannelPool pool1 = new FixedChannelPool(bootstrap2, NOOP_HANDLER, 1);
        final FixedChannelPool pool2 = new FixedChannelPool(bootstrap1, NOOP_HANDLER, 1);

        final AbstractChannelPoolMap<String, FixedChannelPool> channelPoolMap =
                new AbstractChannelPoolMap<String, FixedChannelPool>() {

            @Override
            protected FixedChannelPool newPool(String key) {
                if ("#1".equals(key)) {
                    return pool1;
                } else if ("#2".equals(key)) {
                    return pool2;
                } else {
                    throw new AssertionError("Unexpected key=" + key);
                }
            }
        };

        assertSame(pool1, channelPoolMap.get("#1"));
        assertSame(pool2, channelPoolMap.get("#2"));

        // thread1 tries to remove pool1 which is running on thread2
        // thread2 tries to remove pool2 which is running on thread1

        final CyclicBarrier barrier = new CyclicBarrier(2);

        Future<?> future1 = thread1.submit(new Runnable() {
            @Override
            public void run() {
                await(barrier);
                channelPoolMap.remove("#1");
            }
        });

        Future<?> future2 = thread2.submit(new Runnable() {
            @Override
            public void run() {
                await(barrier);
                channelPoolMap.remove("#2");
            }
        });

        // A blocking close on remove will cause a deadlock here and the test will time out
        try {
            future1.get(1, TimeUnit.SECONDS);
            future2.get(1, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            // Fail the test on timeout to distinguish from other errors
            throw new AssertionError(e);
        } finally {
            pool1.close();
            pool2.close();
            channelPoolMap.close();
            shutdown(thread1, thread2);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testDeadlockOnRemove() do?
testDeadlockOnRemove() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/pool/FixedChannelPoolMapDeadlockTest.java.
Where is testDeadlockOnRemove() defined?
testDeadlockOnRemove() is defined in transport/src/test/java/io/netty/channel/pool/FixedChannelPoolMapDeadlockTest.java at line 176.
What does testDeadlockOnRemove() call?
testDeadlockOnRemove() calls 2 function(s): await, shutdown.

Analyze Your Own Codebase

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

Try Supermodel Free