Skip to content

Commit 408623c

Browse files
authored
spring-projectsGH-2059: expose adminTimeout property in EmbeddedKafka annotation (spring-projects#2194)
* spring-projectsGH-2059: expose adminTimeout property in EmbeddedKafka annotation * spring-projectsGH-2059: remove unused import * spring-projectsGH-2059: change since version param in added methods Resolves spring-projects#2059
1 parent 31b78c4 commit 408623c

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
@@ -90,6 +90,7 @@
9090
* @author Elliot Kennedy
9191
* @author Nakul Mishra
9292
* @author Pawel Lozinski
93+
* @author Adrian Chlebosz
9394
*
9495
* @since 2.2
9596
*/
@@ -113,7 +114,7 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean {
113114
*/
114115
public static final String BROKER_LIST_PROPERTY = "spring.embedded.kafka.brokers.property";
115116

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

118119
public static final int DEFAULT_ZK_SESSION_TIMEOUT = 18000;
119120

@@ -157,7 +158,7 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean {
157158

158159
private int[] kafkaPorts;
159160

160-
private Duration adminTimeout = DEFAULT_ADMIN_TIMEOUT;
161+
private Duration adminTimeout = Duration.ofSeconds(DEFAULT_ADMIN_TIMEOUT);
161162

162163
private int zkConnectionTimeout = DEFAULT_ZK_CONNECTION_TIMEOUT;
163164

@@ -238,33 +239,24 @@ public EmbeddedKafkaBroker kafkaPorts(int... ports) {
238239
}
239240

240241
/**
241-
* Set an explicit port for the embedded Zookeeper.
242-
* @param port the port.
243-
* @return the {@link EmbeddedKafkaBroker}.
242+
* Set the system property with this name to the list of broker addresses.
243+
* @param brokerListProperty the brokerListProperty to set
244+
* @return this broker.
244245
* @since 2.3
245246
*/
246-
public EmbeddedKafkaBroker zkPort(int port) {
247-
this.zkPort = port;
247+
public EmbeddedKafkaBroker brokerListProperty(String brokerListProperty) {
248+
this.brokerListProperty = brokerListProperty;
248249
return this;
249250
}
250-
/**
251-
* Set the timeout in seconds for admin operations (e.g. topic creation, close).
252-
* Default 30 seconds.
253-
* @param adminTimeout the timeout.
254-
* @since 2.2
255-
*/
256-
public void setAdminTimeout(int adminTimeout) {
257-
this.adminTimeout = Duration.ofSeconds(adminTimeout);
258-
}
259251

260252
/**
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.
253+
* Set an explicit port for the embedded Zookeeper.
254+
* @param port the port.
255+
* @return the {@link EmbeddedKafkaBroker}.
264256
* @since 2.3
265257
*/
266-
public EmbeddedKafkaBroker brokerListProperty(String brokerListProperty) {
267-
this.brokerListProperty = brokerListProperty;
258+
public EmbeddedKafkaBroker zkPort(int port) {
259+
this.zkPort = port;
268260
return this;
269261
}
270262

@@ -286,6 +278,27 @@ public void setZkPort(int zkPort) {
286278
this.zkPort = zkPort;
287279
}
288280

281+
/**
282+
* Set the timeout in seconds for admin operations (e.g. topic creation, close).
283+
* @param adminTimeout the timeout.
284+
* @return the {@link EmbeddedKafkaBroker}
285+
* @since 2.8.5
286+
*/
287+
public EmbeddedKafkaBroker adminTimeout(int adminTimeout) {
288+
this.adminTimeout = Duration.ofSeconds(adminTimeout);
289+
return this;
290+
}
291+
292+
/**
293+
* Set the timeout in seconds for admin operations (e.g. topic creation, close).
294+
* Default 10 seconds.
295+
* @param adminTimeout the timeout.
296+
* @since 2.2
297+
*/
298+
public void setAdminTimeout(int adminTimeout) {
299+
this.adminTimeout = Duration.ofSeconds(adminTimeout);
300+
}
301+
289302
/**
290303
* Set connection timeout for the client to the embedded Zookeeper.
291304
* @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)