You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/01 18:48:49 UTC

[03/50] brooklyn-server git commit: Move code from TestUtils to Asserts, and deprecate

Move code from TestUtils to Asserts, and deprecate

- Deprecate code in TestUtils so we can delete it in 0.6
- Move code to Asserts
- Note: I've been lazy, and not updated uses of it!
  But this is just in test code, and I'll update everything
  first thing in 0.6 work.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b2471c28
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b2471c28
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b2471c28

Branch: refs/heads/0.5.0
Commit: b2471c284274259c8c6cc3a574c673667c2beea5
Parents: 9714edc
Author: Aled Sage <al...@gmail.com>
Authored: Thu Mar 28 10:37:14 2013 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Mar 29 09:47:46 2013 +0000

----------------------------------------------------------------------
 .../src/main/java/brooklyn/test/Asserts.java    | 262 ++++++++++++++++++-
 .../main/java/brooklyn/test/TestUtils.groovy    | 135 ++++++++--
 2 files changed, 376 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b2471c28/usage/test-support/src/main/java/brooklyn/test/Asserts.java
----------------------------------------------------------------------
diff --git a/usage/test-support/src/main/java/brooklyn/test/Asserts.java b/usage/test-support/src/main/java/brooklyn/test/Asserts.java
index c5a4283..d4261a9 100644
--- a/usage/test-support/src/main/java/brooklyn/test/Asserts.java
+++ b/usage/test-support/src/main/java/brooklyn/test/Asserts.java
@@ -2,18 +2,36 @@ package brooklyn.test;
 
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
+import groovy.lang.Closure;
 import groovy.time.TimeDuration;
 
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.test.TestUtils.BooleanWithMessage;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
 @Beta
 public class Asserts {
 
+    private static final Logger log = LoggerFactory.getLogger(Asserts.class);
+
+    private Asserts() {}
+    
     public static <T> void eventually(Supplier<? extends T> supplier, Predicate<T> predicate) {
         eventually(ImmutableMap.<String,Object>of(), supplier, predicate);
     }
@@ -23,8 +41,8 @@ public class Asserts {
     }
     
     public static <T> void eventually(Map<String,?> flags, Supplier<? extends T> supplier, Predicate<T> predicate, String errMsg) {
-        TimeDuration timeout = TestUtils.toTimeDuration(flags.get("timeout"), new TimeDuration(0,0,1,0));
-        TimeDuration period = TestUtils.toTimeDuration(flags.get("period"), new TimeDuration(0,0,0,10));
+        TimeDuration timeout = toTimeDuration(flags.get("timeout"), new TimeDuration(0,0,1,0));
+        TimeDuration period = toTimeDuration(flags.get("period"), new TimeDuration(0,0,0,10));
         long periodMs = period.toMilliseconds();
         long startTime = System.currentTimeMillis();
         long expireTime = startTime+timeout.toMilliseconds();
@@ -52,8 +70,8 @@ public class Asserts {
     }
 
     public static <T> void continually(Map<String,?> flags, Supplier<? extends T> supplier, Predicate<T> predicate, String errMsg) {
-        TimeDuration duration = TestUtils.toTimeDuration(flags.get("timeout"), new TimeDuration(0,0,1,0));
-        TimeDuration period = TestUtils.toTimeDuration(flags.get("period"), new TimeDuration(0,0,0,10));
+        TimeDuration duration = toTimeDuration(flags.get("timeout"), new TimeDuration(0,0,1,0));
+        TimeDuration period = toTimeDuration(flags.get("period"), new TimeDuration(0,0,0,10));
         long periodMs = period.toMilliseconds();
         long startTime = System.currentTimeMillis();
         long expireTime = startTime+duration.toMilliseconds();
@@ -66,14 +84,246 @@ public class Asserts {
         }
     }
 
+    
+    
+    public static void succeedsEventually(Runnable r) {
+        succeedsEventually(ImmutableMap.<String,Object>of(), r);
+    }
+
+    public static void succeedsEventually(Map<String,?> flags, Runnable r) {
+        succeedsEventually(flags, toCallable(r));
+    }
+    
+    public static void succeedsEventually(Callable<?> c) {
+        succeedsEventually(ImmutableMap.<String,Object>of(), c);
+    }
+    
+    /**
+     * Convenience method for cases where we need to test until something is true.
+     *
+     * The runnable will be invoked periodically until it succesfully concludes.
+     * <p>
+     * The following flags are supported:
+     * <ul>
+     * <li>abortOnError (boolean, default true)
+     * <li>abortOnException - (boolean, default false)
+     * <li>timeout - (a TimeDuration or an integer in millis, defaults to 30*SECONDS)
+     * <li>period - (a TimeDuration or an integer in millis, for fixed retry time; if not set, defaults to exponentially increasing from 1 to 500ms)
+     * <li>minPeriod - (a TimeDuration or an integer in millis; only used if period not explicitly set; the minimum period when exponentially increasing; defaults to 1ms)
+     * <li>maxPeriod - (a TimeDuration or an integer in millis; only used if period not explicitly set; the maximum period when exponentially increasing; defaults to 500ms)
+     * <li>maxAttempts - (integer, Integer.MAX_VALUE)
+     * </ul>
+     * 
+     * The following flags are deprecated:
+     * <ul>
+     * <li>useGroovyTruth - (defaults to false; any result code apart from 'false' will be treated as success including null; ignored for Runnables which aren't Callables)
+     * </ul>
+     * 
+     * @param flags, accepts the flags listed above
+     * @param r
+     * @param finallyBlock
+     */
+    public static void succeedsEventually(Map<String,?> flags, Callable<?> c) {
+        boolean abortOnException = get(flags, "abortOnException", false);
+        boolean abortOnError = get(flags, "abortOnError", false);
+        boolean useGroovyTruth = get(flags, "useGroovyTruth", false);
+        boolean logException = get(flags, "logException", true);
+
+        // To speed up tests, default is for the period to start small and increase...
+        TimeDuration duration = toTimeDuration(flags.get("timeout"), new TimeDuration(0,0,30,0));
+        TimeDuration fixedPeriod = toTimeDuration(flags.get("period"), null);
+        TimeDuration minPeriod = (fixedPeriod != null) ? fixedPeriod : toTimeDuration(flags.get("minPeriod"), new TimeDuration(0,0,0,1));
+        TimeDuration maxPeriod = (fixedPeriod != null) ? fixedPeriod : toTimeDuration(flags.get("maxPeriod"), new TimeDuration(0,0,0,500));
+        int maxAttempts = get(flags, "maxAttempts", Integer.MAX_VALUE);
+        int attempt = 0;
+        long startTime = System.currentTimeMillis();
+        try {
+            Throwable lastException = null;
+            Object result = null;
+            long lastAttemptTime = 0;
+            long expireTime = startTime+duration.toMilliseconds();
+            long sleepTimeBetweenAttempts = minPeriod.toMilliseconds();
+            
+            while (attempt < maxAttempts && lastAttemptTime < expireTime) {
+                try {
+                    attempt++;
+                    lastAttemptTime = System.currentTimeMillis();
+                    result = c.call();
+                    if (log.isTraceEnabled()) log.trace("Attempt {} after {} ms: {}", new Object[] {attempt, System.currentTimeMillis() - startTime, result});
+                    if (useGroovyTruth) {
+                        if (groovyTruth(result)) return;
+                    } else if (Boolean.FALSE.equals(result)) {
+                        if (result instanceof BooleanWithMessage) 
+                            log.warn("Test returned an instance of BooleanWithMessage but useGroovyTruth is not set! " +
+                                     "The result of this probably isn't what you intended.");
+                        return;
+                    } else {
+                        return;
+                    }
+                    lastException = null;
+                } catch(Throwable e) {
+                    lastException = e;
+                    if (log.isTraceEnabled()) log.trace("Attempt {} after {} ms: {}", new Object[] {attempt, System.currentTimeMillis() - startTime, e.getMessage()});
+                    if (abortOnException) throw e;
+                    if (abortOnError && e instanceof Error) throw e;
+                }
+                long sleepTime = Math.min(sleepTimeBetweenAttempts, expireTime-System.currentTimeMillis());
+                if (sleepTime > 0) Thread.sleep(sleepTime);
+                sleepTimeBetweenAttempts = Math.min(sleepTimeBetweenAttempts*2, maxPeriod.toMilliseconds());
+            }
+            
+            log.debug("TestUtils.executeUntilSucceedsWithFinallyBlockInternal exceeded max attempts or timeout - {} attempts lasting {} ms", attempt, System.currentTimeMillis()-startTime);
+            if (lastException != null)
+                throw lastException;
+            fail("invalid result: "+result);
+        } catch (Throwable t) {
+            if (logException) log.info("failed succeeds-eventually, "+attempt+" attempts, "+
+                    (System.currentTimeMillis()-startTime)+"ms elapsed "+
+                    "(rethrowing): "+t);
+            throw propagate(t);
+        }
+    }
+
+    public static <T> void succeedsContinually(Runnable r) {
+        succeedsContinually(ImmutableMap.<String,Object>of(), r);
+    }
+    
+    public static <T> void succeedsContinually(Map<String,?> flags, Runnable r) {
+        succeedsContinually(flags, toCallable(r));
+    }
+
+    public static void succeedsContinually(Callable<?> c) {
+        succeedsContinually(ImmutableMap.<String,Object>of(), c);
+    }
+    
+    public static void succeedsContinually(Map<String,?> flags, Callable<?> job) {
+        TimeDuration duration = toTimeDuration(flags.get("timeout"), new TimeDuration(0,0,1,0));
+        TimeDuration period = toTimeDuration(flags.get("period"), new TimeDuration(0,0,0,10));
+        long periodMs = period.toMilliseconds();
+        long startTime = System.currentTimeMillis();
+        long expireTime = startTime+duration.toMilliseconds();
+        
+        boolean first = true;
+        while (first || System.currentTimeMillis() <= expireTime) {
+            try {
+                job.call();
+            } catch (Exception e) {
+                throw propagate(e);
+            }
+            if (periodMs > 0) sleep(periodMs);
+            first = false;
+        }
+    }
+    
+    private static TimeDuration toTimeDuration(Object duration) {
+        return toTimeDuration(duration, null);
+    }
+            
+    private static TimeDuration toTimeDuration(Object duration, TimeDuration defaultVal) {
+        if (duration == null) {
+            return defaultVal;
+        } else if (duration instanceof TimeDuration) {
+            return (TimeDuration) duration;
+        } else if (duration instanceof Number) {
+            return new TimeDuration(0,0,0,((Number) duration).intValue());
+            // TODO would be nice to have this, but we need to sort out utils / test-utils dependency
+//        } else if (duration instanceof String) {
+//            return Time.parseTimeString((String)duration);
+        } else {
+            throw new IllegalArgumentException("Cannot convert "+duration+" of type "+duration.getClass().getName()+" to a TimeDuration");
+        }
+    }
+    
+    public static void assertFails(Runnable c) {
+        assertFailsWith(c, Predicates.alwaysTrue());
+    }
+    
+    public static void assertFailsWith(Runnable c, final Closure<Boolean> exceptionChecker) {
+        assertFailsWith(c, new Predicate<Throwable>() {
+            public boolean apply(Throwable input) {
+                return exceptionChecker.call(input);
+            }
+        });
+    }
+    
+    public static void assertFailsWith(Runnable c, final Class<? extends Throwable> validException, final Class<? extends Throwable> ...otherValidExceptions) {
+        final List<Class> validExceptions = ImmutableList.<Class>builder()
+                .add(validException)
+                .addAll(ImmutableList.copyOf(otherValidExceptions))
+                .build();
+        
+        assertFailsWith(c, new Predicate<Throwable>() {
+            public boolean apply(Throwable e) {
+                for (Class<?> validException: validExceptions) {
+                    if (validException.isInstance(e)) return true;
+                }
+                fail("Test threw exception of unexpected type "+e.getClass()+"; expecting "+validExceptions);
+                return false;
+            }
+        });
+    }
+    
+    public static void assertFailsWith(Runnable c, Predicate<? super Throwable> exceptionChecker) {
+        boolean failed = false;
+        try {
+            c.run();
+        } catch (Throwable e) {
+            failed = true;
+            if (!exceptionChecker.apply(e)) {
+                log.debug("Test threw invalid exception (failing)", e);
+                fail("Test threw invalid exception: "+e);
+            }
+            log.debug("Test for exception successful ("+e+")");
+        }
+        if (!failed) fail("Test code should have thrown exception but did not");
+    }
+
+    private static boolean groovyTruth(Object o) {
+        // TODO Doesn't handle matchers (see http://docs.codehaus.org/display/GROOVY/Groovy+Truth)
+        if (o == null) {
+            return false;
+        } else if (o instanceof Boolean) {
+            return (Boolean)o;
+        } else if (o instanceof String) {
+            return !((String)o).isEmpty();
+        } else if (o instanceof Collection) {
+            return !((Collection)o).isEmpty();
+        } else if (o instanceof Map) {
+            return !((Map)o).isEmpty();
+        } else if (o instanceof Iterator) {
+            return ((Iterator)o).hasNext();
+        } else if (o instanceof Enumeration) {
+            return ((Enumeration)o).hasMoreElements();
+        } else {
+            return true;
+        }
+    }
+    
+    private static <T> T get(Map<String,?> map, String key, T defaultVal) {
+        Object val = map.get(key);
+        return (T) ((val == null) ? defaultVal : val);
+    }
+    
+    private static Callable<?> toCallable(Runnable r) {
+        return (r instanceof Callable) ? (Callable<?>)r : Executors.callable(r);
+    }
+    
     private static void sleep(long periodMs) {
         if (periodMs > 0) {
             try {
                 Thread.sleep(periodMs);
             } catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-                throw new RuntimeException(e);
+                throw propagate(e);
             }
         }
     }
+    
+    private static RuntimeException propagate(Throwable t) {
+        if (t instanceof InterruptedException) {
+            Thread.currentThread().interrupt();
+        }
+        if (t instanceof RuntimeException) throw (RuntimeException)t;
+        if (t instanceof Error) throw (Error)t;
+        throw new RuntimeException(t);
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b2471c28/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
----------------------------------------------------------------------
diff --git a/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy b/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
index 54fc516..ab81741 100644
--- a/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
+++ b/usage/test-support/src/main/java/brooklyn/test/TestUtils.groovy
@@ -29,7 +29,12 @@ public class TestUtils {
 
     private TestUtils() { }
 
-    /** True if two attempts to connect to the port succeed. */
+    /**
+     * True if two attempts to connect to the port succeed.
+     * 
+     * @deprecated since 0.5; use {@link brooklyn.util.NetworkUtils#isPortAvailable(int)}
+     */
+    @Deprecated
     public static boolean isPortInUse(int port, long retryAfterMillis=0) {
         try {
             def s = new Socket("localhost", port)
@@ -82,7 +87,7 @@ public class TestUtils {
     // calling groovy from java doesn't cope with generics here; stripping them from here :-(
     //      <T> void assertEventually(Map flags=[:], Supplier<? extends T> supplier, Predicate<T> predicate)
     /**
-     * @deprecated since 0.5; use {@link Asserts.eventually(Map, Supplier, Predicate)}
+     * @deprecated since 0.5; use {@link Asserts#eventually(Map, Supplier, Predicate)}
      */
     @Deprecated
     public static void assertEventually(Map flags=[:], Supplier supplier, Predicate predicate) {
@@ -90,30 +95,49 @@ public class TestUtils {
     }
     
     /**
-     * @deprecated since 0.5; use {@link Asserts.eventually(Map, Supplier, Predicate, String)}
+     * @deprecated since 0.5; use {@link Asserts#eventually(Map, Supplier, Predicate, String)}
      */
     @Deprecated
     public static <T> void assertEventually(Map flags=[:], Supplier<? extends T> supplier, Predicate<T> predicate, String errMsg) {
         Asserts.eventually(flags, supplier, predicate, errMsg);
     }
-    
+
+    /**    
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(java.util.Map, Callable)}
+     */
+    @Deprecated
     public static void assertEventually(Map flags=[:], Callable c) {
         executeUntilSucceeds(flags, c);
     }
+    
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Runnable)}
+     */
+    @Deprecated
     public static void assertEventually(Map flags=[:], Runnable c) {
         executeUntilSucceeds(flags, c);
     }
 
-    //FIXME rename these to assertEventually, refactor to have boolean blockUntil in some other util class
-    //FIXME remove dupilcation with LanguageUtils.repeatUntilSuccess
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Callable)}
+     */
+    @Deprecated
     public static void executeUntilSucceeds(Map flags=[:], Closure c) {
-        executeUntilSucceedsWithFinallyBlock(flags, c) { }
+        Asserts.succeedsEventually(flags, c);
     }
 
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Callable)}
+     */
+    @Deprecated
     public static void executeUntilSucceeds(Map flags=[:], Callable c) {
-        executeUntilSucceedsWithFinallyBlock(flags, c) { }
+        Asserts.succeedsEventually(flags, c);
     }
     
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Runnable)}
+     */
+    @Deprecated
     public static void executeUntilSucceeds(Map flags=[:], Runnable r) {
         if (r in Callable) 
             executeUntilSucceedsWithFinallyBlock(flags, {return ((Callable)r).call();}, { })
@@ -123,6 +147,10 @@ public class TestUtils {
             executeUntilSucceedsWithFinallyBlock(flags, {r.run(); return true}, { })
     }
 
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Callable)}, and tear-down with {@link AfterMethod}.
+     */
+    @Deprecated
     public static void executeUntilSucceedsElseShutdown(Map flags=[:], Entity entity, Closure c) {
         try { 
             executeUntilSucceedsWithFinallyBlock(flags, c) { }
@@ -132,11 +160,20 @@ public class TestUtils {
         }
     }
 
-    /** convenience for entities to ensure they shutdown afterwards */
+    /**
+     * convenience for entities to ensure they shutdown afterwards.
+     * 
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Callable)}, and tear-down with {@link AfterMethod}.
+     */
+    @Deprecated
     public static void executeUntilSucceedsWithShutdown(Map flags=[:], Entity entity, Closure c) {
         executeUntilSucceedsWithFinallyBlock(flags, c) { entity.stop() }
     }
 
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Callable)}, and tear-down with {@link AfterMethod}.
+     */
+    @Deprecated
     public static void executeUntilSucceedsWithFinallyBlock(Map flags=[:], Closure c, Closure finallyBlock={}) {
         executeUntilSucceedsWithFinallyBlockInternal(flags, c, finallyBlock)
     }
