BUG-4803: invalidate cache before each test 66/31766/3
authorRobert Varga <rovarga@cisco.com>
Tue, 22 Dec 2015 11:04:10 +0000 (12:04 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 4 Jan 2016 10:39:07 +0000 (10:39 +0000)
Running tests will pollute the cache, so we need to clear it before each
test.

Change-Id: I0cc171c22409d81092d82d5570a3c0068bbfc889
Signed-off-by: Robert Varga <rovarga@cisco.com>
common/util/src/main/java/org/opendaylight/yangtools/util/OffsetMapCache.java
common/util/src/test/java/org/opendaylight/yangtools/util/OffsetMapTest.java

index e99a4f8a0692ee853ba80e952ab27fcd8a62e83e..b9776e3421bab45dffdcaa6f0066d73e5a9be261 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.util;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -42,6 +43,11 @@ final class OffsetMapCache {
         return (Map<T, Integer>) CACHE.getUnchecked(args);
     }
 
+    @VisibleForTesting
+    static void invalidateCache() {
+        CACHE.invalidateAll();
+    }
+
     static <T> Map<T, Integer> orderedOffsets(final Collection<T> args) {
         if (args.size() == 1) {
             return unorderedOffsets(args);
index 4c4f6bbf18ebe7ae9f5bc418c0e90662884d290c..17a6f2e1edf8d308b76e258d2363e6cb90daadae 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NoSuchElementException;
 import java.util.Set;
+import org.junit.Before;
 import org.junit.Test;
 
 public class OffsetMapTest {
@@ -39,6 +40,11 @@ public class OffsetMapTest {
         return (ImmutableOffsetMap<String, String>) ImmutableOffsetMap.copyOf(twoEntryMap);
     }
 
+    @Before
+    public void setup() {
+        OffsetMapCache.invalidateCache();
+    }
+
     @Test(expected=IllegalArgumentException.class)
     public void testWrongImmutableConstruction() {
         new ImmutableOffsetMap.Ordered<String, String>(Collections.<String, Integer>emptyMap(), new String[1]);