Skip to content

Commit 5650491

Browse files
breader124garyrussell
authored andcommitted
GH-2059: adminTimeout property on @embeddedkafka
* GH-2059: expose adminTimeout property in EmbeddedKafka annotation * GH-2059: remove unused import * GH-2059: change since version param in added methods Resolves #2059
1 parent da0b820 commit 5650491

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

spring-kafka-test/src/main/java/org/springframework/kafka/test/EmbeddedKafkaBroker.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
* @author Elliot Kennedy
9292
* @author Nakul Mishra
9393
* @author Pawel Lozinski
94+
* @author Adrian Chlebosz
9495
*
9596
* @since 2.2
9697
*/
@@ -114,7 +115,7 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean {
114115
*/
115116
public static final String BROKER_LIST_PROPERTY = "spring.embedded.kafka.brokers.property";
116117

117-
private static final Duration DEFAULT_ADMIN_TIMEOUT = Duration.ofSeconds(10);
118+
public static final int DEFAULT_ADMIN_TIMEOUT = 10;
118119

119120
public static final int DEFAULT_ZK_SESSION_TIMEOUT = 18000;
120121

@@ -176,7 +177,7 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean {
176177

177178
private int[] kafkaPorts;
178179

179-
private Duration adminTimeout = DEFAULT_ADMIN_TIMEOUT;
180+
private Duration adminTimeout = Duration.ofSeconds(DEFAULT_ADMIN_TIMEOUT);
180181

181182
private int zkConnectionTimeout = DEFAULT_ZK_CONNECTION_TIMEOUT;
182183

@@ -257,33 +258,24 @@ public EmbeddedKafkaBroker kafkaPorts(int... ports) {
257258
}
258259

259260
/**
260-
* Set an explicit port for the embedded Zookeeper.
261-
* @param port the port.
262-
* @return the {@link EmbeddedKafkaBroker}.
261+
* Set the system property with this name to the list of broker addresses.
262+
* @param brokerListProperty the brokerListProperty to set
263+
* @return this broker.
263264
* @since 2.3
264265
*/
265-
public EmbeddedKafkaBroker zkPort(int port) {
266-
this.zkPort = port;
266+
public EmbeddedKafkaBroker brokerListProperty(String brokerListProperty) {
267+
this.brokerListProperty = brokerListProperty;
267268
return this;
268269
}
269-
/**
270-
* Set the timeout in seconds for admin operations (e.g. topic creation, close).
271-
* Default 30 seconds.
272-
* @param adminTimeout the timeout.
273-
* @since 2.2
274-
*/
275-
public void setAdminTimeout(int adminTimeout) {
276-
this.adminTimeout = Duration.ofSeconds(adminTimeout);
277-
}
278270

279271
/**
280-
* Set the system property with this name to the list of broker addresses.
281-
* @param brokerListProperty the brokerListProperty to set
282-
* @return this broker.
272+
* Set an explicit port for the embedded Zookeeper.
273+
* @param port the port.
274+
* @return the {@link EmbeddedKafkaBroker}.
283275
* @since 2.3
284276
*/
285-
public EmbeddedKafkaBroker brokerListProperty(String brokerListProperty) {
286-
this.brokerListProperty = brokerListProperty;
277+
public EmbeddedKafkaBroker zkPort(int port) {
278+
this.zkPort = port;
287279
return this;
288280
}
289281

@@ -305,6 +297,27 @@ public void setZkPort(int zkPort) {
305297
this.zkPort = zkPort;
306298
}
307299

300+
/**
301+
* Set the timeout in seconds for admin operations (e.g. topic creation, close).
302+
* @param adminTimeout the timeout.
303+
* @return the {@link EmbeddedKafkaBroker}
304+
* @since 2.8.5
305+
*/
306+
public EmbeddedKafkaBroker adminTimeout(int adminTimeout) {
307+
this.adminTimeout = Duration.ofSeconds(adminTimeout);
308+
return this;
309+
}
310+
311+
/**
312+
* Set the timeout in seconds for admin operations (e.g. topic creation, close).
313+
* Default 10 seconds.
314+
* @param adminTimeout the timeout.
315+
* @since 2.2
316+
*/
317+
public void setAdminTimeout(int adminTimeout) {
318+
this.adminTimeout = Duration.ofSeconds(adminTimeout);
319+
}
320+
308321
/**
309322
* Set connection timeout for the client to the embedded Zookeeper.
310323
* @param zkConnectionTimeout the connection timeout,

spring-kafka-test/src/main/java/org/springframework/kafka/test/condition/EmbeddedKafkaCondition.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 the original author or authors.
2+
* Copyright 2019-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,6 +51,7 @@
5151
* @author Gary Russell
5252
* @author Artem Bilan
5353
* @author Pawel Lozinski
54+
* @author Adrian Chlebosz
5455
*
5556
* @since 2.3
5657
*
@@ -127,7 +128,8 @@ private EmbeddedKafkaBroker createBroker(EmbeddedKafka embedded) {
127128
.zkPort(embedded.zookeeperPort())
128129
.kafkaPorts(ports)
129130
.zkConnectionTimeout(embedded.zkConnectionTimeout())
130-
.zkSessionTimeout(embedded.zkSessionTimeout());
131+
.zkSessionTimeout(embedded.zkSessionTimeout())
132+
.adminTimeout(embedded.adminTimeout());
131133
Properties properties = new Properties();
132134

133135
for (String pair : embedded.brokerProperties()) {

spring-kafka-test/src/main/java/org/springframework/kafka/test/context/EmbeddedKafka.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,6 +60,7 @@
6060
* @author Gary Russell
6161
* @author Sergio Lourenco
6262
* @author Pawel Lozinski
63+
* @author Adrian Chlebosz
6364
*
6465
* @since 1.3
6566
*
@@ -172,5 +173,12 @@
172173
*/
173174
int zkSessionTimeout() default EmbeddedKafkaBroker.DEFAULT_ZK_SESSION_TIMEOUT;
174175

176+
/**
177+
* Timeout in seconds for admin operations (e.g. topic creation, close).
178+
* @return default {@link EmbeddedKafkaBroker#DEFAULT_ADMIN_TIMEOUT}
179+
* @since 2.8.5
180+
*/
181+
int adminTimeout() default EmbeddedKafkaBroker.DEFAULT_ADMIN_TIMEOUT;
182+
175183
}
176184

0 commit comments

Comments
 (0)