@@ -162,11 +199,20 @@ public class TestUtils {
      * @param flags, accepts the flags listed above
      * @param r
      * @param finallyBlock
+     * 
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Callable)}, and tear-down with {@link AfterMethod}.
      */
+    @Deprecated
     public static void executeUntilSucceedsWithFinallyBlock(Map flags=[:], Callable<?> c, Closure finallyBlock={}) {
         executeUntilSucceedsWithFinallyBlockInternal(flags, c, finallyBlock);
     }
-    /** the "real" implementation, renamed to allow multiple entry points (depending whether closure cast to callable) */
+    
+    /**
+     * the "real" implementation, renamed to allow multiple entry points (depending whether closure cast to callable)
+     * 
+     * @deprecated since 0.5; use {@link Asserts#succeedsEventually(Map, Callable)}, and tear-down with {@link AfterMethod}.
+     */
+    @Deprecated
     private static void executeUntilSucceedsWithFinallyBlockInternal(Map flags=[:], Callable<?> c, Closure finallyBlock={}) {
 //        log.trace "abortOnError = {}", flags.abortOnError
         boolean abortOnException = flags.abortOnException ?: false
@@ -229,11 +275,19 @@ public class TestUtils {
         }
     }
 
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsContinually(Map, Runnable)}
+     */
+    @Deprecated
     public static <T> void assertSucceedsContinually(Map flags=[:], Runnable job) {
         assertSucceedsContinually(flags, Executors.callable(job));
     }
     
