use of org.apache.kafka.common.utils.ByteBufferOutputStream in project kafka by apache.
the class FetcherTest method testInvalidDefaultRecordBatch.
@Test
public void testInvalidDefaultRecordBatch() {
buildFetcher();
ByteBuffer buffer = ByteBuffer.allocate(1024);
ByteBufferOutputStream out = new ByteBufferOutputStream(buffer);
MemoryRecordsBuilder builder = new MemoryRecordsBuilder(out, DefaultRecordBatch.CURRENT_MAGIC_VALUE, CompressionType.NONE, TimestampType.CREATE_TIME, 0L, 10L, 0L, (short) 0, 0, false, false, 0, 1024);
builder.append(10L, "key".getBytes(), "value".getBytes());
builder.close();
buffer.flip();
// Garble the CRC
buffer.position(17);
buffer.put("beef".getBytes());
buffer.position(0);
assignFromUser(singleton(tp0));
subscriptions.seek(tp0, 0);
// normal fetch
assertEquals(1, fetcher.sendFetches());
client.prepareResponse(fullFetchResponse(tidp0, MemoryRecords.readableRecords(buffer), Errors.NONE, 100L, 0));
consumerClient.poll(time.timer(0));
// the fetchedRecords() should always throw exception due to the bad batch.
for (int i = 0; i < 2; i++) {
try {
fetcher.collectFetch();
fail("fetchedRecords should have raised KafkaException");
} catch (KafkaException e) {
assertEquals(0, subscriptions.position(tp0).offset);
}
}
}
Aggregations