Java Code Examples for org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#writerIndex()

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#writerIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void comparableInterfaceNotViolated() {
    assumeFalse(buffer.isReadOnly());
    buffer.writerIndex(buffer.readerIndex());
    assumeTrue(buffer.writableBytes() >= 4);

    buffer.writeLong(0);
    ByteBuf buffer2 = newBuffer(CAPACITY);
    assumeFalse(buffer2.isReadOnly());
    buffer2.writerIndex(buffer2.readerIndex());
    // Write an unsigned integer that will cause buffer.getUnsignedInt() - buffer2.getUnsignedInt() to underflow the
    // int type and wrap around on the negative side.
    buffer2.writeLong(0xF0000000L);
    assertTrue(buffer.compareTo(buffer2) < 0);
    assertTrue(buffer2.compareTo(buffer) > 0);
    buffer2.release();
}
 
Example 2
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void comparableInterfaceNotViolated() {
    assumeFalse(buffer.isReadOnly());
    buffer.writerIndex(buffer.readerIndex());
    assumeTrue(buffer.writableBytes() >= 4);

    buffer.writeLong(0);
    ByteBuf buffer2 = newBuffer(CAPACITY);
    assumeFalse(buffer2.isReadOnly());
    buffer2.writerIndex(buffer2.readerIndex());
    // Write an unsigned integer that will cause buffer.getUnsignedInt() - buffer2.getUnsignedInt() to underflow the
    // int type and wrap around on the negative side.
    buffer2.writeLong(0xF0000000L);
    assertTrue(buffer.compareTo(buffer2) < 0);
    assertTrue(buffer2.compareTo(buffer) > 0);
    buffer2.release();
}
 
Example 3
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void comparableInterfaceNotViolated() {
    assumeFalse(buffer.isReadOnly());
    buffer.writerIndex(buffer.readerIndex());
    assumeTrue(buffer.writableBytes() >= 4);

    buffer.writeLong(0);
    ByteBuf buffer2 = newBuffer(CAPACITY);
    assumeFalse(buffer2.isReadOnly());
    buffer2.writerIndex(buffer2.readerIndex());
    // Write an unsigned integer that will cause buffer.getUnsignedInt() - buffer2.getUnsignedInt() to underflow the
    // int type and wrap around on the negative side.
    buffer2.writeLong(0xF0000000L);
    assertTrue(buffer.compareTo(buffer2) < 0);
    assertTrue(buffer2.compareTo(buffer) > 0);
    buffer2.release();
}
 
Example 4
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSequentialByteBufferBackedHeapBufferTransfer1() {
    byte[] valueContent = new byte[BLOCK_SIZE * 2];
    ByteBuf value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
    value.writerIndex(0);
    buffer.writerIndex(0);
    for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
        random.nextBytes(valueContent);
        value.setBytes(0, valueContent);
        assertEquals(0, buffer.readerIndex());
        assertEquals(i, buffer.writerIndex());
        buffer.writeBytes(value, random.nextInt(BLOCK_SIZE), BLOCK_SIZE);
        assertEquals(0, value.readerIndex());
        assertEquals(0, value.writerIndex());
    }

    random.setSeed(seed);
    byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
    ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
    for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
        random.nextBytes(expectedValueContent);
        int valueOffset = random.nextInt(BLOCK_SIZE);
        value.setBytes(0, valueContent);
        assertEquals(i, buffer.readerIndex());
        assertEquals(CAPACITY, buffer.writerIndex());
        buffer.readBytes(value, valueOffset, BLOCK_SIZE);
        for (int j = valueOffset; j < valueOffset + BLOCK_SIZE; j ++) {
            assertEquals(expectedValue.getByte(j), value.getByte(j));
        }
        assertEquals(0, value.readerIndex());
        assertEquals(0, value.writerIndex());
    }
}
 
Example 5
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void testWriteCharSequenceExpand(Charset charset) {
    ByteBuf buf = newBuffer(1);
    try {
        int writerIndex = buf.capacity() - 1;
        buf.writerIndex(writerIndex);
        int written = buf.writeCharSequence("AB", charset);
        assertEquals(writerIndex, buf.writerIndex() - written);
    } finally {
        buf.release();
    }
}
 
Example 6
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void testWriteReadCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    buf.writerIndex(1);
    int bytes = buf.writeCharSequence(sequence, charset);
    buf.readerIndex(1);
    assertEquals(sequence, CharBuffer.wrap(buf.readCharSequence(bytes, charset)));
    buf.release();
}
 
