Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -45,6 +45,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;

/**
* A mock of the producer interface you can use for testing code that uses Kafka.
Expand Down Expand Up @@ -73,7 +74,7 @@ public class MockProducer<K, V> implements Producer<K, V> {
private boolean transactionAborted;
private boolean producerFenced;
private boolean sentOffsets;
private long commitCount = 0L;
private final AtomicLong commitCount = new AtomicLong(0);
Copy link
Member

Choose a reason for hiding this comment

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

This change does not guarantee that MockProducer is thread-safe

private final List<KafkaMetric> addedMetrics = new ArrayList<>();

public RuntimeException initTransactionException = null;
Expand Down Expand Up @@ -235,7 +236,7 @@ public void commitTransaction() throws ProducerFencedException {
this.transactionAborted = false;
this.transactionInFlight = false;

++this.commitCount;
this.commitCount.getAndIncrement();
}

@Override
Expand Down Expand Up @@ -491,7 +492,7 @@ public boolean sentOffsets() {
}

public long commitCount() {
return this.commitCount;
return this.commitCount.get();
}

/**
Expand Down
1 change: 0 additions & 1 deletion gradle/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
These are possibly real bugs, and have not been evaluated, they were just bulk excluded to unblock upgrading Spotbugs.
-->
<Or>
<Class name="org.apache.kafka.clients.producer.MockProducer"/>
<Class name="org.apache.kafka.clients.producer.internals.ProducerBatch"/>
<Class name="org.apache.kafka.common.utils.ChunkedBytesStream"/>
<Class name="org.apache.kafka.common.security.authenticator.LoginManager"/>
Expand Down