Home / Function/ testKeepStateConsistentOnError() — netty Function Reference

testKeepStateConsistentOnError() — netty Function Reference

Architecture documentation for the testKeepStateConsistentOnError() function in AbstractCoalescingBufferQueueTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  e8f78f2e_4b4a_c73b_413e_84c55f93213f["testKeepStateConsistentOnError()"]
  04c5cf5a_e41c_5ef0_e696_3df84d28c281["AbstractCoalescingBufferQueueTest"]
  e8f78f2e_4b4a_c73b_413e_84c55f93213f -->|defined in| 04c5cf5a_e41c_5ef0_e696_3df84d28c281
  style e8f78f2e_4b4a_c73b_413e_84c55f93213f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/AbstractCoalescingBufferQueueTest.java lines 93–153

    @Test
    public void testKeepStateConsistentOnError() {
        final IllegalReferenceCountException exception = new IllegalReferenceCountException();
        final EmbeddedChannel channel = new EmbeddedChannel();
        final AbstractCoalescingBufferQueue queue = new AbstractCoalescingBufferQueue(channel, 128) {
            @Override
            protected ByteBuf compose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) {
                // Simulate throwing an IllegalReferenceCountException.
                throw exception;
            }

            @Override
            protected ByteBuf composeFirst(ByteBufAllocator allocator, ByteBuf first, int bufferSize) {
                // Simulate throwing an IllegalReferenceCountException.
                throw exception;
            }

            @Override
            protected ByteBuf removeEmptyValue() {
                return Unpooled.EMPTY_BUFFER;
            }
        };

        ChannelPromise promise = channel.newPromise();
        ByteBuf buffer = Unpooled.buffer().writeLong(0);
        queue.add(buffer, promise);

        ChannelPromise promise2 = channel.newPromise();
        ByteBuf buffer2 = Unpooled.buffer().writeLong(0);
        queue.add(buffer2, promise2);

        // Size should be 4 as its 2 buffers and 2 listeners.
        assertEquals(4, queue.size());
        assertEquals(16, queue.readableBytes());

        assertThrows(IllegalStateException.class, new Executable() {
            @Override
            public void execute() throws Throwable {
                queue.remove(channel.alloc(), 128,  channel.newPromise());
            }
        });

        // This should result in have the first buf and first listener removed from the queue.
        assertEquals(2, queue.size());
        assertEquals(8, queue.readableBytes());
        assertSame(exception, promise.cause());
        assertEquals(0, buffer.refCnt());

        assertFalse(promise2.isDone());
        assertEquals(1, buffer2.refCnt());
        ByteBuf removed = queue.remove(channel.alloc(), 128, channel.newPromise());
        assertEquals(8, removed.readableBytes());
        removed.release();

        assertTrue(queue.isEmpty());
        assertEquals(0, queue.size());
        assertEquals(0, queue.readableBytes());
        ByteBuf removed2 = queue.remove(channel.alloc(), 128, channel.newPromise());
        assertEquals(0, removed2.readableBytes());
        removed2.release();
    }

Domain

Subdomains

Frequently Asked Questions

What does testKeepStateConsistentOnError() do?
testKeepStateConsistentOnError() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/AbstractCoalescingBufferQueueTest.java.
Where is testKeepStateConsistentOnError() defined?
testKeepStateConsistentOnError() is defined in transport/src/test/java/io/netty/channel/AbstractCoalescingBufferQueueTest.java at line 93.

Analyze Your Own Codebase

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

Try Supermodel Free