Home / Class/ UnorderedThreadPoolEventExecutorTest Class — netty Architecture

UnorderedThreadPoolEventExecutorTest Class — netty Architecture

Architecture documentation for the UnorderedThreadPoolEventExecutorTest class in UnorderedThreadPoolEventExecutorTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f0665e95_bf5c_2315_7fab_6f3711bb232f["UnorderedThreadPoolEventExecutorTest"]
  74203d94_eede_88eb_6f3b_840361418f22["UnorderedThreadPoolEventExecutorTest.java"]
  f0665e95_bf5c_2315_7fab_6f3711bb232f -->|defined in| 74203d94_eede_88eb_6f3b_840361418f22
  68d15cc2_bf84_e7e4_556a_5522c2e1223a["testNotEndlessExecute()"]
  f0665e95_bf5c_2315_7fab_6f3711bb232f -->|method| 68d15cc2_bf84_e7e4_556a_5522c2e1223a
  c3261673_1851_f4a0_29a2_daa7352b785d["scheduledAtFixedRateMustRunTaskRepeatedly()"]
  f0665e95_bf5c_2315_7fab_6f3711bb232f -->|method| c3261673_1851_f4a0_29a2_daa7352b785d
  865569a0_9bfc_bcbc_f5be_8ff7eebd9b3e["testGetReturnsCorrectValueOnSuccess()"]
  f0665e95_bf5c_2315_7fab_6f3711bb232f -->|method| 865569a0_9bfc_bcbc_f5be_8ff7eebd9b3e
  625267c0_987c_e71b_c1f9_f80e7d95b275["testGetReturnsCorrectValueOnFailure()"]
  f0665e95_bf5c_2315_7fab_6f3711bb232f -->|method| 625267c0_987c_e71b_c1f9_f80e7d95b275
  12025038_6c61_4231_0ba9_4b1e55d95b0e["tasksRunningInUnorderedExecutorAreInEventLoop()"]
  f0665e95_bf5c_2315_7fab_6f3711bb232f -->|method| 12025038_6c61_4231_0ba9_4b1e55d95b0e

Relationship Graph

Source Code

common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java lines 30–141

public class UnorderedThreadPoolEventExecutorTest {

    // See https://github.com/netty/netty/issues/6507
    @Test
    public void testNotEndlessExecute() throws Exception {
        UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1);

        try {
            // Having the first task wait on an exchanger allow us to make sure that the lister on the second task
            // is not added *after* the promise completes. We need to do this to prevent a race where the second task
            // and listener are completed before the DefaultPromise.NotifyListeners task get to run, which means our
            // queue inspection might observe this task after the CountDownLatch opens.
            final Exchanger<Void> exchanger = new Exchanger<Void>();
            final CountDownLatch latch = new CountDownLatch(3);
            Runnable task = new Runnable() {
                @Override
                public void run() {
                    try {
                        exchanger.exchange(null);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    latch.countDown();
                }
            };
            executor.execute(task);
            Future<?> future = executor.submit(new Runnable() {
                @Override
                public void run() {
                    latch.countDown();
                }
            }).addListener((FutureListener<Object>) f -> latch.countDown());
            exchanger.exchange(null);
            latch.await();
            future.syncUninterruptibly();

            // Now just check if the queue stays empty multiple times. This is needed as the submit to execute(...)
            // by DefaultPromise may happen in an async fashion
            for (int i = 0; i < 10000; i++) {
                assertTrue(executor.getQueue().isEmpty());
            }
        } finally {
            executor.shutdownGracefully();
        }
    }

    @Test
    @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
    public void scheduledAtFixedRateMustRunTaskRepeatedly() throws InterruptedException {
        UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1);
        final CountDownLatch latch = new CountDownLatch(3);
        Future<?> future = executor.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                latch.countDown();
            }
        }, 1, 1, TimeUnit.MILLISECONDS);
        try {
            latch.await();
        } finally {
            future.cancel(true);
            executor.shutdownGracefully();
        }
    }

    @Test
    public void testGetReturnsCorrectValueOnSuccess() throws Exception {
        UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1);
        try {
            final String expected = "expected";
            Future<String> f = executor.submit(new Callable<String>() {
                @Override
                public String call() {
                    return expected;
                }
            });

            assertEquals(expected, f.get());
        } finally {
            executor.shutdownGracefully();
        }

Frequently Asked Questions

What is the UnorderedThreadPoolEventExecutorTest class?
UnorderedThreadPoolEventExecutorTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java.
Where is UnorderedThreadPoolEventExecutorTest defined?
UnorderedThreadPoolEventExecutorTest is defined in common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java at line 30.

Analyze Your Own Codebase

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

Try Supermodel Free