Skip to content

Commit b2d4035

Browse files
committed
Remove ParameterizedTest
1 parent a2b2abd commit b2d4035

File tree

7 files changed

+61
-89
lines changed

7 files changed

+61
-89
lines changed

instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/v0_11/KafkaClientDefaultTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void testKafkaProducerAndConsumerSpan(boolean testHeaders) throws Exception {
108108
.hasLinks(LinkData.create(producerSpan.get().getSpanContext()))
109109
.hasParent(trace.getSpan(0))
110110
.hasAttributesSatisfyingExactly(
111-
processAttributes("10", greeting, testHeaders)),
111+
processAttributes("10", greeting, testHeaders, false)),
112112
span -> span.hasName("processing").hasParent(trace.getSpan(1))));
113113
}
114114

@@ -152,7 +152,8 @@ void testPassThroughTombstone()
152152
.hasKind(SpanKind.CONSUMER)
153153
.hasLinks(LinkData.create(producerSpan.get().getSpanContext()))
154154
.hasParent(trace.getSpan(0))
155-
.hasAttributesSatisfyingExactly(processAttributes(null, null, false))));
155+
.hasAttributesSatisfyingExactly(
156+
processAttributes(null, null, false, false))));
156157
}
157158

158159
@DisplayName("test records(TopicPartition) kafka consume")
@@ -203,6 +204,7 @@ void testRecordsWithTopicPartitionKafkaConsume()
203204
.hasKind(SpanKind.CONSUMER)
204205
.hasLinks(LinkData.create(producerSpan.get().getSpanContext()))
205206
.hasParent(trace.getSpan(0))
206-
.hasAttributesSatisfyingExactly(processAttributes(null, greeting, false))));
207+
.hasAttributesSatisfyingExactly(
208+
processAttributes(null, greeting, false, false))));
207209
}
208210
}

instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/v0_11/KafkaClientPropagationDisabledTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ void testReadRemoteContextWhenPropagationIsDisabled() throws InterruptedExceptio
6464
span.hasName(SHARED_TOPIC + " process")
6565
.hasKind(SpanKind.CONSUMER)
6666
.hasLinks(Collections.emptyList())
67-
.hasAttributesSatisfyingExactly(processAttributes(null, message, false)),
67+
.hasAttributesSatisfyingExactly(
68+
processAttributes(null, message, false, false)),
6869
span -> span.hasName("processing").hasParent(trace.getSpan(0))));
6970
}
7071
}

instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/v0_11/KafkaClientSuppressReceiveSpansTest.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
import org.apache.kafka.clients.producer.ProducerRecord;
2424
import org.junit.jupiter.api.Test;
2525
import org.junit.jupiter.api.extension.RegisterExtension;
26-
import org.junit.jupiter.params.ParameterizedTest;
27-
import org.junit.jupiter.params.provider.ValueSource;
2826

2927
class KafkaClientSuppressReceiveSpansTest extends KafkaClientPropagationBaseTest {
3028
@RegisterExtension
3129
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
3230

33-
@ParameterizedTest
34-
@ValueSource(strings = {"testSingleBaggage", "testMultiBaggage"})
35-
void testKafkaProduceAndConsume(String testBaggageKind) throws InterruptedException {
31+
@Test
32+
void testKafkaProduceAndConsume() throws InterruptedException {
3633
String greeting = "Hello Kafka!";
3734
testing.runWithSpan(
3835
"parent",
@@ -44,14 +41,10 @@ void testKafkaProduceAndConsume(String testBaggageKind) throws InterruptedExcept
4441
// adding baggage header in w3c baggage format
4542
.add(
4643
"baggage",
47-
"test-baggage-key-1=test-baggage-value-1".getBytes(StandardCharsets.UTF_8));
48-
if (testBaggageKind.equals("testMultiBaggage")) {
49-
producerRecord
50-
.headers()
51-
.add(
52-
"baggage",
53-
"test-baggage-key-2=test-baggage-value-2".getBytes(StandardCharsets.UTF_8));
54-
}
44+
"test-baggage-key-1=test-baggage-value-1".getBytes(StandardCharsets.UTF_8))
45+
.add(
46+
"baggage",
47+
"test-baggage-key-2=test-baggage-value-2".getBytes(StandardCharsets.UTF_8));
5548
producer.send(
5649
producerRecord,
5750
(meta, ex) -> {
@@ -90,7 +83,7 @@ void testKafkaProduceAndConsume(String testBaggageKind) throws InterruptedExcept
9083
.hasKind(SpanKind.CONSUMER)
9184
.hasParent(trace.getSpan(1))
9285
.hasAttributesSatisfyingExactly(
93-
processAttributes("10", greeting, false, testBaggageKind)),
86+
processAttributes("10", greeting, false, true)),
9487
span ->
9588
span.hasName("processing")
9689
.hasKind(SpanKind.INTERNAL)
@@ -128,7 +121,8 @@ void testPassThroughTombstone()
128121
span.hasName(SHARED_TOPIC + " process")
129122
.hasKind(SpanKind.CONSUMER)
130123
.hasParent(trace.getSpan(0))
131-
.hasAttributesSatisfyingExactly(processAttributes(null, null, false))));
124+
.hasAttributesSatisfyingExactly(
125+
processAttributes(null, null, false, false))));
132126
}
133127

