Author: manik.surtani(a)jboss.com
Date: 2008-04-28 19:19:14 -0400 (Mon, 28 Apr 2008)
New Revision: 5738
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java
Log:
Improved test
Modified: core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java 2008-04-28
19:09:53 UTC (rev 5737)
+++
core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java 2008-04-28
23:19:14 UTC (rev 5738)
@@ -55,7 +55,6 @@
STOPPED, STARTING, STARTED
}
-
static
{
try
@@ -108,7 +107,6 @@
*/
protected Object invokeWithRetries(Method m, Object... params)
{
-// assertValidState(); // needs more thought
long endTime = System.currentTimeMillis() + config.getTimeout();
do
{
@@ -412,22 +410,6 @@
}
}
- private void assertValidState()
- {
- while (state == State.STARTING)
- {
- try
- {
- Thread.sleep(100);
- }
- catch (InterruptedException e)
- {
- // do nothing
- }
- }
- if (state != State.STARTED) throw new CacheException("Cache Loader not
started!");
- }
-
protected void restart() throws IOException
{
stop();
Modified: core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java 2008-04-28
19:09:53 UTC (rev 5737)
+++ core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java 2008-04-28
23:19:14 UTC (rev 5738)
@@ -20,6 +20,8 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* Tests the TcpDelegatingCacheLoader
@@ -33,11 +35,13 @@
protected static final int CACHE_SERVER_RESTART_DELAY_MS = 1000;
protected static final int TCP_CACHE_LOADER_TIMEOUT_MS = 2000;
protected static int START_COUNT = 0;
- static TcpCacheServer cache_server = null;
+ static TcpCacheServer cacheServer = null;
@BeforeClass
public static void startCacheServer()
{
+ final CountDownLatch startedSignal = new CountDownLatch(1);
+
Thread t = new Thread()
{
public void run()
@@ -45,15 +49,16 @@
try
{
System.out.println("Starting TcpCacheServer");
- cache_server = new TcpCacheServer();
- cache_server.setBindAddress("127.0.0.1");
- cache_server.setPort(12121);
+ cacheServer = new TcpCacheServer();
+ cacheServer.setBindAddress("127.0.0.1");
+ cacheServer.setPort(12121);
Configuration config =
UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL,
true);
CacheSPI cache = (CacheSPI) new
DefaultCacheFactory().createCache(config);
- cache_server.setCache(cache);
- cache_server.create();
- cache_server.start();
+ cacheServer.setCache(cache);
+ cacheServer.create();
+ cacheServer.start();
START_COUNT++;
+ startedSignal.countDown();
}
catch (Exception ex)
{
@@ -64,17 +69,32 @@
};
t.setDaemon(true);
t.start();
- // give the cache server 2 secs to start up
- TestingUtil.sleepThread(2000);
+
+ // Wait for the cache server to start up.
+ boolean started = false;
+ try
+ {
+ started = startedSignal.await(120, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ // do nothing
+ }
+
+ if (!started)
+ {
+ // the TcpCacheServer was unable to start up for some reason!!
+ throw new RuntimeException("Unable to start the TcpCacheServer after 120
seconds!!");
+ }
}
@AfterClass
public static void stopCacheServer()
{
- if (cache_server != null)
+ if (cacheServer != null)
{
System.out.println("Stopping TcpCacheServer");
- cache_server.stop();
+ cacheServer.stop();
}
}
@@ -104,7 +124,6 @@
}
// restart tests
-
public void testCacheServerRestartMidCall() throws Exception
{
CacheServerRestarter restarter = new CacheServerRestarter();
Show replies by date