mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-27 22:37:15 +00:00
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:
1 parent
d17e900b81
commit
e0809a21dc
1 file changed
+9
-5
+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");
|
||||
|
||||
Reference in new issue
Block a user