Home / Class/ BoundedInputStreamTest Class — netty Architecture

BoundedInputStreamTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  ab2c52d1_4dad_2c5a_94ad_a0909a9613d1["BoundedInputStreamTest"]
  a24c918d_d2c9_38e2_7fb1_c24dab851939["BoundedInputStreamTest.java"]
  ab2c52d1_4dad_2c5a_94ad_a0909a9613d1 -->|defined in| a24c918d_d2c9_38e2_7fb1_c24dab851939
  a387d0fb_a207_d742_466b_5c9195391c51["testBoundEnforced()"]
  ab2c52d1_4dad_2c5a_94ad_a0909a9613d1 -->|method| a387d0fb_a207_d742_466b_5c9195391c51
  49e5f5f3_c996_3104_1079_b783698c2e29["testBoundEnforced256()"]
  ab2c52d1_4dad_2c5a_94ad_a0909a9613d1 -->|method| 49e5f5f3_c996_3104_1079_b783698c2e29
  2a12bf1e_ff86_8203_f091_bfa155f96791["testBigReadsPermittedIfUnderlyingStreamIsSmall()"]
  ab2c52d1_4dad_2c5a_94ad_a0909a9613d1 -->|method| 2a12bf1e_ff86_8203_f091_bfa155f96791

Relationship Graph

Source Code

common/src/test/java/io/netty/util/internal/BoundedInputStreamTest.java lines 31–77

public class BoundedInputStreamTest {

    @RepeatedTest(50)
    void testBoundEnforced() throws IOException {
        final byte[] bytes = new byte[64];
        ThreadLocalRandom.current().nextBytes(bytes);
        try (BoundedInputStream reader = new BoundedInputStream(new ByteArrayInputStream(bytes), bytes.length - 1)) {
            assertEquals(bytes[0], (byte) reader.read());

            assertThrows(IOException.class, () -> {
                int max = bytes.length;
                do {
                    int result = reader.read(new byte[max], 0, max);
                    assertThat(result).isNotEqualTo(-1);
                    max -= result;
                } while (max > 0);
            });
        }
    }

    @Test
    void testBoundEnforced256() throws IOException {
        final byte[] bytes = new byte[256];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = (byte) i;
        }
        try (BoundedInputStream reader = new BoundedInputStream(new ByteArrayInputStream(bytes), bytes.length - 1)) {
            for (byte expectedByte : bytes) {
                assertEquals(expectedByte, (byte) reader.read());
            }

            assertThrows(IOException.class, reader::read);
            assertThrows(IOException.class, () -> reader.read(new byte[1], 0, 1));
        }
    }

    @RepeatedTest(50)
    void testBigReadsPermittedIfUnderlyingStreamIsSmall() throws IOException {
        final byte[] bytes = new byte[64];
        ThreadLocalRandom.current().nextBytes(bytes);
        try (BoundedInputStream reader = new BoundedInputStream(new ByteArrayInputStream(bytes), 8192)) {
            final byte[] buffer = new byte[10000];
            assertThat(reader.read(buffer, 0, 10000)).isEqualTo(64);
            assertArrayEquals(bytes, Arrays.copyOfRange(buffer, 0, 64));
        }
    }
}

Frequently Asked Questions

What is the BoundedInputStreamTest class?
BoundedInputStreamTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/internal/BoundedInputStreamTest.java.
Where is BoundedInputStreamTest defined?
BoundedInputStreamTest is defined in common/src/test/java/io/netty/util/internal/BoundedInputStreamTest.java at line 31.

Analyze Your Own Codebase

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

Try Supermodel Free