Altered the example in EmbeddedKafkaHolder usage (#3929)
Integration tests with an EmbeddedKafka instance are sometimes run in parallel in Junit. The current example is not thread safe, so I think the oficial documentation should account for that. **Auto-cherry-pick to `3.3.x` & `3.2.x`** Signed-off-by: mipo256 <mikhailpolivakha@gmail.com>
This commit is contained in:
committed by
GitHub
parent
7b71d207d5
commit
579e7cb8ff
@@ -162,21 +162,20 @@ public final class EmbeddedKafkaHolder {
|
||||
|
||||
public static EmbeddedKafkaBroker getEmbeddedKafka() {
|
||||
if (!started) {
|
||||
try {
|
||||
embeddedKafka.afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new KafkaException("Embedded broker failed to start", e);
|
||||
}
|
||||
started = true;
|
||||
synchronized (this) {
|
||||
if (!started) {
|
||||
try {
|
||||
embeddedKafka.afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new KafkaException("Embedded broker failed to start", e);
|
||||
}
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return embeddedKafka;
|
||||
}
|
||||
|
||||
private EmbeddedKafkaHolder() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user