use synchronization to exclude the possibility of the Java Memory Model causing trouble in SmartFutureCacheTest with concurrency

Change-Id: Ibbb726f3c32ddf748bab05300a32b7ed165940f3
This commit is contained in:
Axel Uhl committed 2015-12-21 16:24:12 +01:00
1 parent d17e900b81
commit e0809a21dc
1 file changed
+9 -5
@@ -53,15 +53,19 @@ public class SmartFutureCacheTest {
@Test
public void testExceptionInComputeCacheUpdate() {
final boolean[] throwException = new boolean[1];
throwException[0] = true;
synchronized (this) { // make sure that other threads see this after the synchronized block has completed
throwException[0] = true;
}
SmartFutureCache<String, String, EmptyUpdateInterval> sfc = new SmartFutureCache<String, String, SmartFutureCache.EmptyUpdateInterval>(
new SmartFutureCache.AbstractCacheUpdater<String, String, SmartFutureCache.EmptyUpdateInterval>() {
@Override
public String computeCacheUpdate(String key, EmptyUpdateInterval updateInterval) {
if (throwException[0]) {
throw new NullPointerException("Humba");
} else {
return "Humba";
synchronized (SmartFutureCacheTest.this) { // make sure we see the latest change to throwException
if (throwException[0]) {
throw new NullPointerException("Humba");
} else {
return "Humba";
}
}
}
}, "SmartFutureCacheTest.testExceptionInComputeCacheUpdate");