Skip to content

Commit 4f3fd0e

Browse files
authored
Review fixes for spring-kafka-2.7:testing (#17736)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com>
1 parent ab2c69c commit 4f3fd0e

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

instrumentation/spring/spring-kafka-2.7/testing/src/main/java/io/opentelemetry/testing/AbstractSpringKafkaTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void tearDownApp() {
106106
"send",
107107
MethodType.methodType(
108108
listenableFutureClass, String.class, Object.class, Object.class));
109-
} catch (ClassNotFoundException | NoSuchMethodException e) {
109+
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
110110
// spring-kafka 3.0 changed the return type
111111
try {
112112
sendMethod =
@@ -131,8 +131,8 @@ void tearDownApp() {
131131
protected void send(String topic, String key, String data) {
132132
try {
133133
send.invoke(kafkaTemplate, topic, key, data);
134-
} catch (Throwable e) {
135-
throw new AssertionError(e);
134+
} catch (Throwable t) {
135+
throw new AssertionError(t);
136136
}
137137
}
138138

@@ -143,7 +143,7 @@ protected void sendBatchMessages(Map<String, String> keyToData) throws Interrupt
143143
// a batch.
144144
int maxAttempts = 5;
145145
for (int i = 1; i <= maxAttempts; i++) {
146-
BatchRecordListener.reset();
146+
BatchRecordListener.reset(keyToData.size());
147147

148148
testing()
149149
.runWithSpan(
@@ -157,7 +157,7 @@ protected void sendBatchMessages(Map<String, String> keyToData) throws Interrupt
157157
});
158158

159159
BatchRecordListener.waitForMessages();
160-
if (BatchRecordListener.getLastBatchSize() == 2) {
160+
if (BatchRecordListener.getLastBatchSize() == keyToData.size()) {
161161
break;
162162
} else if (i < maxAttempts) {
163163
testing().waitForTraces(2);
@@ -166,6 +166,7 @@ protected void sendBatchMessages(Map<String, String> keyToData) throws Interrupt
166166
logger.info("Messages weren't received as batch, retrying");
167167
}
168168
}
169+
assertThat(BatchRecordListener.getLastBatchSize()).isEqualTo(keyToData.size());
169170
}
170171

171172
protected static Consumer<List<? extends LinkData>> links(SpanContext... spanContexts) {

instrumentation/spring/spring-kafka-2.7/testing/src/main/java/io/opentelemetry/testing/BatchRecordListener.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.testing;
77

88
import static java.util.concurrent.TimeUnit.SECONDS;
9+
import static org.assertj.core.api.Assertions.assertThat;
910

1011
import io.opentelemetry.instrumentation.testing.GlobalTraceUtil;
1112
import java.util.List;
@@ -39,13 +40,13 @@ record -> {
3940
});
4041
}
4142

42-
public static void reset() {
43-
messageReceived = new CountDownLatch(2);
43+
public static void reset(int expectedMessages) {
44+
messageReceived = new CountDownLatch(expectedMessages);
4445
lastBatchSize.set(0);
4546
}
4647

4748
public static void waitForMessages() throws InterruptedException {
48-
messageReceived.await(30, SECONDS);
49+
assertThat(messageReceived.await(30, SECONDS)).isTrue();
4950
}
5051

5152
public static int getLastBatchSize() {

instrumentation/spring/spring-kafka-2.7/testing/src/main/java/io/opentelemetry/testing/ConsumerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ConcurrentKafkaListenerContainerFactory<String, String> singleFactory(
7272
// available since spring 2.8
7373
Class.forName("org.springframework.kafka.listener.CommonErrorHandler");
7474
ConsumerConfigUtil.addErrorHandler(factory);
75-
} catch (ClassNotFoundException e) {
75+
} catch (ClassNotFoundException ignored) {
7676
// ignore
7777
}
7878
customizerProvider.ifAvailable(factory::setContainerCustomizer);

0 commit comments

Comments
 (0)