134128
@Test
@@ -166,6 +160,7 @@ void testRecordsWithTopicPartitionKafkaConsume()
166160
span.hasName(SHARED_TOPIC + " process")
167161
.hasKind(SpanKind.CONSUMER)
168162
.hasParent(trace.getSpan(0))
169-
.hasAttributesSatisfyingExactly(processAttributes(null, greeting, false))));
163+
.hasAttributesSatisfyingExactly(
164+
processAttributes(null, greeting, false, false))));
170165
}
171166
}

instrumentation/kafka/kafka-clients/kafka-clients-0.11/testing/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaClientBaseTest.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected static List<AttributeAssertion> receiveAttributes(boolean testHeaders)
216216

217217
@SuppressWarnings("deprecation") // using deprecated semconv
218218
protected static List<AttributeAssertion> processAttributes(
219-
String messageKey, String messageValue, boolean testHeaders) {
219+
String messageKey, String messageValue, boolean testHeaders, boolean testMultiBaggage) {
220220
List<AttributeAssertion> assertions =
221221
new ArrayList<>(
222222
Arrays.asList(
@@ -249,28 +249,11 @@ protected static List<AttributeAssertion> processAttributes(
249249
AttributeKey.stringArrayKey("messaging.header.test_message_header"),
250250
Collections.singletonList("test")));
251251
}
252-
return assertions;
253-
}
254252

255-
protected static List<AttributeAssertion> processAttributes(
256-
String messageKey, String messageValue, boolean testHeaders, String testBaggageKind) {
257-
List<AttributeAssertion> attributeAssertions =
258-
processAttributes(messageKey, messageValue, testHeaders);
259-
attributeAssertions.addAll(processAttributes(testBaggageKind));
260-
return attributeAssertions;
261-
}
262-
263-
protected static List<AttributeAssertion> processAttributes(String testBaggageKind) {
264-
switch (testBaggageKind) {
265-
case "testSingleBaggage":
266-
return Collections.singletonList(
267-
equalTo(AttributeKey.stringKey("test-baggage-key-1"), "test-baggage-value-1"));
268-
case "testMultiBaggage":
269-
return Arrays.asList(
270-
equalTo(AttributeKey.stringKey("test-baggage-key-1"), "test-baggage-value-1"),
271-
equalTo(AttributeKey.stringKey("test-baggage-key-2"), "test-baggage-value-2"));
272-
default:
273-
throw new IllegalArgumentException("Unknown testBaggageKind: " + testBaggageKind);
253+
if (testMultiBaggage) {
254+
assertions.add(equalTo(AttributeKey.stringKey("test-baggage-key-1"), "test-baggage-value-1"));
255+
assertions.add(equalTo(AttributeKey.stringKey("test-baggage-key-2"), "test-baggage-value-2"));
274256
}
257+
return assertions;
275258
}
276259
}

instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/java/io/opentelemetry/instrumentation/kafkaclients/v2_6/AbstractInterceptorsTest.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
import org.apache.kafka.clients.consumer.ConsumerRecords;
1919
import org.apache.kafka.clients.producer.ProducerConfig;
2020
import org.apache.kafka.clients.producer.ProducerRecord;
21+
import org.junit.jupiter.api.Test;
2122
import org.junit.jupiter.api.extension.RegisterExtension;
22-
import org.junit.jupiter.params.ParameterizedTest;
23-
import org.junit.jupiter.params.provider.ValueSource;
2423

