-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for ArC fix when a framework bean uses the decorator
This adding the coverage for https://issues.redhat.com/browse/QUARKUS-5178 It's tested with Quarkiverse extension as the reproducer attached in issue and it was only scenario which I was able to reproduce. To test this you need external lib which contains class (lib_class) implementing the interface. This interface is also aplied on class anotated as decorator in Quarkus app when the bean of lib_class is injected at the same time. This error happen randomly in dev/test mode. The Quarkus PR is quarkusio/quarkus#43245
- Loading branch information
Showing
7 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<properties> | ||
<!-- Need to be this version, I wasn't able to reproduce QUARKUS-5178 on newer versions--> | ||
<quarkus-kafka-streams-processor.version>2.0.1</quarkus-kafka-streams-processor.version> | ||
</properties> | ||
<artifactId>kafka-processor</artifactId> | ||
<name>Quarkus QE TS: Messaging: Reactive Processor Quarkiverse</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkiverse.kafkastreamsprocessor</groupId> | ||
<artifactId>quarkus-kafka-streams-processor-api</artifactId> | ||
<version>${quarkus-kafka-streams-processor.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkiverse.kafkastreamsprocessor</groupId> | ||
<artifactId>quarkus-kafka-streams-processor-impl</artifactId> | ||
<version>${quarkus-kafka-streams-processor.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkiverse.kafkastreamsprocessor</groupId> | ||
<artifactId>quarkus-kafka-streams-processor</artifactId> | ||
<version>${quarkus-kafka-streams-processor.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
37 changes: 37 additions & 0 deletions
37
...ssor/src/main/java/io/quarkus/ts/messaging/kafka/processor/decorator/HeaderDecorator.java
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,37 @@ | ||
package io.quarkus.ts.messaging.kafka.processor.decorator; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.decorator.Decorator; | ||
import jakarta.decorator.Delegate; | ||
import jakarta.inject.Inject; | ||
|
||
import org.apache.kafka.common.header.Header; | ||
import org.apache.kafka.streams.processor.api.Processor; | ||
import org.apache.kafka.streams.processor.api.Record; | ||
|
||
import io.quarkiverse.kafkastreamsprocessor.api.decorator.processor.ProcessorDecoratorPriorities; | ||
|
||
@Decorator | ||
@Priority(ProcessorDecoratorPriorities.PUNCTUATOR_DECORATION + 2) | ||
public class HeaderDecorator<KIn, VIn, KOut, VOut> implements Processor<KIn, VIn, KOut, VOut> { | ||
private final Processor<KIn, VIn, KOut, VOut> delegate; | ||
|
||
@Inject | ||
public HeaderDecorator(@Delegate Processor<KIn, VIn, KOut, VOut> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void process(Record<KIn, VIn> record) { | ||
Header header = record.headers().lastHeader("custom-header"); | ||
if (header != null) { | ||
String value = new String(header.value(), StandardCharsets.UTF_8); | ||
if (value.contains("error")) { | ||
throw new IllegalStateException("Error in header"); | ||
} | ||
} | ||
delegate.process(record); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...cessor/src/main/java/io/quarkus/ts/messaging/kafka/processor/processor/PingProcessor.java
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,15 @@ | ||
package io.quarkus.ts.messaging.kafka.processor.processor; | ||
|
||
import org.apache.kafka.streams.processor.api.ContextualProcessor; | ||
import org.apache.kafka.streams.processor.api.Record; | ||
|
||
import io.quarkiverse.kafkastreamsprocessor.api.Processor; | ||
|
||
@Processor | ||
public class PingProcessor extends ContextualProcessor<String, String, String, String> { | ||
|
||
@Override | ||
public void process(Record<String, String> ping) { | ||
context().forward(ping); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
messaging/kafka-processor/src/main/resources/application.properties
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,3 @@ | ||
kafkastreamsprocessor.input.topic=ping-events | ||
kafkastreamsprocessor.output.topic=pong-events | ||
quarkus.kafka-streams.topics=ping-events,pong-events |
34 changes: 34 additions & 0 deletions
34
...cessor/src/test/java/io/quarkus/ts/messaging/kafka/processor/DevModeKafkaProcessorIT.java
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,34 @@ | ||
package io.quarkus.ts.messaging.kafka.processor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.DevModeQuarkusApplication; | ||
import io.quarkus.ts.messaging.kafka.processor.decorator.HeaderDecorator; | ||
|
||
@Tag("QUARKUS-5178") | ||
@QuarkusScenario | ||
public class DevModeKafkaProcessorIT { | ||
|
||
@DevModeQuarkusApplication | ||
static RestService app = new RestService().setAutoStart(false); | ||
|
||
/** | ||
* The QUARKUS-5178 was caused only in dev mode and not all the time. | ||
* The selected 5 runs start stops should be enough to detect the original issue | ||
*/ | ||
@Test | ||
public void quarkusShouldStartWithoutFailTest() { | ||
// As QUARKUS-5178 not occurring all the time so occasionally we need to check the dev mode multiple time | ||
for (int i = 0; i < 5; i++) { | ||
assertDoesNotThrow(() -> app.start(), | ||
"The QUARKUS-5178 is probably not fixed"); | ||
app.logs().assertDoesNotContain("java.lang.ClassNotFoundException: " + HeaderDecorator.class.getName()); | ||
app.stop(); | ||
} | ||
} | ||
} |
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