From adfae285dfa8fe4f01ffc76b2e4f44b45ac94fae Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Wed, 4 May 2022 17:43:47 -0400 Subject: [PATCH] Finish conversion from Guava Cache to Caffeine (#1616) * Finish conversion from Guava Cache to Caffeine --- .../registry/config/RegistryConfig.java | 12 ++--- .../google/registry/model/EppResource.java | 31 ++++-------- .../registry/model/index/ForeignKeyIndex.java | 48 ++++++++----------- .../google/registry/model/tld/Registry.java | 40 +++++++--------- .../model/tld/label/BaseDomainLabelList.java | 15 ------ .../model/tld/label/PremiumListDao.java | 43 ++++------------- .../model/tld/label/ReservedList.java | 38 +++++---------- .../tmch/TmchCertificateAuthority.java | 4 +- .../registry/tools/UpdateTldCommand.java | 2 +- .../registry/model/EppResourceTest.java | 4 +- .../model/index/ForeignKeyIndexTest.java | 4 +- .../model/tld/label/PremiumListDaoTest.java | 6 +-- .../registry/testing/TestCacheExtension.java | 2 +- .../registry/whois/WhoisActionTest.java | 6 +-- .../whois/WhoisCommandFactoryTest.java | 4 +- 15 files changed, 90 insertions(+), 169 deletions(-) diff --git a/core/src/main/java/google/registry/config/RegistryConfig.java b/core/src/main/java/google/registry/config/RegistryConfig.java index 7d9b2433a..39020954b 100644 --- a/core/src/main/java/google/registry/config/RegistryConfig.java +++ b/core/src/main/java/google/registry/config/RegistryConfig.java @@ -1448,13 +1448,13 @@ public final class RegistryConfig { * @see google.registry.model.tld.label.ReservedList * @see google.registry.model.tld.label.PremiumList */ - public static Duration getDomainLabelListCacheDuration() { - return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.domainLabelCachingSeconds); + public static java.time.Duration getDomainLabelListCacheDuration() { + return java.time.Duration.ofSeconds(CONFIG_SETTINGS.get().caching.domainLabelCachingSeconds); } /** Returns the amount of time a singleton should be cached in persist mode, before expiring. */ - public static Duration getSingletonCachePersistDuration() { - return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.singletonCachePersistSeconds); + public static java.time.Duration getSingletonCachePersistDuration() { + return java.time.Duration.ofSeconds(CONFIG_SETTINGS.get().caching.singletonCachePersistSeconds); } /** @@ -1476,8 +1476,8 @@ public final class RegistryConfig { /** * Returns the amount of time an EPP resource or key should be cached in memory before expiring. */ - public static Duration getEppResourceCachingDuration() { - return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.eppResourceCachingSeconds); + public static java.time.Duration getEppResourceCachingDuration() { + return java.time.Duration.ofSeconds(CONFIG_SETTINGS.get().caching.eppResourceCachingSeconds); } /** Returns the maximum number of EPP resources and keys to keep in in-memory cache. */ diff --git a/core/src/main/java/google/registry/model/EppResource.java b/core/src/main/java/google/registry/model/EppResource.java index 8bad5d6e4..7cb0ba13e 100644 --- a/core/src/main/java/google/registry/model/EppResource.java +++ b/core/src/main/java/google/registry/model/EppResource.java @@ -27,10 +27,9 @@ import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import com.github.benmanes.caffeine.cache.CacheLoader; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.annotations.VisibleForTesting; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; @@ -45,10 +44,10 @@ import google.registry.model.ofy.CommitLogManifest; import google.registry.model.transfer.TransferData; import google.registry.persistence.VKey; import google.registry.util.NonFinalForTesting; +import java.time.Duration; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.concurrent.ExecutionException; import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.AttributeOverride; @@ -57,7 +56,6 @@ import javax.persistence.Column; import javax.persistence.MappedSuperclass; import javax.persistence.Transient; import org.joda.time.DateTime; -import org.joda.time.Duration; /** An EPP entity object (i.e. a domain, contact, or host). */ @MappedSuperclass @@ -396,7 +394,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable { @Override public Map, EppResource> loadAll( - Iterable> keys) { + Set> keys) { return replicaTm().doTransactionless(() -> replicaTm().loadByKeys(keys)); } }; @@ -416,8 +414,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable { private static LoadingCache, EppResource> createEppResourcesCache( Duration expiry) { - return CacheBuilder.newBuilder() - .expireAfterWrite(java.time.Duration.ofMillis(expiry.getMillis())) + return CacheUtils.newCacheBuilder(expiry) .maximumSize(getEppResourceMaxCachedEntries()) .build(CACHE_LOADER); } @@ -439,11 +436,7 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable { if (!RegistryConfig.isEppResourceCachingEnabled()) { return tm().loadByKeys(keys); } - try { - return cacheEppResources.getAll(keys); - } catch (ExecutionException e) { - throw new RuntimeException("Error loading cached EppResources", e.getCause()); - } + return ImmutableMap.copyOf(cacheEppResources.getAll(keys)); } /** @@ -456,13 +449,9 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable { if (!RegistryConfig.isEppResourceCachingEnabled()) { return tm().loadByKey(key); } - try { - // Safe to cast because loading a Key returns an entity of type T. - @SuppressWarnings("unchecked") - T resource = (T) cacheEppResources.get(key); - return resource; - } catch (ExecutionException e) { - throw new RuntimeException("Error loading cached EppResources", e.getCause()); - } + // Safe to cast because loading a Key returns an entity of type T. + @SuppressWarnings("unchecked") + T resource = (T) cacheEppResources.get(key); + return resource; } } diff --git a/core/src/main/java/google/registry/model/index/ForeignKeyIndex.java b/core/src/main/java/google/registry/model/index/ForeignKeyIndex.java index 015f3b60b..9248b16f3 100644 --- a/core/src/main/java/google/registry/model/index/ForeignKeyIndex.java +++ b/core/src/main/java/google/registry/model/index/ForeignKeyIndex.java @@ -26,23 +26,22 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import static google.registry.util.CollectionUtils.entriesToImmutableMap; import static google.registry.util.TypeUtils.instantiate; +import com.github.benmanes.caffeine.cache.CacheLoader; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.annotations.VisibleForTesting; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.collect.Multimaps; -import com.google.common.collect.Streams; import com.googlecode.objectify.Key; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Index; import google.registry.config.RegistryConfig; import google.registry.model.BackupGroupRoot; +import google.registry.model.CacheUtils; import google.registry.model.EppResource; import google.registry.model.annotations.DeleteAfterMigration; import google.registry.model.annotations.ReportedOn; @@ -54,14 +53,14 @@ import google.registry.persistence.VKey; import google.registry.persistence.transaction.CriteriaQueryBuilder; import google.registry.persistence.transaction.JpaTransactionManager; import google.registry.util.NonFinalForTesting; +import java.time.Duration; import java.util.Collection; import java.util.Comparator; import java.util.Map; import java.util.Optional; -import java.util.concurrent.ExecutionException; +import java.util.Set; import javax.annotation.Nullable; import org.joda.time.DateTime; -import org.joda.time.Duration; /** * Class to map a foreign key to the active instance of {@link EppResource} whose unique id matches @@ -273,14 +272,14 @@ public abstract class ForeignKeyIndex extends BackupGroup @Override public Map>, Optional>> loadAll( - Iterable>> keys) { - if (!keys.iterator().hasNext()) { + Set>> keys) { + if (keys.isEmpty()) { return ImmutableMap.of(); } Class resourceClass = RESOURCE_CLASS_TO_FKI_CLASS.inverse().get(keys.iterator().next().getKind()); ImmutableSet foreignKeys = - Streams.stream(keys).map(v -> v.getSqlKey().toString()).collect(toImmutableSet()); + keys.stream().map(v -> v.getSqlKey().toString()).collect(toImmutableSet()); ImmutableSet>> typedKeys = ImmutableSet.copyOf(keys); ImmutableMap> existingFkis = loadIndexesFromStore(resourceClass, foreignKeys, false, true); @@ -312,8 +311,7 @@ public abstract class ForeignKeyIndex extends BackupGroup private static LoadingCache>, Optional>> createForeignKeyIndexesCache(Duration expiry) { - return CacheBuilder.newBuilder() - .expireAfterWrite(java.time.Duration.ofMillis(expiry.getMillis())) + return CacheUtils.newCacheBuilder(expiry) .maximumSize(getEppResourceMaxCachedEntries()) .build(CACHE_LOADER); } @@ -346,21 +344,17 @@ public abstract class ForeignKeyIndex extends BackupGroup foreignKeys.stream() .map(fk -> (VKey>) VKey.create(fkiClass, fk)) .collect(toImmutableList()); - try { - // This cast is safe because when we loaded ForeignKeyIndexes above we used type clazz, which - // is scoped to E. - @SuppressWarnings("unchecked") - ImmutableMap> fkisFromCache = - cacheForeignKeyIndexes.getAll(fkiVKeys).entrySet().stream() - .filter(entry -> entry.getValue().isPresent()) - .filter(entry -> now.isBefore(entry.getValue().get().getDeletionTime())) - .collect( - toImmutableMap( - entry -> entry.getKey().getSqlKey().toString(), - entry -> (ForeignKeyIndex) entry.getValue().get())); - return fkisFromCache; - } catch (ExecutionException e) { - throw new RuntimeException("Error loading cached ForeignKeyIndexes", e.getCause()); - } + // This cast is safe because when we loaded ForeignKeyIndexes above we used type clazz, which + // is scoped to E. + @SuppressWarnings("unchecked") + ImmutableMap> fkisFromCache = + cacheForeignKeyIndexes.getAll(fkiVKeys).entrySet().stream() + .filter(entry -> entry.getValue().isPresent()) + .filter(entry -> now.isBefore(entry.getValue().get().getDeletionTime())) + .collect( + toImmutableMap( + entry -> entry.getKey().getSqlKey().toString(), + entry -> (ForeignKeyIndex) entry.getValue().get())); + return fkisFromCache; } } diff --git a/core/src/main/java/google/registry/model/tld/Registry.java b/core/src/main/java/google/registry/model/tld/Registry.java index 4a947ca2a..34e116048 100644 --- a/core/src/main/java/google/registry/model/tld/Registry.java +++ b/core/src/main/java/google/registry/model/tld/Registry.java @@ -29,11 +29,10 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static org.joda.money.CurrencyUnit.USD; +import com.github.benmanes.caffeine.cache.CacheLoader; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; @@ -50,9 +49,11 @@ import com.googlecode.objectify.annotation.Mapify; import com.googlecode.objectify.annotation.OnSave; import com.googlecode.objectify.annotation.Parent; import google.registry.model.Buildable; +import google.registry.model.CacheUtils; import google.registry.model.CreateAutoTimestamp; import google.registry.model.ImmutableObject; import google.registry.model.UnsafeSerializable; +import google.registry.model.annotations.DeleteAfterMigration; import google.registry.model.annotations.InCrossTld; import google.registry.model.annotations.ReportedOn; import google.registry.model.common.EntityGroupRoot; @@ -69,7 +70,6 @@ import google.registry.util.Idn; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.concurrent.ExecutionException; import java.util.function.Predicate; import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -112,6 +112,7 @@ public class Registry extends ImmutableObject /** Sets the Datastore specific field, tldStr, when the entity is loaded from Cloud SQL */ @PostLoad + @DeleteAfterMigration void postLoad() { tldStr = tldStrId; } @@ -230,7 +231,7 @@ public class Registry extends ImmutableObject /** Returns the registry for a given TLD, throwing if none exists. */ public static Registry get(String tld) { - Registry registry = CACHE.getUnchecked(tld).orElse(null); + Registry registry = CACHE.get(tld).orElse(null); if (registry == null) { throw new RegistryNotFoundException(tld); } @@ -239,20 +240,16 @@ public class Registry extends ImmutableObject /** Returns the registry entities for the given TLD strings, throwing if any don't exist. */ public static ImmutableSet get(Set tlds) { - try { - ImmutableMap> registries = CACHE.getAll(tlds); - ImmutableSet missingRegistries = - registries.entrySet().stream() - .filter(e -> !e.getValue().isPresent()) - .map(Map.Entry::getKey) - .collect(toImmutableSet()); - if (missingRegistries.isEmpty()) { - return registries.values().stream().map(Optional::get).collect(toImmutableSet()); - } else { - throw new RegistryNotFoundException(missingRegistries); - } - } catch (ExecutionException e) { - throw new RuntimeException("Unexpected error retrieving TLDs " + tlds, e); + Map> registries = CACHE.getAll(tlds); + ImmutableSet missingRegistries = + registries.entrySet().stream() + .filter(e -> !e.getValue().isPresent()) + .map(Map.Entry::getKey) + .collect(toImmutableSet()); + if (missingRegistries.isEmpty()) { + return registries.values().stream().map(Optional::get).collect(toImmutableSet()); + } else { + throw new RegistryNotFoundException(missingRegistries); } } @@ -269,8 +266,7 @@ public class Registry extends ImmutableObject /** A cache that loads the {@link Registry} for a given tld. */ private static final LoadingCache> CACHE = - CacheBuilder.newBuilder() - .expireAfterWrite(getSingletonCacheRefreshDuration()) + CacheUtils.newCacheBuilder(getSingletonCacheRefreshDuration()) .build( new CacheLoader>() { @Override @@ -281,7 +277,7 @@ public class Registry extends ImmutableObject } @Override - public Map> loadAll(Iterable tlds) { + public Map> loadAll(Set tlds) { ImmutableMap> keysMap = toMap(ImmutableSet.copyOf(tlds), Registry::createVKey); Map, Registry> entities = diff --git a/core/src/main/java/google/registry/model/tld/label/BaseDomainLabelList.java b/core/src/main/java/google/registry/model/tld/label/BaseDomainLabelList.java index 9a5580570..692ab40e2 100644 --- a/core/src/main/java/google/registry/model/tld/label/BaseDomainLabelList.java +++ b/core/src/main/java/google/registry/model/tld/label/BaseDomainLabelList.java @@ -20,22 +20,17 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static google.registry.model.tld.Registries.getTlds; -import com.google.common.cache.CacheLoader.InvalidCacheLoadException; -import com.google.common.cache.LoadingCache; import com.google.common.collect.HashMultiset; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multiset; -import com.google.common.util.concurrent.UncheckedExecutionException; import google.registry.model.Buildable; import google.registry.model.ImmutableObject; import google.registry.model.tld.Registry; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ExecutionException; import javax.annotation.Nullable; import javax.persistence.Column; import javax.persistence.GeneratedValue; @@ -149,16 +144,6 @@ public abstract class BaseDomainLabelList, R extends Dom protected abstract boolean refersToList(Registry registry, String name); - protected static Optional getFromCache(String listName, LoadingCache cache) { - try { - return Optional.of(cache.get(listName)); - } catch (InvalidCacheLoadException e) { - return Optional.empty(); - } catch (ExecutionException e) { - throw new UncheckedExecutionException("Could not retrieve list named " + listName, e); - } - } - /** Base builder for derived classes of {@link BaseDomainLabelList}. */ public abstract static class Builder, B extends Builder> extends GenericBuilder { diff --git a/core/src/main/java/google/registry/model/tld/label/PremiumListDao.java b/core/src/main/java/google/registry/model/tld/label/PremiumListDao.java index 9f132f7f7..6118ff8e1 100644 --- a/core/src/main/java/google/registry/model/tld/label/PremiumListDao.java +++ b/core/src/main/java/google/registry/model/tld/label/PremiumListDao.java @@ -22,23 +22,20 @@ import static google.registry.config.RegistryConfig.getStaticPremiumListMaxCache import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.util.CollectionUtils.isNullOrEmpty; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.CacheLoader.InvalidCacheLoadException; -import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import google.registry.model.CacheUtils; import google.registry.model.tld.label.PremiumList.PremiumEntry; import google.registry.util.NonFinalForTesting; import java.math.BigDecimal; +import java.time.Duration; import java.util.List; import java.util.Optional; -import java.util.concurrent.ExecutionException; import org.joda.money.CurrencyUnit; import org.joda.money.Money; -import org.joda.time.Duration; /** * Data access object class for accessing {@link PremiumList} objects from Cloud SQL. @@ -71,15 +68,8 @@ public class PremiumListDao { @VisibleForTesting public static LoadingCache> createPremiumListCache( Duration cachePersistDuration) { - return CacheBuilder.newBuilder() - .expireAfterWrite(java.time.Duration.ofMillis(cachePersistDuration.getMillis())) - .build( - new CacheLoader>() { - @Override - public Optional load(final String name) { - return jpaTm().doTransactionless(() -> getLatestRevisionUncached(name)); - } - }); + return CacheUtils.newCacheBuilder(cachePersistDuration) + .build(PremiumListDao::getLatestRevisionUncached); } /** @@ -104,16 +94,9 @@ public class PremiumListDao { @VisibleForTesting static LoadingCache> createPremiumEntryCache( Duration cachePersistDuration) { - return CacheBuilder.newBuilder() - .expireAfterWrite(java.time.Duration.ofMillis(cachePersistDuration.getMillis())) + return CacheUtils.newCacheBuilder(cachePersistDuration) .maximumSize(getStaticPremiumListMaxCachedEntries()) - .build( - new CacheLoader>() { - @Override - public Optional load(RevisionIdAndLabel revisionIdAndLabel) { - return getPriceForLabelUncached(revisionIdAndLabel); - } - }); + .build(PremiumListDao::getPriceForLabelUncached); } /** @@ -123,7 +106,7 @@ public class PremiumListDao { * prices, use {@link #getPremiumPrice}. */ public static Optional getLatestRevision(String premiumListName) { - return premiumListCache.getUnchecked(premiumListName); + return premiumListCache.get(premiumListName); } /** @@ -142,15 +125,7 @@ public class PremiumListDao { } RevisionIdAndLabel revisionIdAndLabel = RevisionIdAndLabel.create(loadedList.getRevisionId(), label); - try { - return premiumEntryCache.get(revisionIdAndLabel).map(loadedList::convertAmountToMoney); - } catch (InvalidCacheLoadException | ExecutionException e) { - throw new RuntimeException( - String.format( - "Could not load premium entry %s for list %s", - revisionIdAndLabel, loadedList.getName()), - e); - } + return premiumEntryCache.get(revisionIdAndLabel).map(loadedList::convertAmountToMoney); } public static PremiumList save(String name, CurrencyUnit currencyUnit, List inputData) { diff --git a/core/src/main/java/google/registry/model/tld/label/ReservedList.java b/core/src/main/java/google/registry/model/tld/label/ReservedList.java index c6229f3c4..7d7d0e9ed 100644 --- a/core/src/main/java/google/registry/model/tld/label/ReservedList.java +++ b/core/src/main/java/google/registry/model/tld/label/ReservedList.java @@ -26,14 +26,13 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import static google.registry.util.CollectionUtils.nullToEmpty; import static org.joda.time.DateTimeZone.UTC; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.base.Splitter; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.UncheckedExecutionException; import google.registry.model.Buildable; +import google.registry.model.CacheUtils; import google.registry.model.replay.SqlOnlyEntity; import google.registry.model.tld.Registry; import google.registry.model.tld.label.DomainLabelMetrics.MetricsReservedListMatch; @@ -41,7 +40,6 @@ import java.io.Serializable; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.ExecutionException; import javax.annotation.Nullable; import javax.persistence.Column; import javax.persistence.Id; @@ -224,7 +222,7 @@ public final class ReservedList * ReservedList from the cache or database. */ public static Optional get(String listName) { - return getFromCache(listName, cache); + return cache.get(listName); } /** @@ -270,33 +268,18 @@ public final class ReservedList return entries; } + /** Loads and returns the reserved lists with the given names, skipping those that don't exist. */ private static ImmutableSet loadReservedLists( ImmutableSet reservedListNames) { - return reservedListNames.stream() - .map( - (listName) -> { - try { - return cache.get(listName); - } catch (ExecutionException e) { - throw new UncheckedExecutionException( - String.format("Could not load the reserved list '%s' from the cache", listName), - e); - } - }) + return cache.getAll(reservedListNames).values().stream() + .filter(Optional::isPresent) + .map(Optional::get) .collect(toImmutableSet()); } - private static LoadingCache cache = - CacheBuilder.newBuilder() - .expireAfterWrite( - java.time.Duration.ofMillis(getDomainLabelListCacheDuration().getMillis())) - .build( - new CacheLoader() { - @Override - public ReservedList load(String listName) { - return ReservedListDao.getLatestRevision(listName).orElse(null); - } - }); + private static final LoadingCache> cache = + CacheUtils.newCacheBuilder(getDomainLabelListCacheDuration()) + .build(ReservedListDao::getLatestRevision); /** * Gets the {@link ReservationType} of a label in a single ReservedList, or returns an absent @@ -337,6 +320,7 @@ public final class ReservedList * A builder for constructing {@link ReservedList} objects, since they are immutable. */ public static class Builder extends BaseDomainLabelList.Builder { + public Builder() {} private Builder(ReservedList instance) { diff --git a/core/src/main/java/google/registry/tmch/TmchCertificateAuthority.java b/core/src/main/java/google/registry/tmch/TmchCertificateAuthority.java index bf2ea88ee..e1c21b63b 100644 --- a/core/src/main/java/google/registry/tmch/TmchCertificateAuthority.java +++ b/core/src/main/java/google/registry/tmch/TmchCertificateAuthority.java @@ -17,7 +17,6 @@ package google.registry.tmch; import static google.registry.config.RegistryConfig.ConfigModule.TmchCaMode.PILOT; import static google.registry.config.RegistryConfig.ConfigModule.TmchCaMode.PRODUCTION; import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration; -import static google.registry.model.CacheUtils.newCacheBuilder; import static google.registry.util.ResourceUtils.readResourceUtf8; import com.github.benmanes.caffeine.cache.CacheLoader; @@ -25,6 +24,7 @@ import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import google.registry.config.RegistryConfig.Config; import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode; +import google.registry.model.CacheUtils; import google.registry.model.tmch.TmchCrl; import google.registry.util.Clock; import google.registry.util.X509Utils; @@ -76,7 +76,7 @@ public final class TmchCertificateAuthority { * persist the correct one for this given environment. */ private static final LoadingCache CRL_CACHE = - newCacheBuilder(getSingletonCacheRefreshDuration()) + CacheUtils.newCacheBuilder(getSingletonCacheRefreshDuration()) .build( new CacheLoader() { @Override diff --git a/core/src/main/java/google/registry/tools/UpdateTldCommand.java b/core/src/main/java/google/registry/tools/UpdateTldCommand.java index 045de6421..9fd5bf0fe 100644 --- a/core/src/main/java/google/registry/tools/UpdateTldCommand.java +++ b/core/src/main/java/google/registry/tools/UpdateTldCommand.java @@ -38,7 +38,7 @@ import org.joda.time.DateTimeZone; /** Command to update a TLD. */ @Parameters(separators = " =", commandDescription = "Update existing TLD(s)") -class UpdateTldCommand extends CreateOrUpdateTldCommand { +public class UpdateTldCommand extends CreateOrUpdateTldCommand { @Nullable @Parameter( names = "--add_reserved_lists", diff --git a/core/src/test/java/google/registry/model/EppResourceTest.java b/core/src/test/java/google/registry/model/EppResourceTest.java index 8ff99c739..34e5a242f 100644 --- a/core/src/test/java/google/registry/model/EppResourceTest.java +++ b/core/src/test/java/google/registry/model/EppResourceTest.java @@ -25,7 +25,7 @@ import com.google.common.collect.ImmutableList; import google.registry.model.contact.ContactResource; import google.registry.model.host.HostResource; import google.registry.testing.TestCacheExtension; -import org.joda.time.Duration; +import java.time.Duration; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -34,7 +34,7 @@ public class EppResourceTest extends EntityTestCase { @RegisterExtension public final TestCacheExtension testCacheExtension = - new TestCacheExtension.Builder().withEppResourceCache(Duration.standardDays(1)).build(); + new TestCacheExtension.Builder().withEppResourceCache(Duration.ofDays(1)).build(); @Test void test_loadCached_ignoresContactChange() { diff --git a/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java b/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java index bce4a2306..6f0f5865f 100644 --- a/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java +++ b/core/src/test/java/google/registry/model/index/ForeignKeyIndexTest.java @@ -38,7 +38,7 @@ import google.registry.testing.TestCacheExtension; import google.registry.testing.TestOfyAndSql; import google.registry.testing.TestOfyOnly; import google.registry.testing.TestSqlOnly; -import org.joda.time.Duration; +import java.time.Duration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -48,7 +48,7 @@ class ForeignKeyIndexTest extends EntityTestCase { @RegisterExtension public final TestCacheExtension testCacheExtension = - new TestCacheExtension.Builder().withForeignIndexKeyCache(Duration.standardDays(1)).build(); + new TestCacheExtension.Builder().withForeignIndexKeyCache(Duration.ofDays(1)).build(); @BeforeEach void setUp() { diff --git a/core/src/test/java/google/registry/model/tld/label/PremiumListDaoTest.java b/core/src/test/java/google/registry/model/tld/label/PremiumListDaoTest.java index 587a23f8c..ee15666a3 100644 --- a/core/src/test/java/google/registry/model/tld/label/PremiumListDaoTest.java +++ b/core/src/test/java/google/registry/model/tld/label/PremiumListDaoTest.java @@ -22,7 +22,6 @@ import static google.registry.testing.DatabaseHelper.newRegistry; import static google.registry.testing.DatabaseHelper.persistResource; import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.USD; -import static org.joda.time.Duration.standardDays; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.base.Stopwatch; @@ -34,6 +33,7 @@ import google.registry.testing.AppEngineExtension; import google.registry.testing.FakeClock; import google.registry.testing.TestCacheExtension; import java.math.BigDecimal; +import java.time.Duration; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.stream.IntStream; @@ -61,9 +61,7 @@ public class PremiumListDaoTest { // Set long persist times on caches so they can be tested (cache times default to 0 in tests). @RegisterExtension public final TestCacheExtension testCacheExtension = - new TestCacheExtension.Builder() - .withPremiumListsCache(standardDays(1)) - .build(); + new TestCacheExtension.Builder().withPremiumListsCache(Duration.ofDays(1)).build(); private static final ImmutableMap TEST_PRICES = ImmutableMap.of( diff --git a/core/src/test/java/google/registry/testing/TestCacheExtension.java b/core/src/test/java/google/registry/testing/TestCacheExtension.java index 5931ad6b2..1ad79756a 100644 --- a/core/src/test/java/google/registry/testing/TestCacheExtension.java +++ b/core/src/test/java/google/registry/testing/TestCacheExtension.java @@ -19,9 +19,9 @@ import com.google.common.collect.Maps; import google.registry.model.EppResource; import google.registry.model.index.ForeignKeyIndex; import google.registry.model.tld.label.PremiumListDao; +import java.time.Duration; import java.util.Map; import java.util.Optional; -import org.joda.time.Duration; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; diff --git a/core/src/test/java/google/registry/whois/WhoisActionTest.java b/core/src/test/java/google/registry/whois/WhoisActionTest.java index daf33dab4..8d7fc732c 100644 --- a/core/src/test/java/google/registry/whois/WhoisActionTest.java +++ b/core/src/test/java/google/registry/whois/WhoisActionTest.java @@ -66,8 +66,8 @@ import google.registry.whois.WhoisMetrics.WhoisMetric; import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.time.Duration; import org.joda.time.DateTime; -import org.joda.time.Duration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.extension.RegisterExtension; @@ -87,8 +87,8 @@ public class WhoisActionTest { @RegisterExtension public final TestCacheExtension testCacheExtension = new TestCacheExtension.Builder() - .withEppResourceCache(Duration.standardDays(1)) - .withForeignIndexKeyCache(Duration.standardDays(1)) + .withEppResourceCache(Duration.ofDays(1)) + .withForeignIndexKeyCache(Duration.ofDays(1)) .build(); private final FakeResponse response = new FakeResponse(); diff --git a/core/src/test/java/google/registry/whois/WhoisCommandFactoryTest.java b/core/src/test/java/google/registry/whois/WhoisCommandFactoryTest.java index 20661e50b..db39a640f 100644 --- a/core/src/test/java/google/registry/whois/WhoisCommandFactoryTest.java +++ b/core/src/test/java/google/registry/whois/WhoisCommandFactoryTest.java @@ -34,7 +34,7 @@ import google.registry.testing.FakeClock; import google.registry.testing.TestCacheExtension; import google.registry.testing.TestOfyAndSql; import java.net.InetAddress; -import org.joda.time.Duration; +import java.time.Duration; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; @@ -50,7 +50,7 @@ class WhoisCommandFactoryTest { @RegisterExtension final TestCacheExtension testCacheExtension = - new TestCacheExtension.Builder().withEppResourceCache(Duration.millis(1000000000)).build(); + new TestCacheExtension.Builder().withEppResourceCache(Duration.ofSeconds(1000000)).build(); WhoisCommandFactory noncachedFactory = WhoisCommandFactory.createNonCached(); WhoisCommandFactory cachedFactory = WhoisCommandFactory.createCached();