From a8ee17a9ada1e617c041b8288a78b273cf609c53 Mon Sep 17 00:00:00 2001 From: vculea Date: Thu, 12 Dec 2024 18:03:10 +0200 Subject: [PATCH] added retryUntilOneIsDetails(int maxRetries, Call... calls) in RetryUtils.java --- .../sdl/selenium/web/utils/RetryUtils.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/sdl/selenium/web/utils/RetryUtils.java b/src/main/java/com/sdl/selenium/web/utils/RetryUtils.java index b8559463..ffeddd1d 100644 --- a/src/main/java/com/sdl/selenium/web/utils/RetryUtils.java +++ b/src/main/java/com/sdl/selenium/web/utils/RetryUtils.java @@ -7,7 +7,6 @@ import org.slf4j.Logger; import java.time.Duration; -import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.concurrent.Callable; @@ -149,9 +148,10 @@ public static Result retryUntilOneIs(int maxRetries, String prefixLog, Ca V execute = null; boolean notExpected = true; int position = 0; - List fields = new ArrayList<>(); + StringBuilder field = new StringBuilder(); do { count++; + field.append("\n|").append(count).append(">"); wait = count < 9 ? fibonacci(wait, fib).getResult() : wait; Utils.sleep(wait); int iteration = 0; @@ -164,11 +164,11 @@ public static Result retryUntilOneIs(int maxRetries, String prefixLog, Ca if (!notExpected) { position = iteration; long millis = getDuringMillis(startMsCall); - fields.add(position + ":" + millis); + field.append(position).append(":").append(millis); break; } long millis = getDuringMillis(startMsCall); - fields.add(iteration + ":" + millis); + field.append(iteration).append(":").append(millis).append(","); } } catch (Exception | AssertionError e) { if (count >= maxRetries) { @@ -182,7 +182,7 @@ public static Result retryUntilOneIs(int maxRetries, String prefixLog, Ca long duringMs = getDuringMillis(startMs); log.info((Strings.isNullOrEmpty(prefixLog) ? "" : prefixLog + ":") + "Retry {} and wait {} milliseconds", count, duringMs); } - return new Result<>(execute, position, count == maxRetries, String.join(",", fields)); + return new Result<>(execute, position, count == maxRetries, field.toString()); } @SafeVarargs @@ -194,9 +194,10 @@ public static Result retryUntilOneIsDetails(int maxRetries, String prefix V execute = null; boolean notExpected = true; int position = 0; - List fields = new ArrayList<>(); + StringBuilder field = new StringBuilder(); do { count++; + field.append("\n|").append(count).append(">"); wait = count < 9 ? fibonacci(wait, fib).getResult() : wait; Utils.sleep(wait); int iteration = 0; @@ -209,11 +210,11 @@ public static Result retryUntilOneIsDetails(int maxRetries, String prefix if (!notExpected) { position = iteration; long millis = getDuringMillis(startMsCall); - fields.add(call.name() + ":" + millis); + field.append(call.name()).append(":").append(millis); break; } long millis = getDuringMillis(startMsCall); - fields.add(call.name() + ":" + millis); + field.append(call.name()).append(":").append(millis).append(","); } } catch (Exception | AssertionError e) { if (count >= maxRetries) { @@ -227,7 +228,7 @@ public static Result retryUntilOneIsDetails(int maxRetries, String prefix long duringMs = getDuringMillis(startMs); log.info((Strings.isNullOrEmpty(prefixLog) ? "" : prefixLog + ":") + "Retry {} and wait {} milliseconds", count, duringMs); } - return new Result<>(execute, position, count == maxRetries, String.join(",", fields)); + return new Result<>(execute, position, count == maxRetries, field.toString()); } @SafeVarargs @@ -246,9 +247,10 @@ public static Result retryUntilOneIs(Duration duration, String prefixLog, V execute = null; boolean notExpected = true; int position = 0; - List fields = new ArrayList<>(); + StringBuilder field = new StringBuilder(); do { count++; + field.append("\n|").append(count).append(">"); wait = fibonacciSinusoidal(wait, fib).getResult(); Utils.sleep(wait); int iteration = 0; @@ -261,11 +263,11 @@ public static Result retryUntilOneIs(Duration duration, String prefixLog, if (!notExpected) { position = iteration; long millis = getDuringMillis(startMsCall); - fields.add(position + ":" + millis); + field.append(position).append(":").append(millis); break; } long millis = getDuringMillis(startMsCall); - fields.add(iteration + ":" + millis); + field.append(iteration).append(":").append(millis).append(","); } } catch (Exception | AssertionError e) { if (timeIsOver(startMillis, duration)) { @@ -279,7 +281,7 @@ public static Result retryUntilOneIs(Duration duration, String prefixLog, long duringMs = getDuringMillis(startMs); log.info((Strings.isNullOrEmpty(prefixLog) ? "" : prefixLog + ":") + "Retry {} and wait {} milliseconds", count, duringMs); } - return new Result<>(execute, position, timeIsOver(startMillis, duration), String.join(",", fields)); + return new Result<>(execute, position, timeIsOver(startMillis, duration), field.toString()); } @SafeVarargs @@ -298,9 +300,10 @@ public static Result retryUntilOneIsDetails(Duration duration, String pre V execute = null; boolean notExpected = true; int position = 0; - List fields = new ArrayList<>(); + StringBuilder field = new StringBuilder(); do { count++; + field.append("\n|").append(count).append(">"); wait = fibonacciSinusoidal(wait, fib).getResult(); Utils.sleep(wait); int iteration = 0; @@ -313,11 +316,11 @@ public static Result retryUntilOneIsDetails(Duration duration, String pre if (!notExpected) { position = iteration; long millis = getDuringMillis(startMsCall); - fields.add(call.name() + ":" + millis); + field.append(call.name()).append(":").append(millis); break; } long millis = getDuringMillis(startMsCall); - fields.add(call.name() + ":" + millis); + field.append(call.name()).append(":").append(millis).append(","); } } catch (Exception | AssertionError e) { if (timeIsOver(startMillis, duration)) { @@ -331,7 +334,7 @@ public static Result retryUntilOneIsDetails(Duration duration, String pre long duringMs = getDuringMillis(startMs); log.info((Strings.isNullOrEmpty(prefixLog) ? "" : prefixLog + ":") + "Retry {} and wait {} milliseconds", count, duringMs); } - return new Result<>(execute, position, timeIsOver(startMillis, duration), String.join(",", fields)); + return new Result<>(execute, position, timeIsOver(startMillis, duration), field.toString()); } private static V retry(Duration duration, String prefixLog, Callable call, boolean safe) {