From cc0a346289e5d392ca89311df3719891267e3248 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Mon, 2 Nov 2009 09:11:13 +0000 Subject: [PATCH] utility for eventual consistency testing git-svn-id: http://jclouds.googlecode.com/svn/trunk@2036 3d8758e0-26b5-11de-8745-db77d3ebf521 --- core/src/main/java/org/jclouds/util/Utils.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/org/jclouds/util/Utils.java b/core/src/main/java/org/jclouds/util/Utils.java index eda9605f73..a4776b9f44 100644 --- a/core/src/main/java/org/jclouds/util/Utils.java +++ b/core/src/main/java/org/jclouds/util/Utils.java @@ -39,6 +39,7 @@ import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpResponse; import org.jclouds.logging.Logger; +import com.google.common.base.Supplier; import com.google.common.collect.ComputationException; /** @@ -49,6 +50,19 @@ import com.google.common.collect.ComputationException; public class Utils { public static final String UTF8_ENCODING = "UTF-8"; + public static boolean enventuallyTrue(Supplier assertion, long inconsistencyMillis) throws InterruptedException { + + for (int i = 0; i < 30; i++) { + if (!assertion.get()) { + Thread.sleep(inconsistencyMillis / 30); + continue; + } + return true; + } + return false; + + } + @Resource protected static Logger logger = Logger.NULL;