Home / Function/ testRetainFromMultipleThreadsThrowsReferenceCountException() — netty Function Reference

testRetainFromMultipleThreadsThrowsReferenceCountException() — netty Function Reference

Architecture documentation for the testRetainFromMultipleThreadsThrowsReferenceCountException() function in AbstractReferenceCountedTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  ccf868c0_a2c7_fe55_6ab0_d9c5dbe5bd8a["testRetainFromMultipleThreadsThrowsReferenceCountException()"]
  7917189b_1868_6962_74c7_fde430107486["AbstractReferenceCountedTest"]
  ccf868c0_a2c7_fe55_6ab0_d9c5dbe5bd8a -->|defined in| 7917189b_1868_6962_74c7_fde430107486
  style ccf868c0_a2c7_fe55_6ab0_d9c5dbe5bd8a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/test/java/io/netty/util/AbstractReferenceCountedTest.java lines 89–133

    @Test
    @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
    public void testRetainFromMultipleThreadsThrowsReferenceCountException() throws Exception {
        int threads = 4;
        Queue<Future<?>> futures = new ArrayDeque<>(threads);
        ExecutorService service = Executors.newFixedThreadPool(threads);
        final AtomicInteger refCountExceptions = new AtomicInteger();

        try {
            for (int i = 0; i < 10000; i++) {
                final AbstractReferenceCounted referenceCounted = newReferenceCounted();
                final CountDownLatch retainLatch = new CountDownLatch(1);
                assertTrue(referenceCounted.release());

                for (int a = 0; a < threads; a++) {
                    final int retainCnt = ThreadLocalRandom.current().nextInt(1, Integer.MAX_VALUE);
                    futures.add(service.submit(() -> {
                        try {
                            retainLatch.await();
                            try {
                                referenceCounted.retain(retainCnt);
                            } catch (IllegalReferenceCountException e) {
                                refCountExceptions.incrementAndGet();
                            }
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                        }
                    }));
                }
                retainLatch.countDown();

                for (;;) {
                    Future<?> f = futures.poll();
                    if (f == null) {
                        break;
                    }
                    f.get();
                }
                assertEquals(4, refCountExceptions.get());
                refCountExceptions.set(0);
            }
        } finally {
            service.shutdown();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testRetainFromMultipleThreadsThrowsReferenceCountException() do?
testRetainFromMultipleThreadsThrowsReferenceCountException() is a function in the netty codebase, defined in common/src/test/java/io/netty/util/AbstractReferenceCountedTest.java.
Where is testRetainFromMultipleThreadsThrowsReferenceCountException() defined?
testRetainFromMultipleThreadsThrowsReferenceCountException() is defined in common/src/test/java/io/netty/util/AbstractReferenceCountedTest.java at line 89.

Analyze Your Own Codebase

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

Try Supermodel Free