Author: manik.surtani(a)jboss.com
Date: 2008-03-07 12:39:36 -0500 (Fri, 07 Mar 2008)
New Revision: 5402
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
Log:
Fixed bug in wait loop
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2008-03-07
17:10:29 UTC (rev 5401)
+++
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2008-03-07
17:39:36 UTC (rev 5402)
@@ -164,7 +164,7 @@
}
// check if we have started.
- if (cache.getCacheStatus().allowInvocations())
+ if (!cache.getCacheStatus().allowInvocations())
throw new IllegalStateException("Cache not in STARTED state, even after
waiting " + configuration.getStateRetrievalTimeout() + " millis.");
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java 2008-03-07 17:10:29 UTC
(rev 5401)
+++ core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java 2008-03-07 17:39:36 UTC
(rev 5402)
@@ -32,23 +32,7 @@
@AfterMethod
public void tearDown()
{
- if (c != null)
- {
- for (Cache cache : c)
- {
- if (cache != null)
- {
- try
- {
- cache.stop();
- }
- catch (Exception e)
- {
- // do nothing
- }
- }
- }
- }
+ TestingUtil.killCaches(c);
c = null;
}
@@ -286,10 +270,15 @@
{
createAndRegisterCache(Configuration.CacheMode.REPL_SYNC, true);
createAndRegisterCache(Configuration.CacheMode.REPL_SYNC, true);
+ TestingUtil.blockUntilViewsReceived(c, 10000);
try
{
// now DIRECTLY change the status of c2.
// emulate the race condition where the remote cache is stopping but hasn't
disconnected from the channel.
+
+ // there is a lousy race condition here - we need to make sure cache[1]'s
start() method doesn't set status to STARTED
+ // after we attempt to change this.
+ TestingUtil.blockUntilCacheStatusAchieved(c[1], CacheStatus.STARTED, 1000);
CacheImpl ci1 = (CacheImpl) TestingUtil.extractField(c[1], "cache");
ci1.cacheStatus = CacheStatus.STARTING;
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-03-07 17:10:29 UTC
(rev 5401)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-03-07 17:39:36 UTC
(rev 5402)
@@ -533,4 +533,23 @@
ComponentRegistry cr = extractComponentRegistry(cache);
return cr.getComponent("remoteDelegate",
RemoteCacheInvocationDelegate.class);
}
+
+ /**
+ * Blocks until the cache has reached a specified state.
+ *
+ * @param cache cache to watch
+ * @param cacheStatus status to wait for
+ * @param timeout timeout to wait for
+ */
+ public static void blockUntilCacheStatusAchieved(Cache cache, CacheStatus cacheStatus,
long timeout)
+ {
+ CacheSPI spi = (CacheSPI) cache;
+ long killTime = System.currentTimeMillis() + timeout;
+ while (System.currentTimeMillis() < killTime)
+ {
+ if (spi.getCacheStatus() == cacheStatus) return;
+ sleepThread(50);
+ }
+ throw new RuntimeException("Timed out waiting for condition");
+ }
}
Show replies by thread