You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2010/04/09 19:47:32 UTC
svn commit: r932530 -
/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/CacheTest.java
Author: dwoods
Date: Fri Apr 9 17:47:32 2010
New Revision: 932530
URL: http://svn.apache.org/viewvc?rev=932530&view=rev
Log:
OPENJPA-1624 Fix intermittent datacache timeout failures in TestSJVMCache and CacheTest
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/CacheTest.java
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/CacheTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/CacheTest.java?rev=932530&r1=932529&r2=932530&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/CacheTest.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/CacheTest.java Fri Apr 9 17:47:32 2010
@@ -985,6 +985,9 @@ public abstract class CacheTest extends
try {
startTx(em);
+ // get starting time for sleep calculations below
+ Date startTime = new Date();
+
CacheObjectE e = new CacheObjectE("e");
em.persist(e);
@@ -996,7 +999,7 @@ public abstract class CacheTest extends
CacheObjectH h = new CacheObjectH("h");
em.persist(h);
-
+
endTx(em);
Object[] ids = new Object[4];
@@ -1023,14 +1026,39 @@ public abstract class CacheTest extends
iterate((Collection) q2.execute());
assertInCache(q2, Boolean.TRUE);
+ Date currentTime = new Date();
+ long diff = (currentTime.getTime() - startTime.getTime());
+ long sleep = 0;
+
+ getLog().info("CacheTest.timeoutsHelper() testing all are still in the cache, elapsed time="+diff);
DataCache cache = cacheManager(factory).getDataCache(
DataCache.NAME_DEFAULT, false);
- checkCache(cache, ids, new boolean[]{ true, true, true, true });
-
+ if (diff < 500) {
+ // all should still be in the cache
+ checkCache(cache, ids, new boolean[]{ true, true, true, true });
+ } else {
+ // need to skip the test on slow systems or when using remote DB connections
+ getLog().warn("CacheTest.timeoutsHelper() skipping checkCache(all, <500) because diff="+diff);
+ }
+
// should cause h to be dropped (timeout=500)
- Thread.currentThread().sleep(600);
- Thread.yield();
- checkCache(cache, ids, new boolean[]{ true, true, true, false });
+ currentTime = new Date();
+ diff = (currentTime.getTime() - startTime.getTime());
+ sleep = 750 - diff;
+ if (sleep > 0) {
+ getLog().info("CacheTest.timeoutsHelper() testing h to be dropped by waiting sleep="+sleep);
+ Thread.currentThread().sleep(sleep);
+ Thread.yield();
+ } else {
+ sleep = 0;
+ }
+ if ((diff + sleep) < 950) {
+ // only h should be dropped
+ checkCache(cache, ids, new boolean[]{ true, true, true, false });
+ } else {
+ // need to skip the test on slow systems or when using remote DB connections
+ getLog().warn("CacheTest.timeoutsHelper() skipping checkCache(h=500) because diff="+(diff+sleep));
+ }
// if this run has a default timeout (set to 1 sec in the test
// case), e should be timed out by this point.
@@ -1040,10 +1068,23 @@ public abstract class CacheTest extends
.getConfiguration()).getDataCacheTimeout() > 0);
// should cause f to be dropped (timeout=1000)
- Thread.currentThread().sleep(500);
- Thread.yield();
- checkCache(cache, ids,
- new boolean[]{ eStatus, false, true, false });
+ currentTime = new Date();
+ diff = currentTime.getTime() - startTime.getTime();
+ sleep = 2000 - diff;
+ if (sleep > 0) {
+ getLog().info("CacheTest.timeoutsHelper() testing f to be dropped by waiting sleep="+sleep);
+ Thread.currentThread().sleep(sleep);
+ Thread.yield();
+ } else {
+ sleep = 0;
+ }
+ if ((diff + sleep) < 4900) {
+ // e is conditional, h and f should be dropped, but not g yet
+ checkCache(cache, ids, new boolean[]{ eStatus, false, true, false });
+ } else {
+ // need to skip the test on slow systems or when using remote DB connections
+ getLog().warn("CacheTest.timeoutsHelper() skipping checkCache(f=1000) because diff="+(diff+sleep));
+ }
// at this point, q2 should be dropped (because its candidate
// class is CacheObjectF), and q1 might be dropped, depending
@@ -1052,10 +1093,16 @@ public abstract class CacheTest extends
assertInCache(q2, Boolean.FALSE);
// should cause g to be dropped (timeout=5000)
- Thread.currentThread().sleep(4000);
- Thread.yield();
- checkCache(cache, ids,
- new boolean[]{ eStatus, false, false, false });
+ currentTime = new Date();
+ diff = currentTime.getTime() - startTime.getTime();
+ sleep = 6000 - diff;
+ if (sleep > 0) {
+ getLog().info("CacheTest.timeoutsHelper() testing g to be dropped by waiting sleep="+sleep);
+ Thread.currentThread().sleep(sleep);
+ Thread.yield();
+ }
+ // all of them should be dropped now, since diff > 5000
+ checkCache(cache, ids, new boolean[]{ eStatus, false, false, false });
}
finally {
endEm(em);
@@ -1074,6 +1121,9 @@ public abstract class CacheTest extends
try {
startTx(em);
+ // get starting time for sleep calculations below
+ Date startTime = new Date();
+
CacheObjectE e = new CacheObjectE("e");
em.persist(e);
@@ -1105,7 +1155,14 @@ public abstract class CacheTest extends
.getDataCacheTimeout() > 0);
// should cause f to be dropped.
- Thread.currentThread().sleep(1100);
+ Date currentTime = new Date();
+ long diff = currentTime.getTime() - startTime.getTime();
+ long sleep = 2000 - diff;
+ if (sleep > 0) {
+ getLog().trace("CacheTest.queryTimeoutsHelper() testing f to be dropped by waiting sleep="+sleep);
+ Thread.currentThread().sleep(sleep);
+ Thread.yield();
+ }
// at this point, q2 should be dropped (because its candidate
// class is CacheObjectF), and q1 might be dropped, depending