-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test latest version of kafka client and streams (#3803)
- Loading branch information
Showing
12 changed files
with
1,029 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
instrumentation/kafka-clients-0.11/kafka-clients-2.4.0-testing/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
plugins { | ||
id("otel.javaagent-testing") | ||
} | ||
|
||
dependencies { | ||
library("org.apache.kafka:kafka-clients:2.4.0") | ||
|
||
testInstrumentation(project(":instrumentation:kafka-clients-0.11:javaagent")) | ||
|
||
testLibrary("org.springframework.kafka:spring-kafka:2.4.0.RELEASE") | ||
testLibrary("org.springframework.kafka:spring-kafka-test:2.4.0.RELEASE") | ||
testLibrary("org.springframework:spring-core:5.2.9.RELEASE") | ||
testImplementation("javax.xml.bind:jaxb-api:2.2.3") | ||
|
||
latestDepTestLibrary("org.apache.kafka:kafka_2.13:+") | ||
} | ||
|
||
tasks { | ||
withType<Test>().configureEach { | ||
// TODO run tests both with and without experimental span attributes | ||
jvmArgs("-Dotel.instrumentation.kafka.experimental-span-attributes=true") | ||
} | ||
|
||
val testPropagationDisabled by registering(Test::class) { | ||
filter { | ||
includeTestsMatching("KafkaClientPropagationDisabledTest") | ||
isFailOnNoMatchingTests = false | ||
} | ||
include("**/KafkaClientPropagationDisabledTest.*") | ||
jvmArgs("-Dotel.instrumentation.kafka.client-propagation.enabled=false") | ||
} | ||
|
||
named<Test>("test") { | ||
dependsOn(testPropagationDisabled) | ||
filter { | ||
excludeTestsMatching("KafkaClientPropagationDisabledTest") | ||
isFailOnNoMatchingTests = false | ||
} | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...kafka-clients-0.11/kafka-clients-2.4.0-testing/src/test/groovy/KafkaClientBaseTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification | ||
import java.util.concurrent.LinkedBlockingQueue | ||
import java.util.concurrent.TimeUnit | ||
import org.apache.kafka.clients.consumer.ConsumerRecord | ||
import org.junit.Rule | ||
import org.springframework.kafka.core.DefaultKafkaConsumerFactory | ||
import org.springframework.kafka.core.DefaultKafkaProducerFactory | ||
import org.springframework.kafka.core.KafkaTemplate | ||
import org.springframework.kafka.listener.KafkaMessageListenerContainer | ||
import org.springframework.kafka.listener.MessageListener | ||
import org.springframework.kafka.test.rule.EmbeddedKafkaRule | ||
import org.springframework.kafka.test.utils.ContainerTestUtils | ||
import org.springframework.kafka.test.utils.KafkaTestUtils | ||
import spock.lang.Unroll | ||
|
||
abstract class KafkaClientBaseTest extends AgentInstrumentationSpecification { | ||
|
||
protected static final SHARED_TOPIC = "shared.topic" | ||
|
||
private static final boolean propagationEnabled = Boolean.parseBoolean( | ||
System.getProperty("otel.instrumentation.kafka.client-propagation.enabled", "true")) | ||
|
||
@Rule | ||
EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, true, SHARED_TOPIC) | ||
|
||
abstract containerProperties() | ||
|
||
Map<String, Object> senderProps() { | ||
return KafkaTestUtils.producerProps(embeddedKafka.getEmbeddedKafka().getBrokersAsString()) | ||
} | ||
|
||
Map<String, Object> consumerProps(String group, String autoCommit) { | ||
return KafkaTestUtils.consumerProps(group, autoCommit, embeddedKafka.getEmbeddedKafka()) | ||
} | ||
|
||
void waitForAssignment(Object container) { | ||
ContainerTestUtils.waitForAssignment(container, embeddedKafka.getEmbeddedKafka().getPartitionsPerTopic()) | ||
} | ||
|
||
def stopProducerFactory(DefaultKafkaProducerFactory producerFactory) { | ||
producerFactory.destroy() | ||
} | ||
|
||
@Unroll | ||
def "test kafka client header propagation manual config"() { | ||
setup: | ||
def senderProps = senderProps() | ||
def producerFactory = new DefaultKafkaProducerFactory<String, String>(senderProps) | ||
def kafkaTemplate = new KafkaTemplate<String, String>(producerFactory) | ||
|
||
// set up the Kafka consumer properties | ||
def consumerProperties = consumerProps("sender", "false") | ||
|
||
// create a Kafka consumer factory | ||
def consumerFactory = new DefaultKafkaConsumerFactory<String, String>(consumerProperties) | ||
|
||
// set the topic that needs to be consumed | ||
def containerProperties = containerProperties() | ||
|
||
// create a Kafka MessageListenerContainer | ||
def container = new KafkaMessageListenerContainer<>(consumerFactory, containerProperties) | ||
|
||
// create a thread safe queue to store the received message | ||
def records = new LinkedBlockingQueue<ConsumerRecord<String, String>>() | ||
|
||
// setup a Kafka message listener | ||
container.setupMessageListener(new MessageListener<String, String>() { | ||
@Override | ||
void onMessage(ConsumerRecord<String, String> record) { | ||
records.add(record) | ||
} | ||
}) | ||
|
||
// start the container and underlying message listener | ||
container.start() | ||
|
||
// wait until the container has the required number of assigned partitions | ||
waitForAssignment(container) | ||
|
||
when: | ||
String message = "Testing without headers" | ||
kafkaTemplate.send(SHARED_TOPIC, message) | ||
|
||
then: | ||
// check that the message was received | ||
def received = records.poll(5, TimeUnit.SECONDS) | ||
|
||
received.headers().iterator().hasNext() == propagationEnabled | ||
|
||
cleanup: | ||
stopProducerFactory(producerFactory) | ||
container?.stop() | ||
} | ||
} |
Oops, something went wrong.