use of org.apache.kafka.common.serialization.ByteArrayDeserializer in project kafka by apache.
the class KafkaConsumerTest method shouldIgnoreGroupInstanceIdForEmptyGroupId.
@Test
public void shouldIgnoreGroupInstanceIdForEmptyGroupId() {
Map<String, Object> config = new HashMap<>();
config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
config.put(ConsumerConfig.GROUP_INSTANCE_ID_CONFIG, "instance_id");
KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(config, new ByteArrayDeserializer(), new ByteArrayDeserializer());
consumer.close();
}
use of org.apache.kafka.common.serialization.ByteArrayDeserializer in project kafka by apache.
the class KafkaConsumerTest method testMetricConfigRecordingLevel.
@Test
public void testMetricConfigRecordingLevel() {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9000");
try (KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(props, new ByteArrayDeserializer(), new ByteArrayDeserializer())) {
assertEquals(Sensor.RecordingLevel.INFO, consumer.metrics.config().recordLevel());
}
props.put(ConsumerConfig.METRICS_RECORDING_LEVEL_CONFIG, "DEBUG");
try (KafkaConsumer<byte[], byte[]> consumer = new KafkaConsumer<>(props, new ByteArrayDeserializer(), new ByteArrayDeserializer())) {
assertEquals(Sensor.RecordingLevel.DEBUG, consumer.metrics.config().recordLevel());
}
}
use of org.apache.kafka.common.serialization.ByteArrayDeserializer in project kafka by apache.
the class FetcherTest method testFetchOffsetOutOfRangeException.
@Test
public void testFetchOffsetOutOfRangeException() {
buildFetcher(OffsetResetStrategy.NONE, new ByteArrayDeserializer(), new ByteArrayDeserializer(), 2, IsolationLevel.READ_UNCOMMITTED);
assignFromUser(singleton(tp0));
subscriptions.seek(tp0, 0);
fetcher.sendFetches();
client.prepareResponse(fullFetchResponse(tidp0, this.records, Errors.OFFSET_OUT_OF_RANGE, 100L, 0));
consumerClient.poll(time.timer(0));
assertFalse(subscriptions.isOffsetResetNeeded(tp0));
for (int i = 0; i < 2; i++) {
OffsetOutOfRangeException e = assertThrows(OffsetOutOfRangeException.class, () -> fetcher.collectFetch());
assertEquals(singleton(tp0), e.offsetOutOfRangePartitions().keySet());
assertEquals(0L, e.offsetOutOfRangePartitions().get(tp0).longValue());
}
}
use of org.apache.kafka.common.serialization.ByteArrayDeserializer in project kafka by apache.
the class FetcherTest method testFetchedRecordsAfterSeek.
@Test
public void testFetchedRecordsAfterSeek() {
buildFetcher(OffsetResetStrategy.NONE, new ByteArrayDeserializer(), new ByteArrayDeserializer(), 2, IsolationLevel.READ_UNCOMMITTED);
assignFromUser(singleton(tp0));
subscriptions.seek(tp0, 0);
assertTrue(fetcher.sendFetches() > 0);
client.prepareResponse(fullFetchResponse(tidp0, this.records, Errors.OFFSET_OUT_OF_RANGE, 100L, 0));
consumerClient.poll(time.timer(0));
assertFalse(subscriptions.isOffsetResetNeeded(tp0));
subscriptions.seek(tp0, 2);
assertEmptyFetch("Should not return records or advance position after seeking to end of topic partition");
}
use of org.apache.kafka.common.serialization.ByteArrayDeserializer in project kafka by apache.
the class FetcherTest method testReturnAbortedTransactionsinUncommittedMode.
@Test
public void testReturnAbortedTransactionsinUncommittedMode() {
buildFetcher(OffsetResetStrategy.EARLIEST, new ByteArrayDeserializer(), new ByteArrayDeserializer(), Integer.MAX_VALUE, IsolationLevel.READ_UNCOMMITTED);
ByteBuffer buffer = ByteBuffer.allocate(1024);
int currentOffset = 0;
currentOffset += appendTransactionalRecords(buffer, 1L, currentOffset, new SimpleRecord(time.milliseconds(), "key".getBytes(), "value".getBytes()), new SimpleRecord(time.milliseconds(), "key".getBytes(), "value".getBytes()));
abortTransaction(buffer, 1L, currentOffset);
buffer.flip();
List<FetchResponseData.AbortedTransaction> abortedTransactions = Collections.singletonList(new FetchResponseData.AbortedTransaction().setProducerId(1).setFirstOffset(0));
MemoryRecords records = MemoryRecords.readableRecords(buffer);
assignFromUser(singleton(tp0));
subscriptions.seek(tp0, 0);
// normal fetch
assertEquals(1, fetcher.sendFetches());
assertFalse(fetcher.hasCompletedFetches());
client.prepareResponse(fullFetchResponseWithAbortedTransactions(records, abortedTransactions, Errors.NONE, 100L, 100L, 0));
consumerClient.poll(time.timer(0));
assertTrue(fetcher.hasCompletedFetches());
Map<TopicPartition, List<ConsumerRecord<byte[], byte[]>>> fetchedRecords = fetchedRecords();
assertTrue(fetchedRecords.containsKey(tp0));
}
Aggregations