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));
}
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));
}
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));
}
Aggregations