-    public static <T> void assertSucceedsContinually(Map flags=[:], Callable<T> job) {
+    /**
+     * @deprecated since 0.5; use {@link Asserts#succeedsContinually(Map, Callable)}
+     */
+    @Deprecated
+    public static void assertSucceedsContinually(Map flags=[:], Callable<?> job) {
         TimeDuration duration = toTimeDuration(flags.timeout) ?: new TimeDuration(0,0,1,0)
         TimeDuration period = toTimeDuration(flags.period) ?: new TimeDuration(0,0,0,10)
         long periodMs = period.toMilliseconds()
@@ -249,7 +303,7 @@ public class TestUtils {
     }
     
     /**
-     * @deprecated since 0.5; use {@link Asserts.continually(Map, Supplier, Predicate)}
+     * @deprecated since 0.5; use {@link Asserts#continually(Map, Supplier, Predicate)}
      */
     @Deprecated
     // FIXME When calling from java, the generics declared in groovy messing things up!
@@ -258,7 +312,7 @@ public class TestUtils {
     }
     
     /**
-     * @deprecated since 0.5; use {@link Asserts.continually(Map, Supplier, Predicate)}
+     * @deprecated since 0.5; use {@link Asserts#continually(Map, Supplier, Predicate)}
      */
     @Deprecated
     public static <T> void assertContinually(Map flags=[:], Supplier<? extends T> supplier, Predicate<T> predicate) {
@@ -266,7 +320,7 @@ public class TestUtils {
     }
 
     /**
-     * @deprecated since 0.5; use {@link Asserts.continually(Map, Supplier, Predicate, String)}
+     * @deprecated since 0.5; use {@link Asserts#continually(Map, Supplier, Predicate, String)}
      */
     @Deprecated
     public static <T> void assertContinually(Map flags=[:], Supplier<? extends T> supplier, Predicate<T> predicate, String errMsg, long durationMs) {
@@ -275,7 +329,7 @@ public class TestUtils {
     }
     
     /**
-     * @deprecated since 0.5; use {@link Asserts.continually(Map, Supplier, Predicate, String)}
+     * @deprecated since 0.5; use {@link Asserts#continually(Map, Supplier, Predicate, String)}
      */
     @Deprecated
     public static <T> void assertContinually(Map flags=[:], Supplier<? extends T> supplier, Predicate<T> predicate, String errMsg) {
@@ -295,6 +349,10 @@ public class TestUtils {
         }
     }
     
+    /**
+     * @deprecated since 0.5; use {@link brooklyn.util.ResourceUtils}
+     */
+    @Deprecated
     public static File getResource(String path, ClassLoader loader) {
         URL resource = loader.getResource(path)
         if (resource==null)
@@ -303,10 +361,18 @@ public class TestUtils {
         return new File(resource.path)
     }
 
+    /**
+     * @deprecated since 0.5; use long and {@link TimeUnit}
+     */
+    @Deprecated
     public static TimeDuration toTimeDuration(Object duration) {
         return toTimeDuration(duration, null);
     }
             
+    /**
+     * @deprecated since 0.5; use long and {@link TimeUnit}
+     */
+    @Deprecated
     public static TimeDuration toTimeDuration(Object duration, TimeDuration defaultVal) {
         if (duration == null) {
             return defaultVal;
@@ -356,30 +422,56 @@ public class TestUtils {
         }
     }
 
+    /**
+     * @deprecated since 0.5; use {@link EntityTestUtils#assertAttributeEqualsEventually(Entity, AttributeSensor, Object)}
+     */
+    @Deprecated
     public static <T> void assertAttributeEventually(Entity entity, AttributeSensor<T> attribute, T expected) {
         executeUntilSucceeds() {
             assertEquals(entity.getAttribute(attribute), expected);
         }
     }
     
+    /**
+     * @deprecated since 0.5; use {@link EntityTestUtils#assertAttributeEqualsContinually(Entity, AttributeSensor, Object)}
+     */
+    @Deprecated
     public static <T> void assertAttributeContinually(Entity entity, AttributeSensor<T> attribute, T expected) {
         assertSucceedsContinually() {
             assertEquals(entity.getAttribute(attribute), expected);
         }
     }
     
+    /**
+     * @deprecated since 0.5; use {@link HttpTestUtils#assertHttpStatusCodeEquals(String, int)}
+     */
+    @Deprecated
     public static void assertUrlStatusCodeEventually(final String url, final int expected) {
         executeUntilSucceeds() {
             assertEquals(urlRespondsStatusCode(url), expected);
         }
     }
 
+    /**
+     * @deprecated since 0.5; use {@link Asserts#assertFails(Runnable)}
+     */
+    @Deprecated
     public static void assertFails(Runnable c) {
         assertFailsWith(c, (Predicate)null);
     }
+    
+    /**
+     * @deprecated since 0.5; use {@link Asserts#assertFailsWith(Closure)}
+     */
+    @Deprecated
     public static void assertFailsWith(Runnable c, Closure exceptionChecker) {
         assertFailsWith(c, exceptionChecker as Predicate);
     }
+    
+    /**
+     * @deprecated since 0.5; use {@link Asserts#assertFailsWith(Runnable, Class, Class...)}
+     */
+    @Deprecated
     public static void assertFailsWith(Runnable c, final Class<? extends Throwable> validException, final Class<? extends Throwable> ...otherValidExceptions) {
         assertFailsWith(c, { e -> 
             if (validException.isInstance(e)) return true;
@@ -389,6 +481,11 @@ public class TestUtils {
             fail("Test threw exception of unexpected type "+e.getClass()+"; expecting "+expectedTypes);             
         });
     }
+    
+    /**
+     * @deprecated since 0.5; use {@link Asserts#assertFailsWith(Runnable, Predicate)}
+     */
+    @Deprecated
     public static void assertFailsWith(Runnable c, Predicate<Throwable> exceptionChecker) {
         boolean failed = false;
         try {
@@ -413,11 +510,19 @@ public class TestUtils {
         if (!s.isEmpty()) fail("Second argument contains additional contents: "+s);
     }
     
+    /**
+     * @deprecated since 0.5; use {@code assertFalse(Iterables.isEmpty(c))}
+     */
+    @Deprecated
     public static <T> void assertNonEmpty(Iterable<T> c) {
         if (c.iterator().hasNext()) return;
         fail("Expected non-empty set");
     }
 
+    /**
+     * @deprecated since 0.5; use {@code assertEquals(Iterables.size(c), expectedSize)}
+     */
+    @Deprecated
     public static <T> void assertSize(Iterable<T> c, int expectedSize) {
         int actualSize = Iterables.size(c);
         if (actualSize==expectedSize) return;