From: Robert Varga Date: Sat, 29 Jun 2019 11:11:12 +0000 (+0200) Subject: Remove CacheUtil and CacheTestUtil X-Git-Tag: release/aluminium~13 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=3893b3dc7918767bf7f6882befda1cce8a498d94;p=genius.git Remove CacheUtil and CacheTestUtil CacheUtil has only a single user in netvirt, which is being removed and CacheTestUtil has only a single internal user. Remove them both. Change-Id: I6e7e4311f60f82ec87e13a248657bc89d1bb759d Signed-off-by: Robert Varga --- diff --git a/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmTest.java b/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmTest.java index 7cab3e3e6..daa7dd51c 100644 --- a/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmTest.java +++ b/itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmTest.java @@ -17,7 +17,6 @@ import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorEventsWait import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorTestModule; import org.opendaylight.genius.datastoreutils.testutils.TestableDataTreeChangeListenerModule; import org.opendaylight.genius.itm.impl.ItmTestUtils; -import org.opendaylight.genius.utils.cache.CacheTestUtil; import org.opendaylight.infrautils.caches.testutils.CacheModule; import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule; import org.opendaylight.infrautils.testutils.LogCaptureRule; @@ -48,11 +47,10 @@ public class ItmTest { clearCaches(); } - private void clearCaches() { + private static void clearCaches() { // Explicitly clear stupid static caches // (TODO which really need to be de-static-ified instead of doing this..) ItmTestUtils.clearAllItmCaches(); - CacheTestUtil.clearAllCaches(); } @Test diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/cache/CacheUtil.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/cache/CacheUtil.java deleted file mode 100644 index f2bc89567..000000000 --- a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/utils/cache/CacheUtil.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.genius.utils.cache; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * Cache wannabe. - * - *

This class wanted to be Cache when it was grown up. Currently it's actually just - * a nested ConcurrentMap, and thus has fairly limited real value. - * - *

The usage of static methods here, instead of an (OSGi) "service" - * (dependency inject-able in tests!) makes it impossible to easily properly - * use code relying on this in component tests (as there would be no automatic - * reset between tests; you would have to manually {@link #destroyCache(String)} - * {@literal @}Before each test). - * - *

This class' "static" Singleton doesn't play nice with OSGi e.g. for hot reload. - * - *

This class' (necessary) use <?> generics causes {@literal @}SuppressWarnings("unchecked") when used. - * - *

Perhaps you would like to use - * Google Guava's simple Caches, if not a full blown JSR 107 javax.cache (JCache) implementation, - * such as Infinispan or Ehcache, - * instead of this class? - * - * @deprecated We now recommend you simply use your own {@code new ConcurrentHashMap<>()} instead. - * - * @author unascribed (Ericsson India?) - original code - * @author Michael Vorburger.ch - JavaDoc - */ -@Deprecated -public final class CacheUtil { - - // package local instead of private for CacheTestUtil - static final ConcurrentMap> MAP_OF_MAP = new ConcurrentHashMap<>(); - - private CacheUtil() { - - } - - public static ConcurrentMap getCache(String cacheName) { - return MAP_OF_MAP.get(cacheName); - } - - public static void createCache(String cacheName) { - MAP_OF_MAP.computeIfAbsent(cacheName, k -> new ConcurrentHashMap<>()); - } - - public static boolean isCacheValid(String cacheName) { - return MAP_OF_MAP.containsKey(cacheName); - } - - public static void destroyCache(String cacheName) { - MAP_OF_MAP.remove(cacheName); - } -} diff --git a/mdsalutil/mdsalutil-api/src/test/java/org/opendaylight/genius/utils/cache/CacheTestUtil.java b/mdsalutil/mdsalutil-api/src/test/java/org/opendaylight/genius/utils/cache/CacheTestUtil.java deleted file mode 100644 index d22e17865..000000000 --- a/mdsalutil/mdsalutil-api/src/test/java/org/opendaylight/genius/utils/cache/CacheTestUtil.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.genius.utils.cache; - -/** - * Utility for use in tests which cover code that still ;-( use the deprecated CacheUtil. - * - * @author Michael Vorburger - */ -public final class CacheTestUtil { - - private CacheTestUtil() { - } - - @SuppressWarnings("deprecation") - public static void clearAllCaches() { - CacheUtil.MAP_OF_MAP.clear(); - } -}