@@ -94,7 +94,7 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean {
9494 */
9595 public static final String BROKER_LIST_PROPERTY = "spring.embedded.kafka.brokers.property" ;
9696
97- private static final int DEFAULT_ADMIN_TIMEOUT = 30 ;
97+ private static final Duration DEFAULT_ADMIN_TIMEOUT = Duration . ofSeconds ( 10 ) ;
9898
9999 private final int count ;
100100
@@ -116,7 +116,7 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean {
116116
117117 private int [] kafkaPorts ;
118118
119- private int adminTimeout = DEFAULT_ADMIN_TIMEOUT ;
119+ private Duration adminTimeout = DEFAULT_ADMIN_TIMEOUT ;
120120
121121 private String brokerListProperty ;
122122
@@ -157,12 +157,12 @@ public EmbeddedKafkaBroker(int count, boolean controlledShutdown, int partitions
157157 /**
158158 * Specify the properties to configure Kafka Broker before start, e.g.
159159 * {@code auto.create.topics.enable}, {@code transaction.state.log.replication.factor} etc.
160- * @param brokerProperties the properties to use for configuring Kafka Broker(s).
160+ * @param properties the properties to use for configuring Kafka Broker(s).
161161 * @return this for chaining configuration.
162162 * @see KafkaConfig
163163 */
164- public EmbeddedKafkaBroker brokerProperties (Map <String , String > brokerProperties ) {
165- this .brokerProperties .putAll (brokerProperties );
164+ public EmbeddedKafkaBroker brokerProperties (Map <String , String > properties ) {
165+ this .brokerProperties .putAll (properties );
166166 return this ;
167167 }
168168
@@ -180,13 +180,13 @@ public EmbeddedKafkaBroker brokerProperty(String property, Object value) {
180180 /**
181181 * Set explicit ports on which the kafka brokers will listen. Useful when running an
182182 * embedded broker that you want to access from other processes.
183- * @param kafkaPorts the ports.
183+ * @param ports the ports.
184184 * @return the {@link EmbeddedKafkaBroker}.
185185 */
186- public EmbeddedKafkaBroker kafkaPorts (int ... kafkaPorts ) {
187- Assert .isTrue (kafkaPorts .length == this .count , "A port must be provided for each instance ["
188- + this .count + "], provided: " + Arrays .toString (kafkaPorts ) + ", use 0 for a random port" );
189- this .kafkaPorts = kafkaPorts ;
186+ public EmbeddedKafkaBroker kafkaPorts (int ... ports ) {
187+ Assert .isTrue (ports .length == this .count , "A port must be provided for each instance ["
188+ + this .count + "], provided: " + Arrays .toString (ports ) + ", use 0 for a random port" );
189+ this .kafkaPorts = ports ;
190190 return this ;
191191 }
192192
@@ -197,7 +197,7 @@ public EmbeddedKafkaBroker kafkaPorts(int... kafkaPorts) {
197197 * @since 2.2
198198 */
199199 public void setAdminTimeout (int adminTimeout ) {
200- this .adminTimeout = adminTimeout ;
200+ this .adminTimeout = Duration . ofSeconds ( adminTimeout ) ;
201201 }
202202
203203 @ Override
@@ -247,42 +247,42 @@ private Properties createBrokerProperties(int i) {
247247 /**
248248 * Add topics to the existing broker(s) using the configured number of partitions.
249249 * The broker(s) must be running.
250- * @param topics the topics.
250+ * @param topicsToAdd the topics.
251251 */
252- public void addTopics (String ... topics ) {
252+ public void addTopics (String ... topicsToAdd ) {
253253 Assert .notNull (this .zookeeper , "Broker must be started before this method can be called" );
254- HashSet <String > set = new HashSet <>(Arrays .asList (topics ));
254+ HashSet <String > set = new HashSet <>(Arrays .asList (topicsToAdd ));
255255 createKafkaTopics (set );
256256 this .topics .addAll (set );
257257 }
258258
259259 /**
260260 * Add topics to the existing broker(s).
261261 * The broker(s) must be running.
262- * @param topics the topics.
262+ * @param topicsToAdd the topics.
263263 * @since 2.2
264264 */
265- public void addTopics (NewTopic ... topics ) {
265+ public void addTopics (NewTopic ... topicsToAdd ) {
266266 Assert .notNull (this .zookeeper , "Broker must be started before this method can be called" );
267- for (NewTopic topic : topics ) {
267+ for (NewTopic topic : topicsToAdd ) {
268268 Assert .isTrue (this .topics .add (topic .name ()), () -> "topic already exists: " + topic );
269269 Assert .isTrue (topic .replicationFactor () <= this .count
270270 && (topic .replicasAssignments () == null
271271 || topic .replicasAssignments ().size () <= this .count ),
272272 () -> "Embedded kafka does not support the requested replication factor: " + topic );
273273 }
274274
275- doWithAdmin (admin -> createTopics (admin , Arrays .asList (topics )));
275+ doWithAdmin (admin -> createTopics (admin , Arrays .asList (topicsToAdd )));
276276 }
277277
278278 /**
279279 * Create topics in the existing broker(s) using the configured number of partitions.
280- * @param topics the topics.
280+ * @param topicsToCreate the topics.
281281 */
282- private void createKafkaTopics (Set <String > topics ) {
282+ private void createKafkaTopics (Set <String > topicsToCreate ) {
283283 doWithAdmin (admin -> {
284284 createTopics (admin ,
285- topics .stream ()
285+ topicsToCreate .stream ()
286286 .map (t -> new NewTopic (t , this .partitionsPerTopic , (short ) this .count ))
287287 .collect (Collectors .toList ()));
288288 });
@@ -291,7 +291,7 @@ private void createKafkaTopics(Set<String> topics) {
291291 private void createTopics (AdminClient admin , List <NewTopic > newTopics ) {
292292 CreateTopicsResult createTopics = admin .createTopics (newTopics );
293293 try {
294- createTopics .all ().get (this .adminTimeout , TimeUnit .SECONDS );
294+ createTopics .all ().get (this .adminTimeout . getSeconds () , TimeUnit .SECONDS );
295295 }
296296 catch (Exception e ) {
297297 throw new KafkaException (e );
@@ -312,7 +312,7 @@ public void doWithAdmin(java.util.function.Consumer<AdminClient> callback) {
312312 }
313313 finally {
314314 if (admin != null ) {
315- admin .close (this .adminTimeout , TimeUnit . SECONDS );
315+ admin .close (this .adminTimeout );
316316 }
317317 }
318318 }
@@ -453,16 +453,16 @@ public void consumeFromAnEmbeddedTopic(Consumer<?, ?> consumer, String topic) {
453453 /**
454454 * Subscribe a consumer to one or more of the embedded topics.
455455 * @param consumer the consumer.
456- * @param topics the topics.
456+ * @param topicsToConsume the topics.
457457 */
458- public void consumeFromEmbeddedTopics (Consumer <?, ?> consumer , String ... topics ) {
459- HashSet <String > diff = new HashSet <>(Arrays .asList (topics ));
458+ public void consumeFromEmbeddedTopics (Consumer <?, ?> consumer , String ... topicsToConsume ) {
459+ HashSet <String > diff = new HashSet <>(Arrays .asList (topicsToConsume ));
460460 diff .removeAll (new HashSet <>(this .topics ));
461461 assertThat (this .topics )
462462 .as ("topic(s):'" + diff + "' are not in embedded topic list" )
463- .containsAll (new HashSet <>(Arrays .asList (topics )));
463+ .containsAll (new HashSet <>(Arrays .asList (topicsToConsume )));
464464 final AtomicBoolean assigned = new AtomicBoolean ();
465- consumer .subscribe (Arrays .asList (topics ), new ConsumerRebalanceListener () {
465+ consumer .subscribe (Arrays .asList (topicsToConsume ), new ConsumerRebalanceListener () {
466466
467467 @ Override
468468 public void onPartitionsRevoked (Collection <TopicPartition > partitions ) {
0 commit comments