|
19 | 19 | import java.io.File; |
20 | 20 | import java.io.IOException; |
21 | 21 | import java.io.UncheckedIOException; |
22 | | -import java.lang.reflect.InvocationTargetException; |
23 | | -import java.lang.reflect.Method; |
24 | 22 | import java.net.InetSocketAddress; |
25 | 23 | import java.nio.file.Files; |
26 | 24 | import java.time.Duration; |
|
53 | 51 | import org.apache.kafka.common.KafkaException; |
54 | 52 | import org.apache.kafka.common.TopicPartition; |
55 | 53 | import org.apache.kafka.common.security.auth.SecurityProtocol; |
56 | | -import org.apache.kafka.common.utils.AppInfoParser; |
57 | 54 | import org.apache.kafka.common.utils.Exit; |
58 | 55 | import org.apache.kafka.common.utils.Time; |
59 | 56 | import org.apache.kafka.common.utils.Utils; |
|
70 | 67 | import org.springframework.retry.policy.SimpleRetryPolicy; |
71 | 68 | import org.springframework.retry.support.RetryTemplate; |
72 | 69 | import org.springframework.util.Assert; |
73 | | -import org.springframework.util.ReflectionUtils; |
74 | 70 |
|
75 | 71 | import kafka.cluster.EndPoint; |
76 | 72 | import kafka.server.KafkaConfig; |
@@ -121,40 +117,6 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean { |
121 | 117 |
|
122 | 118 | public static final int DEFAULT_ZK_CONNECTION_TIMEOUT = DEFAULT_ZK_SESSION_TIMEOUT; |
123 | 119 |
|
124 | | - private static final Method GET_BROKER_STATE_METHOD; |
125 | | - |
126 | | - private static final Method BROKER_CONFIGS_METHOD; |
127 | | - |
128 | | - static { |
129 | | - try { |
130 | | - Method method = KafkaServer.class.getDeclaredMethod("brokerState"); |
131 | | - if (method.getReturnType().equals(AtomicReference.class)) { |
132 | | - GET_BROKER_STATE_METHOD = method; |
133 | | - } |
134 | | - else { |
135 | | - GET_BROKER_STATE_METHOD = null; |
136 | | - } |
137 | | - } |
138 | | - catch (NoSuchMethodException | SecurityException ex) { |
139 | | - throw new IllegalStateException("Failed to determine KafkaServer.brokerState() method; client version: " |
140 | | - + AppInfoParser.getVersion(), ex); |
141 | | - } |
142 | | - try { |
143 | | - AtomicReference<Method> configsMethod = new AtomicReference<>(); |
144 | | - ReflectionUtils.doWithMethods(TestUtils.class, |
145 | | - method -> configsMethod.set(method), |
146 | | - method -> method.getName().equals("createBrokerConfig")); |
147 | | - BROKER_CONFIGS_METHOD = configsMethod.get(); |
148 | | - if (BROKER_CONFIGS_METHOD == null) { |
149 | | - throw new IllegalStateException(); |
150 | | - } |
151 | | - } |
152 | | - catch (IllegalStateException ex) { |
153 | | - throw new IllegalStateException("Failed to obtain TestUtils.createBrokerConfig method; client version: " |
154 | | - + AppInfoParser.getVersion(), ex); |
155 | | - } |
156 | | - } |
157 | | - |
158 | 120 | private final int count; |
159 | 121 |
|
160 | 122 | private final boolean controlledShutdown; |
@@ -414,29 +376,13 @@ private void overrideExitMethods() { |
414 | 376 | } |
415 | 377 |
|
416 | 378 | private Properties createBrokerProperties(int i) { |
417 | | - try { |
418 | | - if (BROKER_CONFIGS_METHOD.getParameterTypes().length == 21) { // 3.3.2 |
419 | | - return (Properties) BROKER_CONFIGS_METHOD.invoke(null, i, this.zkConnect, this.controlledShutdown, |
420 | | - true, this.kafkaPorts[i], |
421 | | - scala.Option.apply(null), |
422 | | - scala.Option.apply(null), |
423 | | - scala.Option.apply(null), |
424 | | - true, false, 0, false, 0, false, 0, scala.Option.apply(null), 1, false, |
425 | | - this.partitionsPerTopic, (short) this.count, false); |
426 | | - } |
427 | | - else { |
428 | | - return (Properties) BROKER_CONFIGS_METHOD.invoke(null, i, this.zkConnect, this.controlledShutdown, |
429 | | - true, this.kafkaPorts[i], |
430 | | - scala.Option.apply(null), |
431 | | - scala.Option.apply(null), |
432 | | - scala.Option.apply(null), |
433 | | - true, false, 0, false, 0, false, 0, scala.Option.apply(null), 1, false, |
434 | | - this.partitionsPerTopic, (short) this.count); |
435 | | - } |
436 | | - } |
437 | | - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { |
438 | | - throw new IllegalStateException(ex); |
439 | | - } |
| 379 | + return TestUtils.createBrokerConfig(i, this.zkConnect, this.controlledShutdown, |
| 380 | + true, this.kafkaPorts[i], |
| 381 | + scala.Option.apply(null), |
| 382 | + scala.Option.apply(null), |
| 383 | + scala.Option.apply(null), |
| 384 | + true, false, 0, false, 0, false, 0, scala.Option.apply(null), 1, false, |
| 385 | + this.partitionsPerTopic, (short) this.count, false); |
440 | 386 | } |
441 | 387 |
|
442 | 388 | /** |
@@ -628,24 +574,7 @@ public void destroy() { |
628 | 574 | } |
629 | 575 |
|
630 | 576 | private boolean brokerRunning(KafkaServer kafkaServer) { |
631 | | - try { |
632 | | - return !kafkaServer.brokerState().equals(BrokerState.NOT_RUNNING); |
633 | | - } |
634 | | - catch (NoSuchMethodError error) { |
635 | | - if (GET_BROKER_STATE_METHOD != null) { |
636 | | - try { |
637 | | - return !GET_BROKER_STATE_METHOD.invoke(kafkaServer).toString().equals("NOT_RUNNING"); |
638 | | - } |
639 | | - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { |
640 | | - logger.debug(ex, "Could not determine broker state during shutdown"); |
641 | | - return true; |
642 | | - } |
643 | | - } |
644 | | - else { |
645 | | - logger.debug("Could not determine broker state during shutdown"); |
646 | | - return true; |
647 | | - } |
648 | | - } |
| 577 | + return !kafkaServer.brokerState().equals(BrokerState.NOT_RUNNING); |
649 | 578 | } |
650 | 579 |
|
651 | 580 | public Set<String> getTopics() { |
|
0 commit comments