Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ public void onCompletion(final RecordMetadata metadata,
}
});
} catch (final RuntimeException uncaughtException) {
if (uncaughtException instanceof KafkaException &&
uncaughtException.getCause() instanceof ProducerFencedException) {
if (uncaughtException instanceof KafkaException &&(
uncaughtException.getCause() instanceof ProducerFencedException ||
uncaughtException.getCause() instanceof UnknownProducerIdException

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message of RecoverableClientException does not match any longer... (I would recommend to not add the error name to begin with, as the root cause exception is pass into the constructor anyway)

)) {
final KafkaException kafkaException = (KafkaException) uncaughtException;
// producer.send() call may throw a KafkaException which wraps a FencedException,
// in this case we should throw its wrapped inner cause so that it can be captured and re-wrapped as TaskMigrationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.errors.ProducerFencedException;
import org.apache.kafka.common.errors.TimeoutException;
import org.apache.kafka.common.errors.UnknownProducerIdException;
import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.header.internals.RecordHeader;
Expand Down Expand Up @@ -199,6 +200,44 @@ public synchronized Future<RecordMetadata> send(final ProducerRecord record, fin
collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
}

@SuppressWarnings("unchecked")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing generics in the method. I fixed it.

@Test(expected = RecoverableClientException.class)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should avoid to use this construct but use assertThrows() instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also verify the root cause?

public void shouldThrowRecoverableExceptionOnProducerFencedException() {
final RecordCollector collector = new RecordCollectorImpl(
"test",
logContext,
new DefaultProductionExceptionHandler(),
new Metrics().sensor("dropped-records")
);
collector.init(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) {
@Override
public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) {
throw new KafkaException(new ProducerFencedException("asdf"));
}
});

collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
}

@SuppressWarnings("unchecked")
@Test(expected = RecoverableClientException.class)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

public void shouldThrowRecoverableExceptionOnUnknownProducerException() {
final RecordCollector collector = new RecordCollectorImpl(
"test",
logContext,
new DefaultProductionExceptionHandler(),
new Metrics().sensor("dropped-records")
);
collector.init(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) {
@Override
public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) {
throw new KafkaException(new UnknownProducerIdException("asdf"));
}
});

collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
}

@SuppressWarnings("unchecked")
@Test(expected = RecoverableClientException.class)
public void shouldThrowRecoverableExceptionWhenProducerFencedInCallback() {
Expand All @@ -219,6 +258,26 @@ public synchronized Future<RecordMetadata> send(final ProducerRecord record, fin
collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
}

@SuppressWarnings("unchecked")
@Test(expected = RecoverableClientException.class)
public void shouldThrowRecoverableExceptionWhenProducerForgottenInCallback() {
final RecordCollector collector = new RecordCollectorImpl(
"test",
logContext,
new DefaultProductionExceptionHandler(),
new Metrics().sensor("skipped-records"));
collector.init(new MockProducer(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer) {
@Override
public synchronized Future<RecordMetadata> send(final ProducerRecord record, final Callback callback) {
callback.onCompletion(null, new UnknownProducerIdException("asdf"));
return null;
}
});

collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "3", "0", null, null, stringSerializer, stringSerializer, streamPartitioner);
}

@SuppressWarnings("unchecked")
@Test
public void shouldThrowStreamsExceptionOnSubsequentCallIfASendFailsWithDefaultExceptionHandler() {
Expand Down