-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from flazarus1A/feature/Add-retry-configmapping
feat(config): Add Retry configmapping object
- Loading branch information
Showing
14 changed files
with
421 additions
and
50 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
112 changes: 112 additions & 0 deletions
112
api/src/main/java/io/quarkiverse/kafkastreamsprocessor/api/properties/RetryConfig.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,112 @@ | ||
/*- | ||
* #%L | ||
* Quarkus Kafka Streams Processor | ||
* %% | ||
* Copyright (C) 2024 Amadeus s.a.s. | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package io.quarkiverse.kafkastreamsprocessor.api.properties; | ||
|
||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.microprofile.faulttolerance.Retry; | ||
|
||
import io.smallrye.config.WithDefault; | ||
|
||
public interface RetryConfig { | ||
|
||
/** | ||
* Max number of retries. | ||
* | ||
* @see Retry#maxRetries() | ||
*/ | ||
@WithDefault("-1") | ||
int maxRetries(); | ||
|
||
/** | ||
* The delay between retries. | ||
* | ||
* @see Retry#delay() | ||
*/ | ||
@WithDefault("0") | ||
long delay(); | ||
|
||
/** | ||
* The unit for {@link #delay()}. Default milliseconds. | ||
* | ||
* @see Retry#delayUnit() | ||
*/ | ||
@WithDefault("MILLIS") | ||
ChronoUnit delayUnit(); | ||
|
||
/** | ||
* The max duration. | ||
* | ||
* @see Retry#maxDuration() | ||
*/ | ||
@WithDefault("180000") | ||
long maxDuration(); | ||
|
||
/** | ||
* The duration unit for {@link #maxDuration()}. | ||
* <p> | ||
* Milliseconds by default. | ||
* </p> | ||
* | ||
* @see Retry#durationUnit() | ||
*/ | ||
@WithDefault("MILLIS") | ||
ChronoUnit durationUnit(); | ||
|
||
/** | ||
* Jitter value to randomly vary retry delays for. | ||
* | ||
* @see Retry#jitter() | ||
*/ | ||
@WithDefault("200") | ||
long jitter(); | ||
|
||
/** | ||
* The delay unit for {@link #jitter()}. Default is milliseconds. | ||
* | ||
* @see Retry#jitterDelayUnit() | ||
*/ | ||
@WithDefault("MILLIS") | ||
ChronoUnit jitterDelayUnit(); | ||
|
||
/** | ||
* The list of exception types that should trigger a retry. | ||
* <p> | ||
* Default is the provided {@link io.quarkiverse.kafkastreamsprocessor.api.exception.RetryableException}. | ||
* </p> | ||
* | ||
* @see Retry#retryOn() | ||
*/ | ||
@WithDefault("io.quarkiverse.kafkastreamsprocessor.api.exception.RetryableException") | ||
List<Class<? extends Throwable>> retryOn(); | ||
|
||
/** | ||
* The list of exception types that should <i>not</i> trigger a retry. | ||
* <p> | ||
* Default is empty list | ||
* </p> | ||
* | ||
* @see Retry#abortOn() | ||
*/ | ||
@WithDefault("") | ||
Optional<List<Class<? extends Throwable>>> abortOn(); | ||
} |
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
99 changes: 99 additions & 0 deletions
99
...kafkastreamsprocessor/kafka/streams/test/KafkaStreamsProcessorProcessorWithRetryTest.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,99 @@ | ||
/*- | ||
* #%L | ||
* Quarkus Kafka Streams Processor | ||
* %% | ||
* Copyright (C) 2024 Amadeus s.a.s. | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package io.quarkiverse.kafkastreamsprocessor.kafka.streams.test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.kafkastreamsprocessor.api.exception.RetryableException; | ||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class KafkaStreamsProcessorProcessorWithRetryTest { | ||
|
||
private static volatile List<ReflectiveClassBuildItem> registeredClasses; | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(io.quarkiverse.kafkastreamsprocessor.kafka.streams.test.MyProcessor.class)) | ||
.overrideConfigKey("kafkastreamsprocessor.input.topics", "ping-events") | ||
.overrideConfigKey("kafkastreamsprocessor.output.topic", "pong-events") | ||
.overrideConfigKey("quarkus.kafka-streams.topics", "ping-events,pong-events") | ||
.overrideConfigKey("kafkastreamsprocessor.retry.retry-on", | ||
"io.quarkiverse.kafkastreamsprocessor.kafka.streams.test.KafkaStreamsProcessorProcessorWithRetryTest$RetryException") | ||
.overrideConfigKey("kafkastreamsprocessor.retry.abort-on", | ||
"io.quarkiverse.kafkastreamsprocessor.kafka.streams.test.KafkaStreamsProcessorProcessorWithRetryTest$AbortException") | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
private static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return chainBuilder -> chainBuilder.addBuildStep( | ||
context -> { | ||
registeredClasses = context.consumeMulti(ReflectiveClassBuildItem.class); | ||
checkProperClassesAreRegistered(); | ||
}) | ||
.consumes(ReflectiveClassBuildItem.class) | ||
.produces(GeneratedResourceBuildItem.class) | ||
.build(); | ||
} | ||
|
||
private static void checkProperClassesAreRegistered() { | ||
assertNotNull(registeredClasses); | ||
|
||
List<String> allRegisteredClasses = registeredClasses.stream() | ||
.flatMap(c -> c.getClassNames().stream()) | ||
.collect(Collectors.toList()); | ||
|
||
assertThat(allRegisteredClasses, hasItem(MyProcessor.class.getName())); | ||
// Default retryOn exception for Fault Tolerance | ||
assertThat(allRegisteredClasses, hasItem(RetryableException.class.getName())); | ||
// Explicit retryOn & abortOn exceptions | ||
assertThat(allRegisteredClasses, hasItem(RetryException.class.getName())); | ||
assertThat(allRegisteredClasses, hasItem(AbortException.class.getName())); | ||
} | ||
|
||
@Test | ||
void shouldRegisterTypesForReflection() { | ||
// if it gets there, it succeeded | ||
assertNull(registeredClasses); | ||
} | ||
|
||
public static class RetryException { | ||
|
||
} | ||
|
||
public static class AbortException { | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.