Search in sources :

Example 6 with ByteBufferInputStream

use of org.apache.kafka.common.utils.ByteBufferInputStream in project kafka by apache.

the class DefaultRecordTest method testInvalidHeaderValuePartial.

@Test
public void testInvalidHeaderValuePartial() {
    byte attributes = 0;
    long timestampDelta = 2;
    int offsetDelta = 1;
    int sizeOfBodyInBytes = 100;
    ByteBuffer buf = ByteBuffer.allocate(sizeOfBodyInBytes + ByteUtils.sizeOfVarint(sizeOfBodyInBytes));
    ByteUtils.writeVarint(sizeOfBodyInBytes, buf);
    buf.put(attributes);
    ByteUtils.writeVarlong(timestampDelta, buf);
    ByteUtils.writeVarint(offsetDelta, buf);
    // null key
    ByteUtils.writeVarint(-1, buf);
    // null value
    ByteUtils.writeVarint(-1, buf);
    ByteUtils.writeVarint(1, buf);
    ByteUtils.writeVarint(1, buf);
    buf.put((byte) 1);
    // header value too long
    ByteUtils.writeVarint(105, buf);
    buf.position(buf.limit());
    buf.flip();
    DataInputStream inputStream = new DataInputStream(new ByteBufferInputStream(buf));
    assertThrows(InvalidRecordException.class, () -> DefaultRecord.readPartiallyFrom(inputStream, skipArray, 0L, 0L, RecordBatch.NO_SEQUENCE, null));
}
Also used : ByteBufferInputStream(org.apache.kafka.common.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 7 with ByteBufferInputStream

use of org.apache.kafka.common.utils.ByteBufferInputStream in project kafka by apache.

the class DefaultRecordTest method testInvalidHeaderKeyPartial.

@Test
public void testInvalidHeaderKeyPartial() {
    byte attributes = 0;
    long timestampDelta = 2;
    int offsetDelta = 1;
    int sizeOfBodyInBytes = 100;
    ByteBuffer buf = ByteBuffer.allocate(sizeOfBodyInBytes + ByteUtils.sizeOfVarint(sizeOfBodyInBytes));
    ByteUtils.writeVarint(sizeOfBodyInBytes, buf);
    buf.put(attributes);
    ByteUtils.writeVarlong(timestampDelta, buf);
    ByteUtils.writeVarint(offsetDelta, buf);
    // null key
    ByteUtils.writeVarint(-1, buf);
    // null value
    ByteUtils.writeVarint(-1, buf);
    ByteUtils.writeVarint(1, buf);
    // header key too long
    ByteUtils.writeVarint(105, buf);
    buf.position(buf.limit());
    buf.flip();
    DataInputStream inputStream = new DataInputStream(new ByteBufferInputStream(buf));
    assertThrows(InvalidRecordException.class, () -> DefaultRecord.readPartiallyFrom(inputStream, skipArray, 0L, 0L, RecordBatch.NO_SEQUENCE, null));
}
Also used : ByteBufferInputStream(org.apache.kafka.common.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 8 with ByteBufferInputStream

use of org.apache.kafka.common.utils.ByteBufferInputStream in project kafka by apache.

the class DefaultRecordTest method testInvalidNumHeadersPartial.

@Test
public void testInvalidNumHeadersPartial() {
    byte attributes = 0;
    long timestampDelta = 2;
    int offsetDelta = 1;
    int sizeOfBodyInBytes = 100;
    ByteBuffer buf = ByteBuffer.allocate(sizeOfBodyInBytes + ByteUtils.sizeOfVarint(sizeOfBodyInBytes));
    ByteUtils.writeVarint(sizeOfBodyInBytes, buf);
    buf.put(attributes);
    ByteUtils.writeVarlong(timestampDelta, buf);
    ByteUtils.writeVarint(offsetDelta, buf);
    // null key
    ByteUtils.writeVarint(-1, buf);
    // null value
    ByteUtils.writeVarint(-1, buf);
    // -1 num.headers, not allowed
    ByteUtils.writeVarint(-1, buf);
    buf.position(buf.limit());
    buf.flip();
    DataInputStream inputStream = new DataInputStream(new ByteBufferInputStream(buf));
    assertThrows(InvalidRecordException.class, () -> DefaultRecord.readPartiallyFrom(inputStream, skipArray, 0L, 0L, RecordBatch.NO_SEQUENCE, null));
}
Also used : ByteBufferInputStream(org.apache.kafka.common.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

DataInputStream (java.io.DataInputStream)8 ByteBufferInputStream (org.apache.kafka.common.utils.ByteBufferInputStream)8 ByteBuffer (java.nio.ByteBuffer)6 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)2 TaskAssignmentException (org.apache.kafka.streams.errors.TaskAssignmentException)2