2524
abstract class AbstractInterceptorsTest extends KafkaClientBaseTest {
2625

@@ -45,9 +44,8 @@ public Map<String, Object> consumerProps() {
4544
return props;
4645
}
4746

48-
@ParameterizedTest
49-
@ValueSource(strings = {"testSingleBaggage", "testMultiBaggage"})
50-
void testInterceptors(String testBaggageKind) throws InterruptedException {
47+
@Test
48+
void testInterceptors() throws InterruptedException {
5149
testing.runWithSpan(
5250
"parent",
5351
() -> {
@@ -58,14 +56,10 @@ void testInterceptors(String testBaggageKind) throws InterruptedException {
5856
// adding baggage header in w3c baggage format
5957
.add(
6058
"baggage",
61-
"test-baggage-key-1=test-baggage-value-1".getBytes(StandardCharsets.UTF_8));
62-
if (testBaggageKind.equals("testMultiBaggage")) {
63-
producerRecord
64-
.headers()
65-
.add(
66-
"baggage",
67-
"test-baggage-key-2=test-baggage-value-2".getBytes(StandardCharsets.UTF_8));
68-
}
59+
"test-baggage-key-1=test-baggage-value-1".getBytes(StandardCharsets.UTF_8))
60+
.add(
61+
"baggage",
62+
"test-baggage-key-2=test-baggage-value-2".getBytes(StandardCharsets.UTF_8));
6963
producer.send(
7064
producerRecord,
7165
(meta, ex) -> {
@@ -87,8 +81,8 @@ void testInterceptors(String testBaggageKind) throws InterruptedException {
8781
testing.runWithSpan("process child", () -> {});
8882
}
8983

90-
assertTraces(testBaggageKind);
84+
assertTraces();
9185
}
9286

93-
abstract void assertTraces(String testBaggageKind);
87+
abstract void assertTraces();
9488
}

instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/java/io/opentelemetry/instrumentation/kafkaclients/v2_6/InterceptorsSuppressReceiveSpansTest.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@
1414
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_MESSAGE_BODY_SIZE;
1515
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
1616
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
17-
import static java.util.Arrays.asList;
1817

18+
import io.opentelemetry.api.common.AttributeKey;
1919
import io.opentelemetry.api.trace.SpanKind;
20-
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
2120
import java.nio.charset.StandardCharsets;
22-
import java.util.ArrayList;
23-
import java.util.List;
2421
import org.assertj.core.api.AbstractLongAssert;
2522
import org.assertj.core.api.AbstractStringAssert;
2623

2724
class InterceptorsSuppressReceiveSpansTest extends AbstractInterceptorsTest {
2825

2926
@SuppressWarnings("deprecation") // using deprecated semconv
3027
@Override
31-
void assertTraces(String testBaggageKind) {
28+
void assertTraces() {
3229
testing.waitAndAssertTraces(
3330
trace ->
3431
trace.hasSpansSatisfyingExactly(
@@ -44,32 +41,32 @@ void assertTraces(String testBaggageKind) {
4441
satisfies(
4542
MESSAGING_CLIENT_ID,
4643
stringAssert -> stringAssert.startsWith("producer"))),
47-
span -> {
48-
List<AttributeAssertion> assertions =
49-
new ArrayList<>(
50-
asList(
51-
equalTo(MESSAGING_SYSTEM, "kafka"),
52-
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
53-
equalTo(MESSAGING_OPERATION, "process"),
54-
equalTo(
55-
MESSAGING_MESSAGE_BODY_SIZE,
56-
greeting.getBytes(StandardCharsets.UTF_8).length),
57-
satisfies(
58-
MESSAGING_DESTINATION_PARTITION_ID,
59-
AbstractStringAssert::isNotEmpty),
60-
satisfies(
61-
MESSAGING_KAFKA_MESSAGE_OFFSET,
62-
AbstractLongAssert::isNotNegative),
63-
equalTo(MESSAGING_KAFKA_CONSUMER_GROUP, "test"),
64-
satisfies(
65-
MESSAGING_CLIENT_ID,
66-
stringAssert -> stringAssert.startsWith("consumer"))));
67-
assertions.addAll(processAttributes(testBaggageKind));
68-
span.hasName(SHARED_TOPIC + " process")
69-
.hasKind(SpanKind.CONSUMER)
70-
.hasParent(trace.getSpan(1))
71-
.hasAttributesSatisfyingExactly(assertions);
72-
},
44+
span ->
45+
span.hasName(SHARED_TOPIC + " process")
46+
.hasKind(SpanKind.CONSUMER)
47+
.hasParent(trace.getSpan(1))
48+
.hasAttributesSatisfyingExactly(
49+
equalTo(MESSAGING_SYSTEM, "kafka"),
50+
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
51+
equalTo(MESSAGING_OPERATION, "process"),
52+
equalTo(
53+
MESSAGING_MESSAGE_BODY_SIZE,
54+
greeting.getBytes(StandardCharsets.UTF_8).length),
55+
satisfies(
56+
MESSAGING_DESTINATION_PARTITION_ID,
57+
AbstractStringAssert::isNotEmpty),
58+
satisfies(
59+
MESSAGING_KAFKA_MESSAGE_OFFSET, AbstractLongAssert::isNotNegative),
60+
equalTo(MESSAGING_KAFKA_CONSUMER_GROUP, "test"),
61+
satisfies(
62+
MESSAGING_CLIENT_ID,
63+
stringAssert -> stringAssert.startsWith("consumer")),
64+
equalTo(
65+
AttributeKey.stringKey("test-baggage-key-1"),
66+
"test-baggage-value-1"),
67+
equalTo(
68+
AttributeKey.stringKey("test-baggage-key-2"),
69+
"test-baggage-value-2")),
7370
span ->
7471
span.hasName("process child")
7572
.hasKind(SpanKind.INTERNAL)

instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/java/io/opentelemetry/instrumentation/kafkaclients/v2_6/InterceptorsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class InterceptorsTest extends AbstractInterceptorsTest {
3030

3131
@SuppressWarnings("deprecation") // using deprecated semconv
3232
@Override
33-
void assertTraces(String unused) {
33+
void assertTraces() {
3434
AtomicReference<SpanContext> producerSpanContext = new AtomicReference<>();
3535
testing.waitAndAssertSortedTraces(
3636
orderByRootSpanName("parent", SHARED_TOPIC + " receive", "producer callback"),

0 commit comments

Comments
 (0)