Rename Registries to Tlds (#2042)

* Rename Registries to Tlds

* Change Tlds to TLDs in comments
This commit is contained in:
sarahcaseybot 2023-05-24 17:08:09 -04:00 committed by GitHub
parent 6b5d7f5b21
commit 2df1fbc418
41 changed files with 81 additions and 82 deletions

View file

@ -21,7 +21,7 @@ import static google.registry.batch.BatchModule.PARAM_DRY_RUN;
import static google.registry.config.RegistryEnvironment.PRODUCTION;
import static google.registry.dns.DnsUtils.requestDomainDnsRefresh;
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_DELETE;
import static google.registry.model.tld.Registries.getTldsOfType;
import static google.registry.model.tld.Tlds.getTldsOfType;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.Action.Method.POST;
import static google.registry.request.RequestParameters.PARAM_TLDS;

View file

@ -27,9 +27,9 @@ import static google.registry.cron.CronModule.FOR_EACH_TEST_TLD_PARAM;
import static google.registry.cron.CronModule.JITTER_SECONDS_PARAM;
import static google.registry.cron.CronModule.QUEUE_PARAM;
import static google.registry.cron.CronModule.RUN_IN_EMPTY_PARAM;
import static google.registry.model.tld.Registries.getTldsOfType;
import static google.registry.model.tld.Tld.TldType.REAL;
import static google.registry.model.tld.Tld.TldType.TEST;
import static google.registry.model.tld.Tlds.getTldsOfType;
import com.google.cloud.tasks.v2.Task;
import com.google.common.collect.ArrayListMultimap;

View file

@ -20,8 +20,8 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import com.google.common.collect.ImmutableList;
import com.google.common.net.InternetDomainName;
import google.registry.model.common.DnsRefreshRequest;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tlds;
import java.util.Collection;
import java.util.Optional;
import org.joda.time.DateTime;
@ -38,7 +38,7 @@ public final class DnsUtils {
private static void requestDnsRefresh(String name, TargetType type, Duration delay) {
// Throws an IllegalArgumentException if the name is not under a managed TLD -- we only update
// DNS for names that are under our management.
String tld = Registries.findTldForNameOrThrow(InternetDomainName.from(name)).toString();
String tld = Tlds.findTldForNameOrThrow(InternetDomainName.from(name)).toString();
tm().transact(
() ->
tm().insert(
@ -114,7 +114,7 @@ public final class DnsUtils {
}
public static long getDnsAPlusAAAATtlForHost(String host, Duration dnsDefaultATtl) {
Optional<InternetDomainName> tldName = Registries.findTldForName(InternetDomainName.from(host));
Optional<InternetDomainName> tldName = Tlds.findTldForName(InternetDomainName.from(host));
Duration dnsAPlusAaaaTtl = dnsDefaultATtl;
if (tldName.isPresent()) {
Tld tld = Tld.get(tldName.get().toString());

View file

@ -40,8 +40,8 @@ import google.registry.dns.writer.DnsWriterZone;
import google.registry.model.domain.Domain;
import google.registry.model.domain.secdns.DomainDsData;
import google.registry.model.host.Host;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tlds;
import google.registry.util.Clock;
import google.registry.util.Concurrent;
import google.registry.util.Retrier;
@ -248,7 +248,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
public void publishHost(String hostName) {
// Get the superordinate domain name of the host.
InternetDomainName host = InternetDomainName.from(hostName);
Optional<InternetDomainName> tld = Registries.findTldForName(host);
Optional<InternetDomainName> tld = Tlds.findTldForName(host);
// Host not managed by our registry, no need to update DNS.
if (!tld.isPresent()) {

View file

@ -31,8 +31,8 @@ import google.registry.dns.writer.DnsWriterZone;
import google.registry.model.domain.Domain;
import google.registry.model.domain.secdns.DomainDsData;
import google.registry.model.host.Host;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tlds;
import google.registry.util.Clock;
import java.io.IOException;
import java.net.Inet4Address;
@ -154,7 +154,7 @@ public class DnsUpdateWriter extends BaseDnsWriter {
// Get the superordinate domain name of the host.
InternetDomainName host = InternetDomainName.from(hostName);
ImmutableList<String> hostParts = host.parts();
Optional<InternetDomainName> tld = Registries.findTldForName(host);
Optional<InternetDomainName> tld = Tlds.findTldForName(host);
// host not managed by our registry, no need to update DNS.
if (!tld.isPresent()) {

View file

@ -15,7 +15,7 @@
package google.registry.export;
import static com.google.common.base.Verify.verifyNotNull;
import static google.registry.model.tld.Registries.getTldsOfType;
import static google.registry.model.tld.Tlds.getTldsOfType;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.Action.Method.POST;
import static java.nio.charset.StandardCharsets.UTF_8;

View file

@ -26,12 +26,12 @@ import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.intersection;
import static com.google.common.collect.Sets.union;
import static google.registry.model.domain.Domain.MAX_REGISTRATION_YEARS;
import static google.registry.model.tld.Registries.findTldForName;
import static google.registry.model.tld.Registries.getTlds;
import static google.registry.model.tld.Tld.TldState.GENERAL_AVAILABILITY;
import static google.registry.model.tld.Tld.TldState.PREDELEGATION;
import static google.registry.model.tld.Tld.TldState.QUIET_PERIOD;
import static google.registry.model.tld.Tld.TldState.START_DATE_SUNRISE;
import static google.registry.model.tld.Tlds.findTldForName;
import static google.registry.model.tld.Tlds.getTlds;
import static google.registry.model.tld.label.ReservationType.ALLOWED_IN_SUNRISE;
import static google.registry.model.tld.label.ReservationType.FULLY_BLOCKED;
import static google.registry.model.tld.label.ReservationType.NAME_COLLISION;

View file

@ -16,7 +16,7 @@ package google.registry.flows.host;
import static google.registry.model.EppResourceUtils.isActive;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.tld.Registries.findTldForName;
import static google.registry.model.tld.Tlds.findTldForName;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static java.util.stream.Collectors.joining;

View file

@ -26,7 +26,7 @@ import static com.google.common.collect.Sets.immutableEnumSet;
import static com.google.common.io.BaseEncoding.base64;
import static google.registry.config.RegistryConfig.getDefaultRegistrarWhoisServer;
import static google.registry.model.CacheUtils.memoizeWithShortExpiration;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;

View file

@ -40,15 +40,15 @@ import java.util.stream.Stream;
import javax.persistence.EntityManager;
/** Utilities for finding and listing {@link Tld} entities. */
public final class Registries {
public final class Tlds {
private Registries() {}
private Tlds() {}
/** Supplier of a cached registries map. */
/** Supplier of a cached TLDs map. */
private static Supplier<ImmutableMap<String, TldType>> cache = createFreshCache();
/**
* Returns a newly-created Supplier of a registries to types map.
* Returns a newly-created Supplier of a TLDs to types map.
*
* <p>The supplier's get() method enters a transactionless context briefly to avoid enrolling the
* query inside an unrelated client-affecting transaction.
@ -84,7 +84,7 @@ public final class Registries {
return ImmutableSet.copyOf(filterValues(cache.get(), equalTo(type)).keySet());
}
/** Returns the Registry entities themselves of the given type loaded fresh from the database. */
/** Returns the TLD entities themselves of the given type loaded fresh from the database. */
public static ImmutableSet<Tld> getTldEntitiesOfType(TldType type) {
return Tld.get(filterValues(cache.get(), equalTo(type)).keySet());
}

View file

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
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 static google.registry.model.tld.Tlds.getTlds;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableList;

View file

@ -20,7 +20,7 @@ import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import google.registry.model.eppoutput.Result.Code;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tlds;
import google.registry.util.Clock;
import java.util.Optional;
import org.joda.time.DateTime;
@ -104,7 +104,7 @@ public abstract class EppMetric {
String tld = Iterables.getOnlyElement(tlds);
// Only record TLDs that actually exist, otherwise we can blow up cardinality by recording
// an arbitrarily large number of strings.
setTld(Optional.ofNullable(Registries.getTlds().contains(tld) ? tld : "_invalid"));
setTld(Optional.ofNullable(Tlds.getTlds().contains(tld) ? tld : "_invalid"));
break;
default:
setTld("_various");

View file

@ -23,9 +23,9 @@ import google.registry.config.RegistryConfig.Config;
import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.rde.RdeMode;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tld.TldType;
import google.registry.model.tld.Tlds;
import google.registry.util.Clock;
import java.util.Optional;
import javax.inject.Inject;
@ -83,7 +83,7 @@ public final class PendingDepositChecker {
ImmutableSetMultimap.Builder<String, PendingDeposit> builder =
new ImmutableSetMultimap.Builder<>();
DateTime now = clock.nowUtc();
for (String tldStr : Registries.getTldsOfType(TldType.REAL)) {
for (String tldStr : Tlds.getTldsOfType(TldType.REAL)) {
Tld tld = Tld.get(tldStr);
if (!tld.getEscrowEnabled()) {
continue;

View file

@ -16,7 +16,7 @@ package google.registry.reporting.icann;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.net.MediaType.CSV_UTF_8;
import static google.registry.model.tld.Registries.assertTldExists;
import static google.registry.model.tld.Tlds.assertTldExists;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.api.client.http.ByteArrayContent;

View file

@ -29,9 +29,9 @@ import google.registry.config.RegistryConfig.Config;
import google.registry.gcs.GcsUtils;
import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tld.TldType;
import google.registry.model.tld.Tlds;
import google.registry.persistence.VKey;
import google.registry.request.Action;
import google.registry.request.HttpException.ServiceUnavailableException;
@ -203,7 +203,7 @@ public final class IcannReportingUploadAction implements Runnable {
/** Returns a map of each cursor to the tld. */
private ImmutableMap<Cursor, String> loadCursors() {
ImmutableSet<Tld> registries = Registries.getTldEntitiesOfType(TldType.REAL);
ImmutableSet<Tld> registries = Tlds.getTldEntitiesOfType(TldType.REAL);
ImmutableMap<VKey<? extends Cursor>, Tld> activityKeyMap =
loadKeyMap(registries, CursorType.ICANN_UPLOAD_ACTIVITY);

View file

@ -17,8 +17,8 @@ package google.registry.request;
import static com.google.common.net.MediaType.JSON_UTF_8;
import static google.registry.dns.PublishDnsUpdatesAction.APP_ENGINE_RETRY_HEADER;
import static google.registry.dns.PublishDnsUpdatesAction.CLOUD_TASKS_RETRY_HEADER;
import static google.registry.model.tld.Registries.assertTldExists;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldExists;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static google.registry.request.RequestParameters.extractOptionalHeader;
import static google.registry.request.RequestParameters.extractRequiredParameter;
import static google.registry.request.RequestParameters.extractSetOfParameters;

View file

@ -14,7 +14,7 @@
package google.registry.tools;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static google.registry.persistence.transaction.QueryComposer.Comparator;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;

View file

@ -16,7 +16,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static google.registry.model.tld.Registries.findTldForNameOrThrow;
import static google.registry.model.tld.Tlds.findTldForNameOrThrow;
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
import static google.registry.util.StringGenerator.DEFAULT_PASSWORD_LENGTH;
import static org.joda.time.DateTimeZone.UTC;

View file

@ -28,10 +28,10 @@ import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
import google.registry.model.pricing.StaticPremiumListPricingEngine;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tld.TldState;
import google.registry.model.tld.Tld.TldType;
import google.registry.model.tld.Tlds;
import google.registry.model.tld.label.PremiumList;
import google.registry.model.tld.label.PremiumListDao;
import google.registry.tldconfig.idn.IdnTableEnum;
@ -459,8 +459,8 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
} finally {
// Manually reset the cache here so that subsequent commands (e.g. in SetupOteCommand) see
// the latest version of the data.
// TODO(b/24903801): change all those places to use uncached code paths to get Registries.
Registries.resetCache();
// TODO(b/24903801): change all those places to use uncached code paths to get TLDs.
Tlds.resetCache();
}
}

View file

@ -15,7 +15,7 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.tld.Registries.assertTldExists;
import static google.registry.model.tld.Tlds.assertTldExists;
import static google.registry.util.ListNamingUtils.convertFilePathToName;
import static java.nio.charset.StandardCharsets.UTF_8;

View file

@ -15,7 +15,7 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.tld.Registries.assertTldExists;
import static google.registry.model.tld.Tlds.assertTldExists;
import static google.registry.util.ListNamingUtils.convertFilePathToName;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;

View file

@ -16,7 +16,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.tld.Registries.getTlds;
import static google.registry.model.tld.Tlds.getTlds;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DateTimeUtils.START_OF_TIME;

View file

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Maps.filterValues;
import static com.google.common.io.Resources.getResource;
import static google.registry.model.tld.Registries.findTldForNameOrThrow;
import static google.registry.model.tld.Tlds.findTldForNameOrThrow;
import static google.registry.tools.CommandUtilities.addHeader;
import static google.registry.util.DomainNameUtils.canonicalizeHostname;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;

View file

@ -16,7 +16,7 @@ package google.registry.tools;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.io.BaseEncoding.base16;
import static google.registry.model.tld.Registries.assertTldExists;
import static google.registry.model.tld.Tlds.assertTldExists;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import static java.nio.charset.StandardCharsets.US_ASCII;

View file

@ -14,7 +14,7 @@
package google.registry.tools;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static google.registry.rde.RdeModule.PARAM_DIRECTORY;
import static google.registry.rde.RdeModule.PARAM_LENIENT;
import static google.registry.rde.RdeModule.PARAM_MANUAL;

View file

@ -14,7 +14,7 @@
package google.registry.tools;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardMinutes;

View file

@ -14,7 +14,7 @@
package google.registry.tools;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldsExist;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;

View file

@ -23,9 +23,9 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tld.TldType;
import google.registry.model.tld.Tlds;
import google.registry.persistence.VKey;
import java.util.Map;
import java.util.Optional;
@ -53,7 +53,7 @@ final class ListCursorsCommand implements Command {
public void run() {
Map<String, VKey<Cursor>> cursorKeys =
cursorType.isScoped()
? Registries.getTlds().stream()
? Tlds.getTlds().stream()
.map(Tld::get)
.filter(r -> r.getTldType() == filterTldType)
.filter(r -> !filterEscrowEnabled || r.getEscrowEnabled())

View file

@ -15,7 +15,7 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.tld.Registries.getTldsOfType;
import static google.registry.model.tld.Tlds.getTldsOfType;
import static google.registry.util.CollectionUtils.isNullOrEmpty;
import com.beust.jcommander.Parameter;

View file

@ -20,7 +20,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import google.registry.loadtest.LoadTestAction;
import google.registry.model.registrar.Registrar;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tlds;
/** Command to initiate a load-test. */
@Parameters(separators = " =", commandDescription = "Run a load test.")
@ -91,7 +91,7 @@ class LoadTestCommand extends ConfirmingCommand implements CommandWithConnection
}
// Check validity of TLD and Client Id.
if (!Registries.getTlds().contains(tld)) {
if (!Tlds.getTlds().contains(tld)) {
System.err.printf("No such TLD: %s\n", tld);
return false;
}

View file

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.intersection;
import static com.google.common.collect.Sets.union;
import static google.registry.model.tld.Registries.assertTldExists;
import static google.registry.model.tld.Tlds.assertTldExists;
import static google.registry.util.CollectionUtils.nullToEmpty;
import com.beust.jcommander.Parameter;

View file

@ -16,7 +16,7 @@ package google.registry.tools.server;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.POST;

View file

@ -15,7 +15,7 @@
package google.registry.tools.server;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.tld.Registries.getTlds;
import static google.registry.model.tld.Tlds.getTlds;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.POST;

View file

@ -16,7 +16,7 @@ package google.registry.tools.server;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.dns.DnsUtils.requestDomainDnsRefresh;
import static google.registry.model.tld.Registries.assertTldsExist;
import static google.registry.model.tld.Tlds.assertTldsExist;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.request.RequestParameters.PARAM_TLDS;

View file

@ -15,8 +15,8 @@
package google.registry.whois;
import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.model.tld.Registries.findTldForName;
import static google.registry.model.tld.Registries.getTlds;
import static google.registry.model.tld.Tlds.findTldForName;
import static google.registry.model.tld.Tlds.getTlds;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import com.google.common.annotations.VisibleForTesting;

View file

@ -25,7 +25,7 @@ import com.google.common.collect.Streams;
import com.google.common.net.InetAddresses;
import com.google.common.net.InternetDomainName;
import google.registry.model.host.Host;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tlds;
import java.net.InetAddress;
import org.joda.time.DateTime;
@ -72,8 +72,7 @@ final class NameserverLookupByIpCommand implements WhoisCommand {
Streams.stream(hostsFromDb)
.filter(
host ->
Registries.findTldForName(InternetDomainName.from(host.getHostName()))
.isPresent())
Tlds.findTldForName(InternetDomainName.from(host.getHostName())).isPresent())
.collect(toImmutableList());
if (hosts.isEmpty()) {
throw new WhoisException(now, SC_NOT_FOUND, "No nameservers found.");

View file

@ -16,7 +16,7 @@ package google.registry.whois;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static google.registry.model.tld.Registries.findTldForName;
import static google.registry.model.tld.Tlds.findTldForName;
import static google.registry.util.DomainNameUtils.canonicalizeHostname;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;

View file

@ -42,9 +42,9 @@ import google.registry.config.RegistryConfig;
import google.registry.model.EntityTestCase;
import google.registry.model.registrar.Registrar.State;
import google.registry.model.registrar.Registrar.Type;
import google.registry.model.tld.Registries;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tld.TldType;
import google.registry.model.tld.Tlds;
import google.registry.util.CidrAddressBlock;
import google.registry.util.SerializeUtils;
import java.math.BigDecimal;
@ -603,14 +603,14 @@ class RegistrarTest extends EntityTestCase {
// Cache duration in tests is 0. To make sure the data isn't in the cache we have to set it
// to a higher value and reset the cache.
RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds = 600;
Registries.resetCache();
Tlds.resetCache();
// Make sure the TLD we want to create doesn't exist yet.
// This is also important because getTlds fills out the cache when used.
assertThat(Registries.getTlds()).doesNotContain("newtld");
assertThat(Tlds.getTlds()).doesNotContain("newtld");
// We can't use createTld here because it fails when the cache is used.
persistResource(newTld("newtld", "NEWTLD"));
// Make sure we set up the cache correctly, so the newly created TLD isn't in the cache
assertThat(Registries.getTlds()).doesNotContain("newtld");
assertThat(Tlds.getTlds()).doesNotContain("newtld");
// Test that the uncached version works
assertThat(
@ -633,11 +633,11 @@ class RegistrarTest extends EntityTestCase {
// Make sure the cache hasn't expired during the test and "newtld" is still not in the cached
// TLDs
assertThat(Registries.getTlds()).doesNotContain("newtld");
assertThat(Tlds.getTlds()).doesNotContain("newtld");
} finally {
RegistryConfig.CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds =
origSingletonCacheRefreshSeconds;
Registries.resetCache();
Tlds.resetCache();
}
}

View file

@ -28,8 +28,8 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link Registries}. */
class RegistriesTest {
/** Unit tests for {@link Tlds}. */
class TldsTest {
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@ -42,51 +42,51 @@ class RegistriesTest {
@Test
void testGetTlds() {
initTestTlds();
assertThat(Registries.getTlds()).containsExactly("foo", "a.b.c");
assertThat(Tlds.getTlds()).containsExactly("foo", "a.b.c");
}
@Test
void test_getTldEntities() {
initTestTlds();
persistResource(newTld("testtld", "TESTTLD").asBuilder().setTldType(TldType.TEST).build());
assertThat(Registries.getTldEntitiesOfType(TldType.REAL))
assertThat(Tlds.getTldEntitiesOfType(TldType.REAL))
.containsExactly(Tld.get("foo"), Tld.get("a.b.c"));
assertThat(Registries.getTldEntitiesOfType(TldType.TEST)).containsExactly(Tld.get("testtld"));
assertThat(Tlds.getTldEntitiesOfType(TldType.TEST)).containsExactly(Tld.get("testtld"));
}
@Test
void testGetTlds_withNoRegistriesPersisted_returnsEmptySet() {
assertThat(Registries.getTlds()).isEmpty();
assertThat(Tlds.getTlds()).isEmpty();
}
@Test
void testAssertTldExists_doesExist() {
initTestTlds();
Registries.assertTldExists("foo");
Registries.assertTldExists("a.b.c");
Tlds.assertTldExists("foo");
Tlds.assertTldExists("a.b.c");
}
@Test
void testAssertTldExists_doesntExist() {
initTestTlds();
assertThrows(IllegalArgumentException.class, () -> Registries.assertTldExists("baz"));
assertThrows(IllegalArgumentException.class, () -> Tlds.assertTldExists("baz"));
}
@Test
void testFindTldForName() {
initTestTlds();
assertThat(Registries.findTldForName(InternetDomainName.from("example.foo")).get().toString())
assertThat(Tlds.findTldForName(InternetDomainName.from("example.foo")).get().toString())
.isEqualTo("foo");
assertThat(Registries.findTldForName(InternetDomainName.from("x.y.a.b.c")).get().toString())
assertThat(Tlds.findTldForName(InternetDomainName.from("x.y.a.b.c")).get().toString())
.isEqualTo("a.b.c");
// We don't have an "example" tld.
assertThat(Registries.findTldForName(InternetDomainName.from("foo.example"))).isEmpty();
assertThat(Tlds.findTldForName(InternetDomainName.from("foo.example"))).isEmpty();
// A tld is not a match for itself.
assertThat(Registries.findTldForName(InternetDomainName.from("foo"))).isEmpty();
assertThat(Tlds.findTldForName(InternetDomainName.from("foo"))).isEmpty();
// The name must match the entire tld.
assertThat(Registries.findTldForName(InternetDomainName.from("x.y.a.b"))).isEmpty();
assertThat(Registries.findTldForName(InternetDomainName.from("x.y.b.c"))).isEmpty();
assertThat(Tlds.findTldForName(InternetDomainName.from("x.y.a.b"))).isEmpty();
assertThat(Tlds.findTldForName(InternetDomainName.from("x.y.b.c"))).isEmpty();
// Substring tld matches aren't considered.
assertThat(Registries.findTldForName(InternetDomainName.from("example.barfoo"))).isEmpty();
assertThat(Tlds.findTldForName(InternetDomainName.from("example.barfoo"))).isEmpty();
}
}

View file

@ -19,7 +19,7 @@ import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
import static google.registry.model.registrar.Registrar.State.ACTIVE;
import static google.registry.model.registrar.Registrar.Type.PDT;
import static google.registry.model.tld.Registries.getTlds;
import static google.registry.model.tld.Tlds.getTlds;
import static google.registry.testing.DatabaseHelper.createTlds;
import static google.registry.testing.DatabaseHelper.loadRegistrar;
import static google.registry.testing.DatabaseHelper.persistActiveDomain;

View file

@ -58,8 +58,8 @@ public final class DomainNameUtils {
* <p>This function is compatible with multi-part tlds, e.g. {@code co.uk}. This function will
* also work on domains for which the registry is not authoritative. If you are certain that the
* input will be under a TLD this registry controls, then it is preferable to use {@link
* google.registry.model.tld.Registries#findTldForName(InternetDomainName)
* Registries#findTldForName}, which will work on hostnames in addition to domains.
* google.registry.model.tld.Tlds#findTldForName(InternetDomainName) Registries#findTldForName},
* which will work on hostnames in addition to domains.
*
* @param domainName must be a punycode SLD (not a host or unicode)
* @throws IllegalArgumentException if there is no TLD