Home / Class/ AsciiStringMemoryTest Class — netty Architecture

AsciiStringMemoryTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15["AsciiStringMemoryTest"]
  8bdc737c_c854_63f1_1c46_ca29e54cf1aa["AsciiStringMemoryTest.java"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|defined in| 8bdc737c_c854_63f1_1c46_ca29e54cf1aa
  d19e6ffe_0fb1_6732_bd9f_bf3b911018bf["setup()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| d19e6ffe_0fb1_6732_bd9f_bf3b911018bf
  2aa6a2c3_2374_354d_80d9_a34286825e98["testSharedMemory()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| 2aa6a2c3_2374_354d_80d9_a34286825e98
  c5c30946_e8d9_7ad2_5e9e_3cec1a93aec7["testNotSharedMemory()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| c5c30946_e8d9_7ad2_5e9e_3cec1a93aec7
  499234af_8b4a_a091_9568_23f241f88891["forEachTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| 499234af_8b4a_a091_9568_23f241f88891
  dbe9649f_fafa_cd7f_6ee6_edac359c52a2["forEachWithIndexEndTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| dbe9649f_fafa_cd7f_6ee6_edac359c52a2
  d85946fc_62a8_f639_e708_5f0cefbd26da["forEachWithIndexBeginTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| d85946fc_62a8_f639_e708_5f0cefbd26da
  159c8da0_bc17_5c1a_e6c3_5e5082333e81["forEachDescTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| 159c8da0_bc17_5c1a_e6c3_5e5082333e81
  c3b032e6_ed2a_afda_9e4e_73df2f6f7549["forEachDescWithIndexEndTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| c3b032e6_ed2a_afda_9e4e_73df2f6f7549
  07a40d53_4294_6ee0_4470_173c5b63f4f5["forEachDescWithIndexBeginTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| 07a40d53_4294_6ee0_4470_173c5b63f4f5
  50d838f1_bf00_75cc_2c84_dbc74de24cd8["subSequenceTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| 50d838f1_bf00_75cc_2c84_dbc74de24cd8
  4a770ab6_d909_c080_ca22_5ca34dcfeb51["copyTest()"]
  cfaf93a3_50a8_27c3_9fa0_2c606fea9e15 -->|method| 4a770ab6_d909_c080_ca22_5ca34dcfeb51

Relationship Graph

Source Code

common/src/test/java/io/netty/util/AsciiStringMemoryTest.java lines 31–173

public class AsciiStringMemoryTest {
    private byte[] a;
    private byte[] b;
    private int aOffset = 22;
    private int bOffset = 53;
    private int length = 100;
    private AsciiString aAsciiString;
    private AsciiString bAsciiString;
    private final Random r = new Random();

    @BeforeEach
    public void setup() {
        a = new byte[128];
        b = new byte[256];
        r.nextBytes(a);
        r.nextBytes(b);
        aOffset = 22;
        bOffset = 53;
        length = 100;
        System.arraycopy(a, aOffset, b, bOffset, length);
        aAsciiString = new AsciiString(a, aOffset, length, false);
        bAsciiString = new AsciiString(b, bOffset, length, false);
    }

    @Test
    public void testSharedMemory() {
        ++a[aOffset];
        AsciiString aAsciiString1 = new AsciiString(a, aOffset, length, true);
        AsciiString aAsciiString2 = new AsciiString(a, aOffset, length, false);
        assertEquals(aAsciiString, aAsciiString1);
        assertEquals(aAsciiString, aAsciiString2);
        for (int i = aOffset; i < length; ++i) {
            assertEquals(a[i], aAsciiString.byteAt(i - aOffset));
        }
    }

    @Test
    public void testNotSharedMemory() {
        AsciiString aAsciiString1 = new AsciiString(a, aOffset, length, true);
        ++a[aOffset];
        assertNotEquals(aAsciiString, aAsciiString1);
        int i = aOffset;
        assertNotEquals(a[i], aAsciiString1.byteAt(i - aOffset));
        ++i;
        for (; i < length; ++i) {
            assertEquals(a[i], aAsciiString1.byteAt(i - aOffset));
        }
    }

    @Test
    public void forEachTest() throws Exception {
        final AtomicReference<Integer> aCount = new AtomicReference<Integer>(0);
        final AtomicReference<Integer> bCount = new AtomicReference<Integer>(0);
        aAsciiString.forEachByte(new ByteProcessor() {
            int i;
            @Override
            public boolean process(byte value) {
                assertEquals(value, bAsciiString.byteAt(i++), "failed at index: " + i);
                aCount.set(aCount.get() + 1);
                return true;
            }
        });
        bAsciiString.forEachByte(new ByteProcessor() {
            int i;
            @Override
            public boolean process(byte value) {
                assertEquals(value, aAsciiString.byteAt(i++), "failed at index: " + i);
                bCount.set(bCount.get() + 1);
                return true;
            }
        });
        assertEquals(aAsciiString.length(), aCount.get().intValue());
        assertEquals(bAsciiString.length(), bCount.get().intValue());
    }

    @Test
    public void forEachWithIndexEndTest() throws Exception {
        assertNotEquals(-1, aAsciiString.forEachByte(aAsciiString.length() - 1,
                1, new IndexOfProcessor(aAsciiString.byteAt(aAsciiString.length() - 1))));
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free