Skip to content

Commit

Permalink
feat: #85 Fix Kafka interceptor without Spring and add a consumer int…
Browse files Browse the repository at this point in the history
…erceptor
  • Loading branch information
lukasz-gryzbon committed Aug 12, 2024
1 parent 164c1ab commit 2d9b9a7
Show file tree
Hide file tree
Showing 36 changed files with 1,269 additions and 85 deletions.
2 changes: 1 addition & 1 deletion core/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies {

// LSD
compileOnly 'io.github.lsd-consulting:lsd-distributed-connector:2.0.0'
implementation 'io.github.lsd-consulting:lsd-formatting-library:4.0.46'
implementation 'io.github.lsd-consulting:lsd-formatting-library:4.0.47'
implementation 'io.github.lsd-consulting:lsd-logging-library:1.0.1'

// JSON & XML pretty formatting
Expand Down
12 changes: 6 additions & 6 deletions core/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
jacocoTestReport {
reports {
xml.enabled(true)
html.enabled(true)
html.destination(project.provider(() -> new File("${project.buildDir}/reports/coverage")))
xml.required = true
html.required = true
html.getOutputLocation().set( new File("${project.layout.buildDirectory}/reports/coverage"))
}
executionData(
file("${project.buildDir}/jacoco/test.exec"),
file("${project.buildDir}/jacoco/integrationMongoTest.exec"),
file("${project.buildDir}/jacoco/integrationHttpTest.exec")
file("${project.layout.buildDirectory}/jacoco/test.exec"),
file("${project.layout.buildDirectory}/jacoco/integrationMongoTest.exec"),
file("${project.layout.buildDirectory}/jacoco/integrationHttpTest.exec")
)
}
2 changes: 1 addition & 1 deletion feign/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
because "We need to load properties for the non-spring option"
}
implementation 'io.github.lsd-consulting:lsd-logging-library:1.0.1'
implementation('io.github.lsd-consulting:lsd-formatting-library:4.0.2') {
implementation('io.github.lsd-consulting:lsd-formatting-library:4.0.47') {
because "We need the LSD objectMapper"
}
compileOnly 'io.github.lsd-consulting:lsd-distributed-mongodb-connector:5.0.0'
Expand Down
12 changes: 6 additions & 6 deletions feign/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
jacocoTestReport {
reports {
xml.enabled(true)
html.enabled(true)
html.destination(project.provider(() -> new File("${project.buildDir}/reports/coverage")))
xml.required = true
html.required = true
html.getOutputLocation().set( new File("${project.layout.buildDirectory}/reports/coverage"))
}
executionData(
file("${project.buildDir}/jacoco/test.exec"),
file("${project.buildDir}/jacoco/integrationMongoTest.exec"),
file("${project.buildDir}/jacoco/integrationHttpTest.exec")
file("${project.layout.buildDirectory}/jacoco/test.exec"),
file("${project.layout.buildDirectory}/jacoco/integrationMongoTest.exec"),
file("${project.layout.buildDirectory}/jacoco/integrationHttpTest.exec")
)
}
12 changes: 6 additions & 6 deletions rabbitmq/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
jacocoTestReport {
reports {
xml.enabled(true)
html.enabled(true)
html.destination(project.provider(() -> new File("${project.buildDir}/reports/coverage")))
xml.required = true
html.required = true
html.getOutputLocation().set( new File("${project.layout.buildDirectory}/reports/coverage"))
}
executionData(
file("${project.buildDir}/jacoco/test.exec"),
file("${project.buildDir}/jacoco/integrationMongoTest.exec"),
file("${project.buildDir}/jacoco/integrationHttpTest.exec")
file("${project.layout.buildDirectory}/jacoco/test.exec"),
file("${project.layout.buildDirectory}/jacoco/integrationMongoTest.exec"),
file("${project.layout.buildDirectory}/jacoco/integrationHttpTest.exec")
)
}
2 changes: 2 additions & 0 deletions spring-kafka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ apply from: 'dependencies.gradle'
apply from: 'test.gradle'
apply from: 'jacoco.gradle'
apply from: 'pitest.gradle'
apply from: 'integrationHttpTest.gradle'
apply from: 'springIntegrationHttpTest.gradle'

kotlin {
jvmToolchain(17)
Expand Down
11 changes: 8 additions & 3 deletions spring-kafka/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ dependencies {
because "We need to load properties for the non-spring option"
}
implementation 'io.github.lsd-consulting:lsd-logging-library:1.0.1'
implementation('io.github.lsd-consulting:lsd-formatting-library:4.0.2') {
implementation('io.github.lsd-consulting:lsd-formatting-library:4.0.47') {
because "We need the LSD objectMapper"
}
compileOnly 'io.github.lsd-consulting:lsd-distributed-mongodb-connector:5.0.0'
compileOnly 'io.github.lsd-consulting:lsd-distributed-postgres-connector:1.0.3'
compileOnly 'io.github.lsd-consulting:lsd-distributed-http-connector:3.0.2'

// JSON & XML pretty formatting
implementation 'org.dom4j:dom4j:2.1.3'
implementation('org.dom4j:dom4j:2.1.4') {
exclude group: 'pull-parser', module: 'pull-parser'
because "because pull-parser doesn't support the external-general-entities feature required by Logback"
}
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2'

// Avro
implementation 'org.apache.avro:avro:1.11.3'

// Other
implementation 'org.slf4j:slf4j-api:2.0.7'
// implementation 'org.slf4j:slf4j-api:2.0.16'
// implementation 'ch.qos.logback:logback-core:1.5.6'
// implementation 'ch.qos.logback:logback-classic:1.5.6'
}
51 changes: 51 additions & 0 deletions spring-kafka/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.2.1
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: confluentinc/cp-kafka:7.2.1
hostname: kafka
container_name: kafka
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
KAFKA_CONFLUENT_BALANCER_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_CONFLUENT_SCHEMA_REGISTRY_URL: http://schema-registry:8081
kafka-ui:
container_name: kafka-ui
image: provectuslabs/kafka-ui:latest
ports:
- 8888:8080
environment:
DYNAMIC_CONFIG_ENABLED: true
KAFKA_CLUSTERS_0_NAME: spring_kafka_test
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
volumes:
- ./kui/config.yml:/etc/kafkaui/dynamic_config.yaml
healthy:
image: busybox
restart: "no"
container_name: health_checker
depends_on:
zookeeper:
condition: service_started
kafka:
condition: service_started
kafka-ui:
condition: service_started
65 changes: 65 additions & 0 deletions spring-kafka/integrationHttpTest.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
sourceSets {
integrationHttpTest {
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/integrationHttpTest/java')
}
}
}

configurations {
integrationHttpTestImplementation.extendsFrom implementation
}

dependencies {

// Spring
integrationHttpTestImplementation 'org.springframework.boot:spring-boot-starter-test'
integrationHttpTestImplementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
integrationHttpTestImplementation 'org.springframework.boot:spring-boot-starter-web'
integrationHttpTestImplementation 'org.springframework.kafka:spring-kafka'
integrationHttpTestImplementation 'org.springframework.kafka:spring-kafka-test'

// Other
integrationHttpTestImplementation 'org.awaitility:awaitility:4.1.0'
integrationHttpTestImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.0'
integrationHttpTestImplementation 'org.jeasy:easy-random-core:5.0.0'

// LSD
integrationHttpTestImplementation 'io.github.lsd-consulting:lsd-distributed-http-connector:3.0.1'
integrationHttpTestImplementation('io.github.lsd-consulting:lsd-distributed-generator-ui-service:6.0.2:wiremock-stubs'){
exclude group: "*", module: "*"
}

integrationHttpTestImplementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.1'

// integrationHttpTestImplementation 'ch.qos.logback:logback-core:1.5.6'
// integrationHttpTestImplementation 'ch.qos.logback:logback-classic:1.5.6'
// integrationHttpTestImplementation 'org.slf4j:slf4j-api:2.0.16'
}

tasks.register('integrationHttpTest', Test) {
useJUnitPlatform()
dependsOn assemble

testClassesDirs = sourceSets.integrationHttpTest.output.classesDirs
classpath = sourceSets.integrationHttpTest.runtimeClasspath
outputs.upToDateWhen { false }
testLogging.showStandardStreams = false
mustRunAfter(test)
finalizedBy jacocoTestReport
}

check.dependsOn(integrationHttpTest)

integrationHttpTest {
afterSuite { desc, result ->
if (!desc.parent) {
println "Http integration test results: (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
if (result.testCount == 0) {
throw new IllegalStateException("No tests were found. Failing the build")
}
}
}
}
10 changes: 6 additions & 4 deletions spring-kafka/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
jacocoTestReport {
reports {
xml.enabled(true)
html.enabled(true)
html.destination(project.provider(() -> new File("${project.buildDir}/reports/coverage")))
xml.required = true
html.required = true
html.getOutputLocation().set( new File("${project.layout.buildDirectory}/reports/coverage"))
}
executionData(
file("${project.buildDir}/jacoco/test.exec")
file("${project.layout.buildDirectory}/jacoco/test.exec"),
file("${project.layout.buildDirectory}/jacoco/integrationHttpTest.exec"),
file("${project.layout.buildDirectory}/jacoco/springIntegrationHttpTest.exec")
)
}
11 changes: 7 additions & 4 deletions spring-kafka/pitest.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ build.dependsOn "pitest"

// perform mutation test and enforce coverage
pitest {
junit5PluginVersion = '1.1.0'
junit5PluginVersion = '1.2.1'
pitestVersion = '1.15.0'
useClasspathFile = true
timeoutConstInMillis = 20000
targetTests.set([
'io.lsdconsulting.lsd.distributed.interceptor.captor.**'
])
targetClasses.set([
'io.lsdconsulting.lsd.distributed.interceptor.*'
])
excludedClasses.set([
'io.lsdconsulting.lsd.distributed.interceptor.interceptor.*',
'io.lsdconsulting.lsd.distributed.interceptor.config.*'
])
threads = 4
outputFormats.set(['HTML'])
coverageThreshold = 77
mutationThreshold = 44
coverageThreshold = 25
mutationThreshold = 16
testStrengthThreshold = 58
}
65 changes: 65 additions & 0 deletions spring-kafka/springIntegrationHttpTest.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
sourceSets {
springIntegrationHttpTest {
java {
compileClasspath += main.output
runtimeClasspath += main.output
srcDir file('src/springIntegrationHttpTest/java')
}
}
}

configurations {
springIntegrationHttpTestImplementation.extendsFrom implementation
}

dependencies {

// Spring
springIntegrationHttpTestImplementation 'org.springframework.boot:spring-boot-starter-test'
springIntegrationHttpTestImplementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
springIntegrationHttpTestImplementation 'org.springframework.boot:spring-boot-starter-web'
springIntegrationHttpTestImplementation 'org.springframework.kafka:spring-kafka'
springIntegrationHttpTestImplementation 'org.springframework.kafka:spring-kafka-test'

// Other
springIntegrationHttpTestImplementation 'org.awaitility:awaitility:4.1.0'
springIntegrationHttpTestImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.0'
springIntegrationHttpTestImplementation 'org.jeasy:easy-random-core:5.0.0'

// LSD
springIntegrationHttpTestImplementation 'io.github.lsd-consulting:lsd-distributed-http-connector:3.0.1'
springIntegrationHttpTestImplementation('io.github.lsd-consulting:lsd-distributed-generator-ui-service:6.0.2:wiremock-stubs'){
exclude group: "*", module: "*"
}

springIntegrationHttpTestImplementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.1'

// springIntegrationHttpTestImplementation 'ch.qos.logback:logback-core:1.5.6'
// springIntegrationHttpTestImplementation 'ch.qos.logback:logback-classic:1.5.6'
// springIntegrationHttpTestImplementation 'org.slf4j:slf4j-api:2.0.16'
}

tasks.register('springIntegrationHttpTest', Test) {
useJUnitPlatform()
dependsOn assemble

testClassesDirs = sourceSets.springIntegrationHttpTest.output.classesDirs
classpath = sourceSets.springIntegrationHttpTest.runtimeClasspath
outputs.upToDateWhen { false }
testLogging.showStandardStreams = false
mustRunAfter(test)
finalizedBy jacocoTestReport
}

check.dependsOn(springIntegrationHttpTest)

springIntegrationHttpTest {
afterSuite { desc, result ->
if (!desc.parent) {
println "Http integration test results: (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
if (result.testCount == 0) {
throw new IllegalStateException("No tests were found. Failing the build")
}
}
}
}
Loading

0 comments on commit 2d9b9a7

Please sign in to comment.