From 0656fa3ef42e70f40a57540da4537d1ec4800a70 Mon Sep 17 00:00:00 2001 From: mishako Date: Tue, 19 Jul 2016 10:35:05 +0200 Subject: [PATCH] Fix license test in cc module There was a race condition in the test. The value passed to the Random::nextInt method could sometimes be zero due to the other thread not incrementing it in time. --- .../com/rometools/modules/cc/types/LicenseTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rome-modules/src/test/java/com/rometools/modules/cc/types/LicenseTest.java b/rome-modules/src/test/java/com/rometools/modules/cc/types/LicenseTest.java index 781fb5a..58ae6e4 100644 --- a/rome-modules/src/test/java/com/rometools/modules/cc/types/LicenseTest.java +++ b/rome-modules/src/test/java/com/rometools/modules/cc/types/LicenseTest.java @@ -23,11 +23,13 @@ import java.util.concurrent.atomic.AtomicLong; import org.junit.Before; import org.junit.Test; - -import com.rometools.modules.cc.types.License; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class LicenseTest { + private static final Logger LOG = LoggerFactory.getLogger(LicenseTest.class); + @Before public void setUp() { // As the looked up licenses are held statically we need to clear this between tests. @@ -54,6 +56,7 @@ public class LicenseTest { } } } catch (final Exception e) { + LOG.error("Exception in add-new thread", e); hadException.set(true); } } @@ -66,12 +69,17 @@ public class LicenseTest { final Random rnd = new Random(); try { while (run.get()) { + if (type.intValue() == 0) { + continue; + } + final License license = License.findByValue("http://creativecommons.org/licenses/" + rnd.nextInt(type.intValue()) + "/1"); if (license == null) { hadProblem.set(true); } } } catch (final Exception e) { + LOG.error("Exception in get-existing thread", e); hadException.set(true); } }