Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rnschk committed May 24, 2021
2 parents c4ca18e + 06af0ec commit 2b1a1ec
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<description>This tool helps to control the retry-behaviour in external-task-handlers
based on the official java-client provided by Camunda BPM
</description>
<version>1.2.2</version>
<version>1.2.3</version>
<inceptionYear>2021</inceptionYear>

<organization>
Expand All @@ -37,18 +37,18 @@
<maven.compiler.target>8</maven.compiler.target>

<!-- versions -->
<spring-boot.version>2.4.5</spring-boot.version>
<spring-boot.version>2.5.0</spring-boot.version>
<external-task-client.version>7.15.0</external-task-client.version>
<commons-lang3.version>3.11</commons-lang3.version>
<junit.version>4.13.2</junit.version>
<mockito.version>3.9.0</mockito.version>
<mockito.version>3.10.0</mockito.version>

<!-- plugins -->
<maven-release.version>3.0.0-M4</maven-release.version>
<maven-source.version>3.2.1</maven-source.version>
<maven-compiler.version>3.8.1</maven-compiler.version>
<license-maven.version>4.1</license-maven.version>
<maven-javadoc.version>3.2.0</maven-javadoc.version>
<maven-javadoc.version>3.3.0</maven-javadoc.version>
<maven-gpg.version>3.0.1</maven-gpg.version>
<versions-maven.version>2.8.1</versions-maven.version>
<gitflow-maven.version>1.16.0</gitflow-maven.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class InstantIncidentException extends RuntimeException {
*
*/
public InstantIncidentException() {
super();
}

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ public InstantIncidentException(final String message, final Throwable cause) {
* @param cause root cause passed to the process
*/
public InstantIncidentException(final Throwable cause) {
super(cause);
super(null, cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ private long nextRetryInterval(final Integer remainingRetries, String retryPrope
return 0L;
}

if (retryProperty == null || retryProperty.trim().isEmpty()) {
// if empty retry-config, start again using the default
return nextRetryInterval(remainingRetries, this.valueVault.getDefaultRetryConfig(), true);
}

retryProperty = retryProperty.replace(" ", "").toUpperCase();

Matcher retryListMatcher = this.valueVault.getRetryListPattern().matcher(retryProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public final class RetryConfigValues {
//@formatter:off
private static final long FALLBACK_INTERVAL = 5 * 60 * 1000L; // 5 minutes
private static final String FALLBACK_RETRY_CONFIG = "R3/PT5M";
private static final String FALLBACK_RETRY_CONFIG_NAME = "RETRY_CONFIG";

private static final String RETRY_LIST_REGEX = "^([Pp](?:\\d+[Dd])?(?:[Tt](?!$)(?:\\d+[Hh])?(?:\\d+[Mm])?(?:\\d+[Ss])?)?)(,([Pp](?:\\d+[Dd])?(?:[Tt](?!$)(?:\\d+[Hh])?(?:\\d+[Mm])?(?:\\d+[Ss])?)?))*$";
private static final String RETRY_CYCLE_REGEX = "^(?:[Rr](?<times>\\d+)/)(?<interval>(?:[Pp](?:\\d+[Yy])?)(?:\\d+[Mm])?(?:\\d+[Dd])?(?:[Tt](?!$)(?:\\d+[Hh])?(?:\\d+[Mm])?(?:\\d+[Ss])?)?)$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import java.io.StringWriter;
import java.util.Objects;

import static java.lang.String.format;
import static java.util.Objects.isNull;


public class FailureService {

Expand Down Expand Up @@ -79,12 +82,44 @@ public void handleFailure(final Class<?> origin,
}


private String getErrorMessage(final Throwable throwable) {
if (throwable instanceof InstantIncidentException && Objects.nonNull(throwable.getCause())) {
// if instant-incident, probably root cause is more relevant
return this.getErrorMessage(throwable.getCause());
private String getErrorMessage(final Throwable exception) {

if (!(exception instanceof InstantIncidentException)) {
// AnotherTypeException() -> "AnotherType: another-message"
return exception.getClass().getSimpleName() + ": " + exception.getMessage();
}

if (isNull(exception.getMessage())) { // no message

if (isNull(exception.getCause())) {
// no root-cause: InstantIncidentException()
// -> InstantIncident
return "InstantIncident";

} else {
// with root-cause: InstantIncidentException(cause)
// -> CauseType: cause-message (InstantIncident)
return format("%s: %s (InstantIncident)",
exception.getCause().getClass().getSimpleName(),
exception.getCause().getMessage());
}

} else { // with message

if (isNull(exception.getCause())) {
// no root-cause: InstantIncidentException("message")
// -> InstantIncident: message
return "InstantIncident: " + exception.getMessage();

} else {
// with root-cause InstantIncidentException("message", cause)
// -> CauseType: cause-message (InstantIncident: message)
return format("%s: %s (InstantIncident: %s)",
exception.getCause().getClass().getSimpleName(),
exception.getCause().getMessage(),
exception.getMessage());
}
}
return throwable.getClass().getSimpleName() + ": " + throwable.getMessage();
}


Expand All @@ -102,10 +137,10 @@ private String getStackTrace(final Throwable throwable) {

private void logFailure(final Class<?> origin, final Throwable throwable, final int remainingRetries, final Long nextRetryInterval) {
// log remaining time only if retries > 0
final String millisIfRemainingRetry = String.format("%s", (remainingRetries == 0) ? "" : ", next retry in " + nextRetryInterval + "ms");
final String millisIfRemainingRetry = format("%s", (remainingRetries == 0) ? "" : ", next retry in " + nextRetryInterval + "ms");

final String errorLogString =
String.format("%s: %s. There are %s retry(s) left%s",
format("%s: %s. There are %s retry(s) left%s",
throwable.getClass().getSimpleName(),
throwable.getMessage(),
remainingRetries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void instantIncidentExceptionWithRootCause() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage(rootCause.getClass().getSimpleName() + ": " + rootCause.getMessage());
this.assertErrorMessage("RuntimeException: root-cause (InstantIncident: no-retries)");
this.assertErrorDetails(rootCause);
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand All @@ -101,7 +101,7 @@ public void emptyInstantIncidentExceptionWithRootCause() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage("InstantIncidentException: null");
this.assertErrorMessage("InstantIncident");
//this.assertErrorDetails(new InstantIncidentException());
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand All @@ -120,7 +120,7 @@ public void emptyRootInstantIncidentException() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage("RuntimeException: null");
this.assertErrorMessage("RuntimeException: null (InstantIncident)");
this.assertErrorDetails(instantIncidentException.getCause());
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand All @@ -140,7 +140,7 @@ public void instantIncidentException() {
this.verifyHandleFailure();

// assert
this.assertErrorMessage("InstantIncidentException: instant-incident-no-retries-plz");
this.assertErrorMessage("InstantIncident: instant-incident-no-retries-plz");
this.assertErrorDetails(instantIncidentException);
this.assertNextRetryInterval(0);
this.assertNoRemainingRetries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@

import static org.mockito.Mockito.when;

@TestPropertySource(properties = "de.viadee.bpm.camunda.external-task.retry-config.defaults=R3/PT1D")
@TestPropertySource(properties = "de.viadee.bpm.camunda.external-task.retry-config.default-behavior=R3/PT1D")
public class InvalidDefaultBehaviourTest extends BaseTest {


@Test
public void runtimeException() {
// prepare
when(this.externalTask.getRetries()).thenReturn(null);
when(this.externalTask.getExtensionProperty(this.properties.getIdentifier())).thenReturn("invld!");

// test
this.externalTaskRetryAspect.handleErrorAfterThrown(this.joinPoint, new RuntimeException(), this.externalTask, this.externalTaskService);
Expand Down

0 comments on commit 2b1a1ec

Please sign in to comment.