Merge pull request #255 from andreisavu/retryable-transient

Fix transient RetryablePredicate unit test failure
This commit is contained in:
Adrian Cole 2011-12-18 13:38:26 -08:00
commit db953d469f
1 changed files with 18 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import com.google.common.base.Joiner;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -32,6 +33,9 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import org.testng.collections.Lists;
import static org.testng.Assert.fail;
/** /**
* *
@ -119,7 +123,7 @@ public class RetryablePredicateTest {
stopwatch.start(); stopwatch.start();
predicate.apply(""); predicate.apply("");
long duration = stopwatch.elapsedMillis(); long duration = stopwatch.elapsedMillis();
assertOrdered(3000, duration, 3000+SLOW_BUILD_SERVER_GRACE); assertOrdered(2998, duration, 3000+SLOW_BUILD_SERVER_GRACE);
} }
@Test @Test
@ -179,10 +183,19 @@ public class RetryablePredicateTest {
} }
} }
private void assertOrdered(long... vals) { private void assertOrdered(long... values) {
long prevVal = vals[0]; long prevVal = values[0];
for (long val : vals) { for (long val : values) {
assert val >= prevVal : String.format("%s should be ordered", vals); if (val < prevVal) {
fail(String.format("%s should be ordered", asString(values)));
}
} }
} }
private String asString(long... values) {
List<Long> result = Lists.newArrayList(values.length);
for(long element : values) result.add(element);
return "[" + Joiner.on(", ").join(result) + "]";
}
} }