You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/10/28 16:37:21 UTC
[10/11] git commit: Asserts: log.info with details of failure
Asserts: log.info with details of failure
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/e9e366a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/e9e366a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/e9e366a3
Branch: refs/heads/master
Commit: e9e366a36ed02c2035fabad3b1dcb5d45018b726
Parents: cbc9fdb
Author: Aled Sage <al...@gmail.com>
Authored: Mon Oct 27 14:37:17 2014 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Oct 28 15:35:33 2014 +0000
----------------------------------------------------------------------
.../src/main/java/brooklyn/test/Asserts.java | 26 +++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9e366a3/utils/common/src/main/java/brooklyn/test/Asserts.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/test/Asserts.java b/utils/common/src/main/java/brooklyn/test/Asserts.java
index 11bfa02..b3c1e01 100644
--- a/utils/common/src/main/java/brooklyn/test/Asserts.java
+++ b/utils/common/src/main/java/brooklyn/test/Asserts.java
@@ -29,7 +29,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
@@ -287,7 +286,7 @@ public class Asserts {
sleepTimeBetweenAttempts = Math.min(sleepTimeBetweenAttempts*2, maxPeriod.toMilliseconds());
}
- log.debug("TestUtils.executeUntilSucceedsWithFinallyBlockInternal exceeded max attempts or timeout - {} attempts lasting {} ms", attempt, System.currentTimeMillis()-startTime);
+ log.info("succeedsEventually exceeded max attempts or timeout - {} attempts lasting {} ms, for {}", new Object[] {attempt, System.currentTimeMillis()-startTime, c});
if (lastException != null)
throw lastException;
throw fail("invalid result: "+result);
@@ -317,13 +316,16 @@ public class Asserts {
long periodMs = period.toMilliseconds();
long startTime = System.currentTimeMillis();
long expireTime = startTime+duration.toMilliseconds();
+ int attempt = 0;
boolean first = true;
T result = null;
while (first || System.currentTimeMillis() <= expireTime) {
+ attempt++;
try {
result = job.call();
} catch (Exception e) {
+ log.info("succeedsContinually failed - {} attempts lasting {} ms, for {} (rethrowing)", new Object[] {attempt, System.currentTimeMillis()-startTime, job});
throw propagate(e);
}
if (periodMs > 0) sleep(periodMs);
@@ -455,7 +457,25 @@ public class Asserts {
}
private static Callable<?> toCallable(Runnable r) {
- return (r instanceof Callable) ? (Callable<?>)r : Executors.callable(r);
+ return (r instanceof Callable) ? (Callable<?>)r : new RunnableAdapter<Void>(r, null);
+ }
+
+ /** Same as {@link java.util.concurrent.Executors#callable(Runnable)}, except includes toString() */
+ static final class RunnableAdapter<T> implements Callable<T> {
+ final Runnable task;
+ final T result;
+ RunnableAdapter(Runnable task, T result) {
+ this.task = task;
+ this.result = result;
+ }
+ public T call() {
+ task.run();
+ return result;
+ }
+ @Override
+ public String toString() {
+ return "RunnableAdapter("+task+")";
+ }
}
private static void sleep(long periodMs) {