Example 7
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSequentialByteBufferBackedHeapBufferTransfer1() {
    byte[] valueContent = new byte[BLOCK_SIZE * 2];
    ByteBuf value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
    value.writerIndex(0);
    buffer.writerIndex(0);
    for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
        random.nextBytes(valueContent);
        value.setBytes(0, valueContent);
        assertEquals(0, buffer.readerIndex());
        assertEquals(i, buffer.writerIndex());
        buffer.writeBytes(value, random.nextInt(BLOCK_SIZE), BLOCK_SIZE);
        assertEquals(0, value.readerIndex());
        assertEquals(0, value.writerIndex());
    }

    random.setSeed(seed);
    byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
    ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
    for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
        random.nextBytes(expectedValueContent);
        int valueOffset = random.nextInt(BLOCK_SIZE);
        value.setBytes(0, valueContent);
        assertEquals(i, buffer.readerIndex());
        assertEquals(CAPACITY, buffer.writerIndex());
        buffer.readBytes(value, valueOffset, BLOCK_SIZE);
        for (int j = valueOffset; j < valueOffset + BLOCK_SIZE; j ++) {
            assertEquals(expectedValue.getByte(j), value.getByte(j));
        }
        assertEquals(0, value.readerIndex());
        assertEquals(0, value.writerIndex());
    }
}
 
Example 8
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testWriteCharSequenceExpand(Charset charset) {
    ByteBuf buf = newBuffer(1);
    try {
        int writerIndex = buf.capacity() - 1;
        buf.writerIndex(writerIndex);
        int written = buf.writeCharSequence("AB", charset);
        assertEquals(writerIndex, buf.writerIndex() - written);
    } finally {
        buf.release();
    }
}
 
Example 9
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testWriteReadCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    buf.writerIndex(1);
    int bytes = buf.writeCharSequence(sequence, charset);
    buf.readerIndex(1);
    assertEquals(sequence, CharBuffer.wrap(buf.readCharSequence(bytes, charset)));
    buf.release();
}
 
Example 10
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSequentialByteBufferBackedHeapBufferTransfer1() {
    byte[] valueContent = new byte[BLOCK_SIZE * 2];
    ByteBuf value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
    value.writerIndex(0);
    buffer.writerIndex(0);
    for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
        random.nextBytes(valueContent);
        value.setBytes(0, valueContent);
        assertEquals(0, buffer.readerIndex());
        assertEquals(i, buffer.writerIndex());
        buffer.writeBytes(value, random.nextInt(BLOCK_SIZE), BLOCK_SIZE);
        assertEquals(0, value.readerIndex());
        assertEquals(0, value.writerIndex());
    }

    random.setSeed(seed);
    byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
    ByteBuf expectedValue = wrappedBuffer(expectedValueContent);
    for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) {
        random.nextBytes(expectedValueContent);
        int valueOffset = random.nextInt(BLOCK_SIZE);
        value.setBytes(0, valueContent);
        assertEquals(i, buffer.readerIndex());
        assertEquals(CAPACITY, buffer.writerIndex());
        buffer.readBytes(value, valueOffset, BLOCK_SIZE);
        for (int j = valueOffset; j < valueOffset + BLOCK_SIZE; j ++) {
            assertEquals(expectedValue.getByte(j), value.getByte(j));
        }
        assertEquals(0, value.readerIndex());
        assertEquals(0, value.writerIndex());
    }
}
 
Example 11
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testWriteCharSequenceExpand(Charset charset) {
    ByteBuf buf = newBuffer(1);
    try {
        int writerIndex = buf.capacity() - 1;
        buf.writerIndex(writerIndex);
        int written = buf.writeCharSequence("AB", charset);
        assertEquals(writerIndex, buf.writerIndex() - written);
    } finally {
        buf.release();
    }
}
 
Example 12
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testWriteReadCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    buf.writerIndex(1);
    int bytes = buf.writeCharSequence(sequence, charset);
    buf.readerIndex(1);
    assertEquals(sequence, CharBuffer.wrap(buf.readCharSequence(bytes, charset)));
    buf.release();
}
 
Example 13
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private void ensureWritableDoesNotThrow(boolean force) {
    final ByteBuf buffer = newBuffer(8);
    buffer.writerIndex(buffer.capacity());
    buffer.ensureWritable(8, force);
    buffer.release();
}
 
Example 14
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private void ensureWritableDoesNotThrow(boolean force) {
    final ByteBuf buffer = newBuffer(8);
    buffer.writerIndex(buffer.capacity());
    buffer.ensureWritable(8, force);
    buffer.release();
}
 
Example 15
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private void ensureWritableDoesNotThrow(boolean force) {
    final ByteBuf buffer = newBuffer(8);
    buffer.writerIndex(buffer.capacity());
    buffer.ensureWritable(8, force);
    buffer.release();
}