From e0809a21dc560c8a47f1fce7d328b9564fd985fb Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 21 Dec 2015 16:24:12 +0100 Subject: [PATCH] use synchronization to exclude the possibility of the Java Memory Model causing trouble in SmartFutureCacheTest with concurrency Change-Id: Ibbb726f3c32ddf748bab05300a32b7ed165940f3 --- .../sailing/domain/test/SmartFutureCacheTest.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SmartFutureCacheTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SmartFutureCacheTest.java index fac12b17506..38db6cd2252 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SmartFutureCacheTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/SmartFutureCacheTest.java @@ -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 sfc = new SmartFutureCache( new SmartFutureCache.AbstractCacheUpdater() { @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");