| 1 | package fr.sii.ogham.core.builder.configurer; | |
| 2 | ||
| 3 | import static fr.sii.ogham.core.util.ExceptionUtils.fatalJvmError; | |
| 4 | import static fr.sii.ogham.core.util.ExceptionUtils.hasAnyCause; | |
| 5 | ||
| 6 | import java.util.function.Predicate; | |
| 7 | ||
| 8 | import fr.sii.ogham.core.exception.InvalidMessageException; | |
| 9 | import fr.sii.ogham.core.exception.filler.FillMessageException; | |
| 10 | import fr.sii.ogham.core.exception.handler.NoContentException; | |
| 11 | import fr.sii.ogham.core.exception.handler.TemplateNotFoundException; | |
| 12 | import fr.sii.ogham.core.exception.handler.TemplateParsingFailedException; | |
| 13 | import fr.sii.ogham.core.exception.mimetype.MimeTypeDetectionException; | |
| 14 | import fr.sii.ogham.core.exception.resource.ResourceResolutionException; | |
| 15 | import fr.sii.ogham.core.exception.template.ContextException; | |
| 16 | import fr.sii.ogham.core.exception.template.EngineDetectionException; | |
| 17 | import fr.sii.ogham.core.exception.template.ParseException; | |
| 18 | import fr.sii.ogham.core.exception.util.BeanException; | |
| 19 | import fr.sii.ogham.core.util.ExceptionUtils; | |
| 20 | ||
| 21 | /** | |
| 22 | * Predicate that skip retry if one of theses condition is met: | |
| 23 | * | |
| 24 | * <ul> | |
| 25 | * <li>The error is a JVM error that should not be ignored</li> | |
| 26 | * <li>If the error is due to a preparation error (not sending). In this case, | |
| 27 | * retrying will result in the same behavior so it will fail again: | |
| 28 | * <ul> | |
| 29 | * <li>It is a parsing error</li> | |
| 30 | * <li>The message in not valid</li> | |
| 31 | * <li>A resource associated to the message can't be resolved</li> | |
| 32 | * <li>The mimetype of a resource couldn't be determined</li> | |
| 33 | * </ul> | |
| 34 | * </li> | |
| 35 | * </ul> | |
| 36 | * | |
| 37 | * <p> | |
| 38 | * In other situations, the message may be sent again. | |
| 39 | * | |
| 40 | * | |
| 41 | * @author Aurélien Baudet | |
| 42 | * | |
| 43 | */ | |
| 44 | public final class SendMessageRetryablePredicates { | |
| 45 | ||
| 46 | private SendMessageRetryablePredicates() { | |
| 47 | super(); | |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * Predicate that skip retry if one of theses condition is met: | |
| 52 | * | |
| 53 | * <ul> | |
| 54 | * <li>The error is a JVM error that should not be ignored</li> | |
| 55 | * <li>If the error is due to a preparation error (not sending). In this | |
| 56 | * case, retrying will result in the same behavior so it will fail again: | |
| 57 | * <ul> | |
| 58 | * <li>It is a parsing error</li> | |
| 59 | * <li>The message in not valid</li> | |
| 60 | * <li>A resource associated to the message can't be resolved</li> | |
| 61 | * <li>The mimetype of a resource couldn't be determined</li> | |
| 62 | * </ul> | |
| 63 | * </li> | |
| 64 | * </ul> | |
| 65 | * | |
| 66 | * <p> | |
| 67 | * In other situations, the message may be sent again. | |
| 68 | * | |
| 69 | * @param error | |
| 70 | * the error to analyze | |
| 71 | * @return true if the message can be sent again | |
| 72 | */ | |
| 73 | @SuppressWarnings("squid:S1126") | |
| 74 | public static boolean canResendMessage(Throwable error) { | |
| 75 |
8
1. canResendMessage : negated conditional → NO_COVERAGE 2. canResendMessage : negated conditional → SURVIVED 3. canResendMessage : negated conditional → NO_COVERAGE 4. canResendMessage : negated conditional → SURVIVED 5. canResendMessage : negated conditional → KILLED 6. canResendMessage : negated conditional → KILLED 7. canResendMessage : negated conditional → KILLED 8. canResendMessage : negated conditional → KILLED |
if (fatalJvmError(error) || isMessagePreparationError(error)) { |
| 76 |
2
1. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → NO_COVERAGE 2. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED |
return false; |
| 77 | } | |
| 78 |
8
1. canResendMessage : negated conditional → SURVIVED 2. canResendMessage : negated conditional → NO_COVERAGE 3. canResendMessage : negated conditional → NO_COVERAGE 4. canResendMessage : negated conditional → KILLED 5. canResendMessage : negated conditional → KILLED 6. canResendMessage : negated conditional → KILLED 7. canResendMessage : negated conditional → KILLED 8. canResendMessage : negated conditional → KILLED |
if (hasAnyCause(error, ExceptionUtils::fatalJvmError) || hasAnyCause(error, SendMessageRetryablePredicates::isMessagePreparationError)) { |
| 79 |
4
1. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → NO_COVERAGE 2. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED 3. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED 4. canResendMessage : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED |
return false; |
| 80 | } | |
| 81 |
3
1. canResendMessage : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → NO_COVERAGE 2. canResendMessage : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED 3. canResendMessage : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED |
return true; |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * Checks is raised during preparation of the message. | |
| 86 | * | |
| 87 | * <p> | |
| 88 | * The error may be due to: | |
| 89 | * <ul> | |
| 90 | * <li>Either a parsing error</li> | |
| 91 | * <li>Or the message in not valid</li> | |
| 92 | * <li>Or a resource can't be resolved</li> | |
| 93 | * <li>Or the mimetype of a resource couldn't be determined</li> | |
| 94 | * </ul> | |
| 95 | * | |
| 96 | * <p> | |
| 97 | * In these cases, retrying will always give the same result so there is no | |
| 98 | * point in retrying. | |
| 99 | * | |
| 100 | * @param error | |
| 101 | * the error to analyze | |
| 102 | * @return true if the error is raised during preparation of the message | |
| 103 | */ | |
| 104 | public static boolean isMessagePreparationError(Throwable error) { | |
| 105 | // @formatter:off | |
| 106 |
8
1. isMessagePreparationError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::isMessagePreparationError → SURVIVED 2. isMessagePreparationError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::isMessagePreparationError → NO_COVERAGE 3. isMessagePreparationError : negated conditional → NO_COVERAGE 4. isMessagePreparationError : negated conditional → SURVIVED 5. isMessagePreparationError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::isMessagePreparationError → KILLED 6. isMessagePreparationError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::isMessagePreparationError → KILLED 7. isMessagePreparationError : negated conditional → KILLED 8. isMessagePreparationError : negated conditional → KILLED |
return parsingFailed(error) |
| 107 |
4
1. isMessagePreparationError : negated conditional → NO_COVERAGE 2. isMessagePreparationError : negated conditional → SURVIVED 3. isMessagePreparationError : negated conditional → KILLED 4. isMessagePreparationError : negated conditional → KILLED |
|| messageIsInvalid(error) |
| 108 |
4
1. isMessagePreparationError : negated conditional → SURVIVED 2. isMessagePreparationError : negated conditional → NO_COVERAGE 3. isMessagePreparationError : negated conditional → KILLED 4. isMessagePreparationError : negated conditional → KILLED |
|| resourceIsUnresolved(error) |
| 109 |
4
1. isMessagePreparationError : negated conditional → NO_COVERAGE 2. isMessagePreparationError : negated conditional → SURVIVED 3. isMessagePreparationError : negated conditional → KILLED 4. isMessagePreparationError : negated conditional → KILLED |
|| mimetypeIsUndetectable(error) |
| 110 |
4
1. isMessagePreparationError : negated conditional → NO_COVERAGE 2. isMessagePreparationError : negated conditional → SURVIVED 3. isMessagePreparationError : negated conditional → KILLED 4. isMessagePreparationError : negated conditional → KILLED |
|| developerError(error); |
| 111 | // @formatter:on | |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * Indicates if the error is raised during template parsing. | |
| 116 | * | |
| 117 | * @param error | |
| 118 | * the error to analyze | |
| 119 | * @return true if it is a parsing error | |
| 120 | */ | |
| 121 | public static boolean parsingFailed(Throwable error) { | |
| 122 | // @formatter:off | |
| 123 |
32
1. parsingFailed : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::parsingFailed → SURVIVED 2. parsingFailed : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::parsingFailed → NO_COVERAGE 3. parsingFailed : negated conditional → SURVIVED 4. parsingFailed : negated conditional → NO_COVERAGE 5. parsingFailed : negated conditional → SURVIVED 6. parsingFailed : negated conditional → NO_COVERAGE 7. parsingFailed : negated conditional → NO_COVERAGE 8. parsingFailed : negated conditional → SURVIVED 9. parsingFailed : negated conditional → SURVIVED 10. parsingFailed : negated conditional → NO_COVERAGE 11. parsingFailed : negated conditional → SURVIVED 12. parsingFailed : negated conditional → NO_COVERAGE 13. parsingFailed : negated conditional → NO_COVERAGE 14. parsingFailed : negated conditional → SURVIVED 15. parsingFailed : negated conditional → NO_COVERAGE 16. parsingFailed : negated conditional → SURVIVED 17. parsingFailed : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::parsingFailed → KILLED 18. parsingFailed : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::parsingFailed → KILLED 19. parsingFailed : negated conditional → KILLED 20. parsingFailed : negated conditional → KILLED 21. parsingFailed : negated conditional → KILLED 22. parsingFailed : negated conditional → KILLED 23. parsingFailed : negated conditional → KILLED 24. parsingFailed : negated conditional → KILLED 25. parsingFailed : negated conditional → KILLED 26. parsingFailed : negated conditional → KILLED 27. parsingFailed : negated conditional → KILLED 28. parsingFailed : negated conditional → KILLED 29. parsingFailed : negated conditional → KILLED 30. parsingFailed : negated conditional → KILLED 31. parsingFailed : negated conditional → KILLED 32. parsingFailed : negated conditional → KILLED |
return error instanceof ParseException |
| 124 | || error instanceof BeanException | |
| 125 | || error instanceof EngineDetectionException | |
| 126 | || error instanceof ContextException | |
| 127 | || error instanceof TemplateParsingFailedException | |
| 128 | || error instanceof TemplateNotFoundException | |
| 129 | || error instanceof NoContentException; | |
| 130 | // @formatter:on | |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Indicates if the error is raised because the message is invalid. | |
| 135 | * | |
| 136 | * @param error | |
| 137 | * the error to analyze | |
| 138 | * @return true if the message is invalid | |
| 139 | */ | |
| 140 | public static boolean messageIsInvalid(Throwable error) { | |
| 141 | // @formatter:off | |
| 142 |
12
1. messageIsInvalid : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::messageIsInvalid → NO_COVERAGE 2. messageIsInvalid : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::messageIsInvalid → SURVIVED 3. messageIsInvalid : negated conditional → SURVIVED 4. messageIsInvalid : negated conditional → NO_COVERAGE 5. messageIsInvalid : negated conditional → SURVIVED 6. messageIsInvalid : negated conditional → NO_COVERAGE 7. messageIsInvalid : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::messageIsInvalid → KILLED 8. messageIsInvalid : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::messageIsInvalid → KILLED 9. messageIsInvalid : negated conditional → KILLED 10. messageIsInvalid : negated conditional → KILLED 11. messageIsInvalid : negated conditional → KILLED 12. messageIsInvalid : negated conditional → KILLED |
return error instanceof InvalidMessageException |
| 143 | || error instanceof FillMessageException; | |
| 144 | // @formatter:on | |
| 145 | } | |
| 146 | ||
| 147 | /** | |
| 148 | * Indicates if the error is raised because a resource can't be resolved. | |
| 149 | * | |
| 150 | * @param error | |
| 151 | * the error to analyze | |
| 152 | * @return true if a resource can't be resolved | |
| 153 | */ | |
| 154 | public static boolean resourceIsUnresolved(Throwable error) { | |
| 155 |
7
1. resourceIsUnresolved : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → NO_COVERAGE 2. resourceIsUnresolved : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → SURVIVED 3. resourceIsUnresolved : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → NO_COVERAGE 4. resourceIsUnresolved : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → SURVIVED 5. resourceIsUnresolved : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → KILLED 6. resourceIsUnresolved : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → KILLED 7. resourceIsUnresolved : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::resourceIsUnresolved → KILLED |
return error instanceof ResourceResolutionException; |
| 156 | } | |
| 157 | ||
| 158 | /** | |
| 159 | * Indicates if the error is raised because a resource mimetype can't be | |
| 160 | * determined. | |
| 161 | * | |
| 162 | * @param error | |
| 163 | * the error to analyze | |
| 164 | * @return true if a resource mimetype can't be determined | |
| 165 | */ | |
| 166 | public static boolean mimetypeIsUndetectable(Throwable error) { | |
| 167 |
7
1. mimetypeIsUndetectable : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → NO_COVERAGE 2. mimetypeIsUndetectable : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → SURVIVED 3. mimetypeIsUndetectable : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → SURVIVED 4. mimetypeIsUndetectable : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → NO_COVERAGE 5. mimetypeIsUndetectable : replaced boolean return with false for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → KILLED 6. mimetypeIsUndetectable : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → KILLED 7. mimetypeIsUndetectable : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::mimetypeIsUndetectable → KILLED |
return error instanceof MimeTypeDetectionException; |
| 168 | } | |
| 169 | ||
| 170 | /** | |
| 171 | * Indicates if the error is raised because the developer has misconfigured | |
| 172 | * or has used an illegal value ( {@link IllegalArgumentException}, | |
| 173 | * {@link NullPointerException}, ...). | |
| 174 | * | |
| 175 | * @param error | |
| 176 | * the error to analyze | |
| 177 | * @return true if developer has used an illegal value | |
| 178 | */ | |
| 179 | public static boolean developerError(Throwable error) { | |
| 180 | // @formatter:off | |
| 181 |
12
1. developerError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::developerError → NO_COVERAGE 2. developerError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::developerError → SURVIVED 3. developerError : negated conditional → SURVIVED 4. developerError : negated conditional → NO_COVERAGE 5. developerError : negated conditional → SURVIVED 6. developerError : negated conditional → NO_COVERAGE 7. developerError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::developerError → KILLED 8. developerError : replaced boolean return with true for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::developerError → KILLED 9. developerError : negated conditional → KILLED 10. developerError : negated conditional → KILLED 11. developerError : negated conditional → KILLED 12. developerError : negated conditional → KILLED |
return error instanceof IllegalArgumentException |
| 182 | || error instanceof NullPointerException; | |
| 183 | // @formatter:on | |
| 184 | } | |
| 185 | ||
| 186 | /** | |
| 187 | * Predicate that skip retry if one of theses condition is met: | |
| 188 | * | |
| 189 | * <ul> | |
| 190 | * <li>The error is a JVM error that should not be ignored</li> | |
| 191 | * <li>If the error is due to a preparation error (not sending). In this | |
| 192 | * case, retrying will result in the same behavior so it will fail again: | |
| 193 | * <ul> | |
| 194 | * <li>It is a parsing error</li> | |
| 195 | * <li>The message in not valid</li> | |
| 196 | * <li>A resource associated to the message can't be resolved</li> | |
| 197 | * <li>The mimetype of a resource couldn't be determined</li> | |
| 198 | * </ul> | |
| 199 | * </li> | |
| 200 | * </ul> | |
| 201 | * | |
| 202 | * <p> | |
| 203 | * In other situations, the message may be sent again. | |
| 204 | * | |
| 205 | * @return the predicate | |
| 206 | */ | |
| 207 | public static Predicate<Throwable> canResendMessage() { | |
| 208 |
6
1. canResendMessage : replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → SURVIVED 2. canResendMessage : replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → NO_COVERAGE 3. canResendMessage : replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → TIMED_OUT 4. canResendMessage : replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED 5. canResendMessage : replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED 6. canResendMessage : replaced return value with null for fr/sii/ogham/core/builder/configurer/SendMessageRetryablePredicates::canResendMessage → KILLED |
return SendMessageRetryablePredicates::canResendMessage; |
| 209 | } | |
| 210 | } | |
Mutations | ||
| 75 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 76 |
1.1 2.2 |
|
| 78 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 79 |
1.1 2.2 3.3 4.4 |
|
| 81 |
1.1 2.2 3.3 |
|
| 106 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 107 |
1.1 2.2 3.3 4.4 |
|
| 108 |
1.1 2.2 3.3 4.4 |
|
| 109 |
1.1 2.2 3.3 4.4 |
|
| 110 |
1.1 2.2 3.3 4.4 |
|
| 123 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 13.13 14.14 15.15 16.16 17.17 18.18 19.19 20.20 21.21 22.22 23.23 24.24 25.25 26.26 27.27 28.28 29.29 30.30 31.31 32.32 |
|
| 142 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 |
|
| 155 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 167 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 181 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 |
|
| 208 |
1.1 2.2 3.3 4.4 5.5 6.6 |