[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/misc ...
Manik Surtani
manik at jboss.org
Fri May 25 12:34:51 EDT 2007
User: msurtani
Date: 07/05/25 12:34:51
Modified: tests/functional/org/jboss/cache/misc TestingUtil.java
Log:
Fixed some pretty nasty BR issues
Revision Changes Path
1.13 +62 -27 JBossCache/tests/functional/org/jboss/cache/misc/TestingUtil.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TestingUtil.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/misc/TestingUtil.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- TestingUtil.java 16 Mar 2007 17:43:14 -0000 1.12
+++ TestingUtil.java 25 May 2007 16:34:51 -0000 1.13
@@ -27,7 +27,7 @@
private static Random random = new Random();
/**
- * Loops, continually calling {@link #areCacheViewsComplete(CacheSPI[])}
+ * Loops, continually calling {@link #areCacheViewsComplete(org.jboss.cache.Cache[])}
* until it either returns true or <code>timeout</code> ms have elapsed.
*
* @param caches caches which must all have consistent views
@@ -85,6 +85,32 @@
}
/**
+ * An overloaded version of {@link #blockUntilViewsReceived(long,org.jboss.cache.Cache[])} that allows for 'shrinking' clusters.
+ * I.e., the usual method barfs if there are more members than expected. This one takes a param (barfIfTooManyMembers) which,
+ * if false, will NOT barf but will wait until the cluster 'shrinks' to the desired size. Useful if in tests, you kill
+ * a member and want to wait until this fact is known across the cluster.
+ *
+ * @param timeout
+ * @param barfIfTooManyMembers
+ * @param caches
+ */
+ public static void blockUntilViewsReceived(long timeout, boolean barfIfTooManyMembers, Cache... caches)
+ {
+ long failTime = System.currentTimeMillis() + timeout;
+
+ while (System.currentTimeMillis() < failTime)
+ {
+ sleepThread(100);
+ if (areCacheViewsComplete(caches, barfIfTooManyMembers))
+ {
+ return;
+ }
+ }
+
+ throw new RuntimeException("timed out before caches had complete views");
+ }
+
+ /**
* Loops, continually calling {@link #areCacheViewsComplete(CacheImpl[])}
* until it either returns true or <code>timeout</code> ms have elapsed.
*
@@ -147,11 +173,16 @@
*/
public static boolean areCacheViewsComplete(Cache[] caches)
{
+ return areCacheViewsComplete(caches, true);
+ }
+
+ public static boolean areCacheViewsComplete(Cache[] caches, boolean barfIfTooManyMembers)
+ {
int memberCount = caches.length;
for (int i = 0; i < memberCount; i++)
{
- if (!isCacheViewComplete(caches[i], memberCount))
+ if (!isCacheViewComplete(caches[i], memberCount, barfIfTooManyMembers))
{
return false;
}
@@ -173,15 +204,10 @@
*/
public static boolean areCacheViewsComplete(CacheImpl[] caches)
{
- int memberCount = caches.length;
-
- for (int i = 0; i < memberCount; i++)
- {
- CacheImpl cache = caches[i];
- return isCacheViewComplete(cache, memberCount);
- }
-
- return true;
+ if (caches == null) throw new NullPointerException("Cache impl array is null");
+ Cache[] c = new Cache[caches.length];
+ for (int i = 0; i < caches.length; i++) c[i] = caches[i];
+ return areCacheViewsComplete(c);
}
/**
@@ -222,11 +248,16 @@
}
/**
- * @param cache
+ * @param c
* @param memberCount
*/
public static boolean isCacheViewComplete(Cache c, int memberCount)
{
+ return isCacheViewComplete(c, memberCount, true);
+ }
+
+ public static boolean isCacheViewComplete(Cache c, int memberCount, boolean barfIfTooManyMembers)
+ {
CacheSPI cache = (CacheSPI) c;
List members = cache.getMembers();
if (members == null || memberCount > members.size())
@@ -235,6 +266,8 @@
}
else if (memberCount < members.size())
{
+ if (barfIfTooManyMembers)
+ {
// This is an exceptional condition
StringBuffer sb = new StringBuffer("Cache at address ");
sb.append(cache.getLocalAddress());
@@ -255,6 +288,8 @@
throw new IllegalStateException(sb.toString());
}
+ else return false;
+ }
return true;
}
More information about the jboss-cvs-commits
mailing list