Home / Function/ testLateListenerIsOrderedCorrectly() — netty Function Reference

testLateListenerIsOrderedCorrectly() — netty Function Reference

Architecture documentation for the testLateListenerIsOrderedCorrectly() function in DefaultPromiseTest.java from the netty codebase.

Function java Buffer Search calls 4 called by 2

Entity Profile

Dependency Diagram

graph TD
  a66b597f_459e_5427_d392_ad3ba06bd7e9["testLateListenerIsOrderedCorrectly()"]
  18d135a2_101c_bae7_e68f_dd4660e1fb75["DefaultPromiseTest"]
  a66b597f_459e_5427_d392_ad3ba06bd7e9 -->|defined in| 18d135a2_101c_bae7_e68f_dd4660e1fb75
  78e11c09_d894_34ba_bf5e_986910bef06e["testLateListenerIsOrderedCorrectlySuccess()"]
  78e11c09_d894_34ba_bf5e_986910bef06e -->|calls| a66b597f_459e_5427_d392_ad3ba06bd7e9
  03f6bfb0_72dc_8e85_ff36_5d856fe88780["testLateListenerIsOrderedCorrectlyFailure()"]
  03f6bfb0_72dc_8e85_ff36_5d856fe88780 -->|calls| a66b597f_459e_5427_d392_ad3ba06bd7e9
  7ea2f073_8f06_492d_3ce0_3651a2c14c01["TestEventExecutor()"]
  a66b597f_459e_5427_d392_ad3ba06bd7e9 -->|calls| 7ea2f073_8f06_492d_3ce0_3651a2c14c01
  8a5571f5_2006_3c17_8a8a_593a884241a7["execute()"]
  a66b597f_459e_5427_d392_ad3ba06bd7e9 -->|calls| 8a5571f5_2006_3c17_8a8a_593a884241a7
  91d7c04c_78df_5079_c536_a87d3e68b6fb["run()"]
  a66b597f_459e_5427_d392_ad3ba06bd7e9 -->|calls| 91d7c04c_78df_5079_c536_a87d3e68b6fb
  817c8cdd_038c_e049_c910_fd52454e0e8d["shutdownGracefully()"]
  a66b597f_459e_5427_d392_ad3ba06bd7e9 -->|calls| 817c8cdd_038c_e049_c910_fd52454e0e8d
  style a66b597f_459e_5427_d392_ad3ba06bd7e9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java lines 486–540

    private static void testLateListenerIsOrderedCorrectly(Throwable cause) throws InterruptedException {
        final EventExecutor executor = new TestEventExecutor();
        try {
            final AtomicInteger state = new AtomicInteger();
            final CountDownLatch latch1 = new CountDownLatch(1);
            final CountDownLatch latch2 = new CountDownLatch(2);
            final Promise<Void> promise = new DefaultPromise<Void>(executor);

            // Add a listener before completion so "lateListener" is used next time we add a listener.
            promise.addListener((FutureListener<Void>) future -> assertTrue(state.compareAndSet(0, 1)));

            // Simulate write operation completing, which will execute listeners in another thread.
            if (cause == null) {
                promise.setSuccess(null);
            } else {
                promise.setFailure(cause);
            }

            // Add a "late listener"
            promise.addListener((FutureListener<Void>) future -> {
                assertTrue(state.compareAndSet(1, 2));
                latch1.countDown();
            });

            // Wait for the listeners and late listeners to be completed.
            latch1.await();
            assertEquals(2, state.get());

            // This is the important listener. A late listener that is added after all late listeners
            // have completed, and needs to update state before a read operation (on the same executor).
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    promise.addListener((FutureListener<Void>) future -> {
                        assertTrue(state.compareAndSet(2, 3));
                        latch2.countDown();
                    });
                }
            });

            // Simulate a read operation being queued up in the executor.
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    // This is the key, we depend upon the state being set in the next listener.
                    assertEquals(3, state.get());
                    latch2.countDown();
                }
            });

            latch2.await();
        } finally {
            executor.shutdownGracefully(0, 0, TimeUnit.SECONDS).sync();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testLateListenerIsOrderedCorrectly() do?
testLateListenerIsOrderedCorrectly() is a function in the netty codebase, defined in common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java.
Where is testLateListenerIsOrderedCorrectly() defined?
testLateListenerIsOrderedCorrectly() is defined in common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java at line 486.
What does testLateListenerIsOrderedCorrectly() call?
testLateListenerIsOrderedCorrectly() calls 4 function(s): TestEventExecutor, execute, run, shutdownGracefully.
What calls testLateListenerIsOrderedCorrectly()?
testLateListenerIsOrderedCorrectly() is called by 2 function(s): testLateListenerIsOrderedCorrectlyFailure, testLateListenerIsOrderedCorrectlySuccess.

Analyze Your Own Codebase

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

Try Supermodel Free