Created
December 3, 2017 17:44
-
-
Save Romeh/5407bfabdd63f1528edcb921e8739d12 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* An exception thrown to signal that a retry operation (executed via {@link RetryRule}) has retried more than the | |
* allowed number of times, and has still failed. | |
*/ | |
public final class RetryException extends RuntimeException { | |
private RetryException(@NotNull String message) { | |
super(message); | |
} | |
/** | |
* @param errors the errors for each attempt at running this test-case | |
*/ | |
@NotNull | |
public static RetryException from(@NotNull Throwable[] errors) { | |
final StringBuilder msg = new StringBuilder("Invoked methods still failed after " + errors.length + " attempts."); | |
for (int i = 0; i < errors.length; i++) { | |
final Throwable error = errors[i]; | |
msg.append('\n'); | |
msg.append("Attempt #").append(i).append(" threw exception:"); | |
msg.append(stackTraceAsString(error)); | |
} | |
return new RetryException(msg.toString()); | |
} | |
@NotNull | |
private static String stackTraceAsString(@NotNull Throwable t) { | |
final StringWriter errors = new StringWriter(); | |
t.printStackTrace(new PrintWriter(errors)); | |
return errors.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment