Make all but one field on RegistryConfig static

The next step will be to get rid of RegistryConfig descendants and RegistryConfigLoader entirely.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143812815
This commit is contained in:
mcilwain 2017-01-06 14:06:01 -08:00 committed by Ben McIlwain
parent 7fba7c1e4f
commit c5c74961bb
23 changed files with 224 additions and 324 deletions

View file

@ -15,6 +15,7 @@
package google.registry.config; package google.registry.config;
import static google.registry.config.ConfigUtils.makeUrl; import static google.registry.config.ConfigUtils.makeUrl;
import static org.joda.time.Duration.standardDays;
import com.google.appengine.api.utils.SystemProperty; import com.google.appengine.api.utils.SystemProperty;
import com.google.common.base.Optional; import com.google.common.base.Optional;
@ -73,11 +74,6 @@ public final class ConfigModule {
return REGISTRY_ENVIRONMENT; return REGISTRY_ENVIRONMENT;
} }
@Provides
public static RegistryConfig provideConfig(RegistryEnvironment environment) {
return environment.config();
}
@Provides @Provides
@Config("projectId") @Config("projectId")
public static String provideProjectId() { public static String provideProjectId() {
@ -356,8 +352,8 @@ public final class ConfigModule {
*/ */
@Provides @Provides
@Config("eppResourceIndexBucketCount") @Config("eppResourceIndexBucketCount")
public static int provideEppResourceIndexBucketCount(RegistryConfig config) { public static int provideEppResourceIndexBucketCount() {
return config.getEppResourceIndexBucketCount(); return RegistryConfig.getEppResourceIndexBucketCount();
} }
/** /**
@ -897,14 +893,15 @@ public final class ConfigModule {
} }
/** /**
* The time between a contact transfer request and its expiration date. * The global automatic transfer length for contacts. After this amount of time has
* elapsed, the transfer is automatically approved.
* *
* @see google.registry.flows.contact.ContactTransferRequestFlow * @see google.registry.flows.contact.ContactTransferRequestFlow
*/ */
@Provides @Provides
@Config("contactAutomaticTransferLength") @Config("contactAutomaticTransferLength")
public static Duration provideContactAutomaticTransferLength(RegistryConfig config) { public static Duration provideContactAutomaticTransferLength() {
return config.getContactAutomaticTransferLength(); return standardDays(5);
} }
/** /**
@ -960,6 +957,33 @@ public final class ConfigModule {
return "google.registry.flows.custom.CustomLogicFactory"; return "google.registry.flows.custom.CustomLogicFactory";
} }
private static final String RESERVED_TERMS_EXPORT_DISCLAIMER = ""
+ "# This list contains reserve terms for the TLD. Other terms may be reserved\n"
+ "# but not included in this list, including terms EXAMPLE REGISTRY chooses not\n"
+ "# to publish, and terms that ICANN commonly mandates to be reserved. This\n"
+ "# list is subject to change and the most up-to-date source is always to\n"
+ "# check availability directly with the Registry server.\n";
/**
* Returns the header text at the top of the reserved terms exported list.
*
* @see google.registry.export.ExportUtils#exportReservedTerms
*/
@Provides
@Config("reservedTermsExportDisclaimer")
public static String provideReservedTermsExportDisclaimer() {
return RESERVED_TERMS_EXPORT_DISCLAIMER;
}
/**
* Returns the clientId of the registrar used by the {@code CheckApiServlet}.
*/
@Provides
@Config("checkApiServletRegistrarClientId")
public static String provideCheckApiServletRegistrarClientId() {
return "TheRegistrar";
}
/** /**
* Returns the help path for the RDAP terms of service. * Returns the help path for the RDAP terms of service.
* *
@ -1050,8 +1074,12 @@ public final class ConfigModule {
public static final String CONTACT_AND_HOST_ROID_SUFFIX = "ROID"; public static final String CONTACT_AND_HOST_ROID_SUFFIX = "ROID";
public static final String RESERVED_TERMS_TEST_EXPORT_DISCLAIMER = "This is a disclaimer.\n";
public static final String GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS = "noreply@testing.example"; public static final String GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS = "noreply@testing.example";
public static final String GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME = "Testing Nomulus"; public static final String GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME = "Testing Nomulus";
public static final Duration CONTACT_AUTOMATIC_TRANSFER_LENGTH = standardDays(5);
} }
} }

View file

@ -15,14 +15,9 @@
package google.registry.config; package google.registry.config;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.config.ConfigUtils.makeUrl;
import static org.joda.time.Duration.standardDays;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.net.HostAndPort;
import java.net.URL;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import org.joda.time.Duration;
/** /**
* Default production configuration for global constants that can't be injected. * Default production configuration for global constants that can't be injected.
@ -34,15 +29,9 @@ import org.joda.time.Duration;
@Immutable @Immutable
public final class ProductionRegistryConfigExample extends RegistryConfig { public final class ProductionRegistryConfigExample extends RegistryConfig {
@SuppressWarnings("unused")
private final RegistryEnvironment environment; private final RegistryEnvironment environment;
private static final String RESERVED_TERMS_EXPORT_DISCLAIMER = ""
+ "# This list contains reserve terms for the TLD. Other terms may be reserved\n"
+ "# but not included in this list, including terms EXAMPLE REGISTRY chooses not\n"
+ "# to publish, and terms that ICANN commonly mandates to be reserved. This\n"
+ "# list is subject to change and the most up-to-date source is always to\n"
+ "# check availability directly with the Registry server.\n";
public ProductionRegistryConfigExample(RegistryEnvironment environment) { public ProductionRegistryConfigExample(RegistryEnvironment environment) {
this.environment = checkNotNull(environment); this.environment = checkNotNull(environment);
} }
@ -51,50 +40,4 @@ public final class ProductionRegistryConfigExample extends RegistryConfig {
public Optional<String> getECatcherAddress() { public Optional<String> getECatcherAddress() {
throw new UnsupportedOperationException(); // n/a throw new UnsupportedOperationException(); // n/a
} }
@Override
public HostAndPort getServer() {
switch (environment) {
case LOCAL:
return HostAndPort.fromParts("localhost", 8080);
default:
return HostAndPort.fromParts(
String.format("tools-dot-%s.appspot.com", getProjectId()), 443);
}
}
@Override
public String getReservedTermsExportDisclaimer() {
return RESERVED_TERMS_EXPORT_DISCLAIMER;
}
@Override
public String getRegistrarDefaultWhoisServer() {
return "whois.nic.registry.example";
}
@Override
public URL getRegistrarDefaultReferralUrl() {
return makeUrl("https://www.registry.example");
}
@Override
public int getEppResourceIndexBucketCount() {
return 997;
}
@Override
public Duration getBaseOfyRetryDuration() {
return Duration.millis(100);
}
@Override
public Duration getContactAutomaticTransferLength() {
return standardDays(5);
}
@Override
public String getCheckApiServletRegistrarClientId() {
return "TheRegistrar";
}
} }

View file

@ -14,6 +14,8 @@
package google.registry.config; package google.registry.config;
import static google.registry.config.ConfigUtils.makeUrl;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.net.HostAndPort; import com.google.common.net.HostAndPort;
@ -109,7 +111,17 @@ public abstract class RegistryConfig {
* *
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API. * <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
*/ */
public abstract HostAndPort getServer(); public static HostAndPort getServer() {
switch (RegistryEnvironment.get()) {
case LOCAL:
return HostAndPort.fromParts("localhost", 8080);
case UNITTEST:
throw new UnsupportedOperationException("Unit tests can't spin up a full server");
default:
return HostAndPort.fromParts(
String.format("tools-dot-%s.appspot.com", getProjectId()), 443);
}
}
/** Returns the amount of time a singleton should be cached, before expiring. */ /** Returns the amount of time a singleton should be cached, before expiring. */
public static Duration getSingletonCacheRefreshDuration() { public static Duration getSingletonCacheRefreshDuration() {
@ -148,46 +160,56 @@ public abstract class RegistryConfig {
} }
} }
/**
* Returns the header text at the top of the reserved terms exported list.
*
* @see google.registry.export.ExportUtils#exportReservedTerms
*/
public abstract String getReservedTermsExportDisclaimer();
/** /**
* Returns default WHOIS server to use when {@code Registrar#getWhoisServer()} is {@code null}. * Returns default WHOIS server to use when {@code Registrar#getWhoisServer()} is {@code null}.
* *
* @see "google.registry.whois.DomainWhoisResponse" * @see "google.registry.whois.DomainWhoisResponse"
* @see "google.registry.whois.RegistrarWhoisResponse" * @see "google.registry.whois.RegistrarWhoisResponse"
*/ */
public abstract String getRegistrarDefaultWhoisServer(); public static String getRegistrarDefaultWhoisServer() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return "whois.nic.fakewhois.example";
default:
return "whois.nic.registry.example";
}
}
/** /**
* Returns the default referral URL that is used unless registrars have specified otherwise. * Returns the default referral URL that is used unless registrars have specified otherwise.
*/ */
public abstract URL getRegistrarDefaultReferralUrl(); public static URL getRegistrarDefaultReferralUrl() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return makeUrl("http://www.referral.example/path");
default:
return makeUrl("https://www.registry.example");
}
}
/** /**
* Returns the number of EppResourceIndex buckets to be used. * Returns the number of {@code EppResourceIndex} buckets to be used.
*/ */
public abstract int getEppResourceIndexBucketCount(); public static int getEppResourceIndexBucketCount() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return 3;
default:
return 997;
}
}
/** /**
* Returns the base duration that gets doubled on each retry within {@code Ofy}. * Returns the base retry duration that gets doubled after each failure within {@code Ofy}.
*/ */
public abstract Duration getBaseOfyRetryDuration(); public static Duration getBaseOfyRetryDuration() {
switch (RegistryEnvironment.get()) {
/** case UNITTEST:
* Returns the global automatic transfer length for contacts. After this amount of time has return Duration.ZERO;
* elapsed, the transfer is automatically approved. default:
*/ return Duration.millis(100);
public abstract Duration getContactAutomaticTransferLength(); }
}
/**
* Returns the clientId of the registrar used by the {@code CheckApiServlet}.
*/
public abstract String getCheckApiServletRegistrarClientId();
// XXX: Please consider using ConfigModule instead of adding new methods to this file. // XXX: Please consider using ConfigModule instead of adding new methods to this file.
} }

View file

@ -14,13 +14,7 @@
package google.registry.config; package google.registry.config;
import static google.registry.config.ConfigUtils.makeUrl;
import static org.joda.time.Duration.standardDays;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.net.HostAndPort;
import java.net.URL;
import org.joda.time.Duration;
/** /**
* An implementation of RegistryConfig for unit testing that contains suitable testing data. * An implementation of RegistryConfig for unit testing that contains suitable testing data.
@ -33,44 +27,4 @@ public class TestRegistryConfig extends RegistryConfig {
public Optional<String> getECatcherAddress() { public Optional<String> getECatcherAddress() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public HostAndPort getServer() {
throw new UnsupportedOperationException();
}
@Override
public String getReservedTermsExportDisclaimer() {
return "This is a disclaimer.\n";
}
@Override
public String getRegistrarDefaultWhoisServer() {
return "whois.nic.fakewhois.example";
}
@Override
public URL getRegistrarDefaultReferralUrl() {
return makeUrl("http://www.referral.example/path");
}
@Override
public int getEppResourceIndexBucketCount() {
return 2;
}
@Override
public Duration getBaseOfyRetryDuration() {
return Duration.ZERO;
}
@Override
public Duration getContactAutomaticTransferLength() {
return standardDays(5);
}
@Override
public String getCheckApiServletRegistrarClientId() {
return "TheRegistrar";
}
} }

View file

@ -16,7 +16,6 @@ package google.registry.export;
import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static google.registry.export.ExportUtils.exportReservedTerms;
import static google.registry.request.Action.Method.POST; import static google.registry.request.Action.Method.POST;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
@ -41,6 +40,7 @@ public class ExportReservedTermsAction implements Runnable {
static final String RESERVED_TERMS_FILENAME = "reserved_terms.txt"; static final String RESERVED_TERMS_FILENAME = "reserved_terms.txt";
@Inject DriveConnection driveConnection; @Inject DriveConnection driveConnection;
@Inject ExportUtils exportUtils;
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld; @Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
@Inject Response response; @Inject Response response;
@Inject ExportReservedTermsAction() {} @Inject ExportReservedTermsAction() {}
@ -70,7 +70,7 @@ public class ExportReservedTermsAction implements Runnable {
RESERVED_TERMS_FILENAME, RESERVED_TERMS_FILENAME,
EXPORT_MIME_TYPE, EXPORT_MIME_TYPE,
registry.getDriveFolderId(), registry.getDriveFolderId(),
exportReservedTerms(registry).getBytes(UTF_8)); exportUtils.exportReservedTerms(registry).getBytes(UTF_8));
logger.infofmt("Exporting reserved terms succeeded for TLD %s, response was: %s", logger.infofmt("Exporting reserved terms succeeded for TLD %s, response was: %s",
tld, resultMsg); tld, resultMsg);
} }

View file

@ -18,22 +18,28 @@ import static google.registry.model.registry.label.ReservationType.UNRESERVED;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.RegistryEnvironment; import google.registry.config.ConfigModule.Config;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList; import google.registry.model.registry.label.ReservedList;
import google.registry.model.registry.label.ReservedList.ReservedListEntry; import google.registry.model.registry.label.ReservedList.ReservedListEntry;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import javax.inject.Inject;
/** Container class for exported-related static utility methods. */ /** Container class for exported-related utility methods. */
public class ExportUtils { public final class ExportUtils {
private ExportUtils() {} private final String reservedTermsExportDisclaimer;
@Inject
public ExportUtils(
@Config("reservedTermsExportDisclaimer") String reservedTermsExportDisclaimer) {
this.reservedTermsExportDisclaimer = reservedTermsExportDisclaimer;
}
/** Returns the file contents of the auto-export reserved terms document for the given TLD. */ /** Returns the file contents of the auto-export reserved terms document for the given TLD. */
public static String exportReservedTerms(Registry registry) { public String exportReservedTerms(Registry registry) {
StringBuilder termsBuilder = StringBuilder termsBuilder = new StringBuilder(reservedTermsExportDisclaimer);
new StringBuilder(RegistryEnvironment.get().config().getReservedTermsExportDisclaimer());
Set<String> reservedTerms = new TreeSet<>(); Set<String> reservedTerms = new TreeSet<>();
for (Key<ReservedList> key : registry.getReservedLists()) { for (Key<ReservedList> key : registry.getReservedLists()) {
ReservedList reservedList = ReservedList.load(key).get(); ReservedList reservedList = ReservedList.load(key).get();

View file

@ -35,7 +35,7 @@ import com.google.template.soy.SoyFileSet;
import com.google.template.soy.tofu.SoyTofu; import com.google.template.soy.tofu.SoyTofu;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import google.registry.config.RegistryConfig; import google.registry.config.ConfigModule.Config;
import google.registry.flows.soy.DomainCheckFeeEppSoyInfo; import google.registry.flows.soy.DomainCheckFeeEppSoyInfo;
import google.registry.model.domain.fee.FeeCheckResponseExtension; import google.registry.model.domain.fee.FeeCheckResponseExtension;
import google.registry.model.eppoutput.CheckData.DomainCheck; import google.registry.model.eppoutput.CheckData.DomainCheck;
@ -69,7 +69,7 @@ public class CheckApiAction implements Runnable {
@Inject @Parameter("domain") String domain; @Inject @Parameter("domain") String domain;
@Inject Response response; @Inject Response response;
@Inject EppController eppController; @Inject EppController eppController;
@Inject RegistryConfig config; @Inject @Config("checkApiServletRegistrarClientId") String checkApiServletRegistrarClientId;
@Inject CheckApiAction() {} @Inject CheckApiAction() {}
@Override @Override
@ -96,9 +96,8 @@ public class CheckApiAction implements Runnable {
.setData(ImmutableMap.of("domainName", domainString)) .setData(ImmutableMap.of("domainName", domainString))
.render() .render()
.getBytes(UTF_8); .getBytes(UTF_8);
SessionMetadata sessionMetadata = new StatelessRequestSessionMetadata( SessionMetadata sessionMetadata =
config.getCheckApiServletRegistrarClientId(), new StatelessRequestSessionMetadata(checkApiServletRegistrarClientId, FEE_EXTENSION_URIS);
FEE_EXTENSION_URIS);
EppResponse response = eppController EppResponse response = eppController
.handleEppCommand( .handleEppCommand(
sessionMetadata, sessionMetadata,

View file

@ -14,12 +14,13 @@
package google.registry.model.index; package google.registry.model.index;
import static google.registry.config.RegistryConfig.getEppResourceIndexBucketCount;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing; import com.google.common.hash.Hashing;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Id;
import google.registry.config.RegistryEnvironment;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.annotations.VirtualEntity; import google.registry.model.annotations.VirtualEntity;
@ -38,7 +39,7 @@ public class EppResourceIndexBucket extends ImmutableObject {
* change the number of buckets and utilize a random distribution once we do. * change the number of buckets and utilize a random distribution once we do.
*/ */
private static long getBucketIdFromEppResource(Key<? extends EppResource> resourceKey) { private static long getBucketIdFromEppResource(Key<? extends EppResource> resourceKey) {
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount(); int numBuckets = getEppResourceIndexBucketCount();
// IDs can't be 0, so add 1 to the hash. // IDs can't be 0, so add 1 to the hash.
return Hashing.consistentHash(resourceKey.getName().hashCode(), numBuckets) + 1; return Hashing.consistentHash(resourceKey.getName().hashCode(), numBuckets) + 1;
} }
@ -56,8 +57,7 @@ public class EppResourceIndexBucket extends ImmutableObject {
/** Returns the keys to all buckets. */ /** Returns the keys to all buckets. */
public static Iterable<Key<EppResourceIndexBucket>> getAllBuckets() { public static Iterable<Key<EppResourceIndexBucket>> getAllBuckets() {
ImmutableList.Builder<Key<EppResourceIndexBucket>> builder = new ImmutableList.Builder<>(); ImmutableList.Builder<Key<EppResourceIndexBucket>> builder = new ImmutableList.Builder<>();
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount(); for (int bucketId = 1; bucketId <= getEppResourceIndexBucketCount(); bucketId++) {
for (int bucketId = 1; bucketId <= numBuckets; bucketId++) {
builder.add(getBucketKey(bucketId)); builder.add(getBucketKey(bucketId));
} }
return builder.build(); return builder.build();

View file

@ -24,6 +24,7 @@ import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Sets.immutableEnumSet; import static com.google.common.collect.Sets.immutableEnumSet;
import static com.google.common.io.BaseEncoding.base64; import static com.google.common.io.BaseEncoding.base64;
import static google.registry.config.RegistryConfig.getRegistrarDefaultWhoisServer;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION; import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
@ -446,10 +447,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
} }
public String getWhoisServer() { public String getWhoisServer() {
if (whoisServer == null) { return firstNonNull(whoisServer, getRegistrarDefaultWhoisServer());
return ENVIRONMENT.config().getRegistrarDefaultWhoisServer();
}
return whoisServer;
} }
public boolean getBlockPremiumNames() { public boolean getBlockPremiumNames() {

View file

@ -29,7 +29,6 @@ import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse; import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService; import com.google.appengine.api.urlfetch.URLFetchService;
import google.registry.config.ConfigModule.Config; import google.registry.config.ConfigModule.Config;
import google.registry.config.RegistryConfig;
import google.registry.keyring.api.KeyModule.Key; import google.registry.keyring.api.KeyModule.Key;
import google.registry.request.HttpException.InternalServerErrorException; import google.registry.request.HttpException.InternalServerErrorException;
import google.registry.util.FormattingLogger; import google.registry.util.FormattingLogger;
@ -62,7 +61,6 @@ public class RdeReporter {
* ICANN Registry Interfaces - Interface details</a>*/ * ICANN Registry Interfaces - Interface details</a>*/
private static final String REPORT_MIME = "text/xml"; private static final String REPORT_MIME = "text/xml";
@Inject RegistryConfig config;
@Inject Retrier retrier; @Inject Retrier retrier;
@Inject URLFetchService urlFetchService; @Inject URLFetchService urlFetchService;
@Inject @Config("rdeReportUrlPrefix") String reportUrlPrefix; @Inject @Config("rdeReportUrlPrefix") String reportUrlPrefix;

View file

@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import google.registry.config.ConfigModule.LocalTestConfig;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList; import google.registry.model.registry.label.ReservedList;
import google.registry.request.Response; import google.registry.request.Response;
@ -64,6 +65,7 @@ public class ExportReservedTermsActionTest {
ExportReservedTermsAction action = new ExportReservedTermsAction(); ExportReservedTermsAction action = new ExportReservedTermsAction();
action.response = response; action.response = response;
action.driveConnection = driveConnection; action.driveConnection = driveConnection;
action.exportUtils = new ExportUtils(LocalTestConfig.RESERVED_TERMS_TEST_EXPORT_DISCLAIMER);
action.tld = tld; action.tld = tld;
action.run(); action.run();
} }

View file

@ -15,6 +15,7 @@
package google.registry.export; package google.registry.export;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.ConfigModule.LocalTestConfig.RESERVED_TERMS_TEST_EXPORT_DISCLAIMER;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
@ -56,7 +57,9 @@ public class ExportUtilsTest {
createTld("tld"); createTld("tld");
persistResource(Registry.get("tld").asBuilder().setReservedLists(rl1, rl2, rl3).build()); persistResource(Registry.get("tld").asBuilder().setReservedLists(rl1, rl2, rl3).build());
// Should not contain jimmy, tine, or oval. // Should not contain jimmy, tine, or oval.
assertThat(ExportUtils.exportReservedTerms(Registry.get("tld"))) assertThat(
new ExportUtils(RESERVED_TERMS_TEST_EXPORT_DISCLAIMER)
.exportReservedTerms(Registry.get("tld")))
.isEqualTo("This is a disclaimer.\ncat\nlol\nsnow\n"); .isEqualTo("This is a disclaimer.\ncat\nlol\nsnow\n");
} }
} }

View file

@ -16,6 +16,8 @@ package google.registry.export.sheet;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.RegistryConfig.getRegistrarDefaultReferralUrl;
import static google.registry.config.RegistryConfig.getRegistrarDefaultWhoisServer;
import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET; import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -263,10 +265,8 @@ public class SyncRegistrarsSheetTest {
assertThat(row).containsEntry("ipAddressWhitelist", ""); assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "http://www.example.org/aaa_registrar"); assertThat(row).containsEntry("url", "http://www.example.org/aaa_registrar");
assertThat(row).containsEntry("icannReferralEmail", ""); assertThat(row).containsEntry("icannReferralEmail", "");
assertThat(row).containsEntry("whoisServer", assertThat(row).containsEntry("whoisServer", getRegistrarDefaultWhoisServer());
ENVIRONMENT.config().getRegistrarDefaultWhoisServer()); assertThat(row).containsEntry("referralUrl", getRegistrarDefaultReferralUrl().toString());
assertThat(row).containsEntry("referralUrl",
ENVIRONMENT.config().getRegistrarDefaultReferralUrl().toString());
row = rows.get(1); row = rows.get(1);
assertThat(row).containsEntry("clientIdentifier", "anotherregistrar"); assertThat(row).containsEntry("clientIdentifier", "anotherregistrar");
@ -298,8 +298,7 @@ public class SyncRegistrarsSheetTest {
assertThat(row).containsEntry("blockPremiumNames", "false"); assertThat(row).containsEntry("blockPremiumNames", "false");
assertThat(row).containsEntry("ipAddressWhitelist", ""); assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "http://www.example.org/another_registrar"); assertThat(row).containsEntry("url", "http://www.example.org/another_registrar");
assertThat(row).containsEntry("referralUrl", assertThat(row).containsEntry("referralUrl", getRegistrarDefaultReferralUrl().toString());
ENVIRONMENT.config().getRegistrarDefaultReferralUrl().toString());
assertThat(row).containsEntry("icannReferralEmail", "jim@example.net"); assertThat(row).containsEntry("icannReferralEmail", "jim@example.net");
Cursor cursor = ofy().load().key(Cursor.createGlobalKey(SYNC_REGISTRAR_SHEET)).now(); Cursor cursor = ofy().load().key(Cursor.createGlobalKey(SYNC_REGISTRAR_SHEET)).now();
@ -342,8 +341,7 @@ public class SyncRegistrarsSheetTest {
assertThat(row).containsEntry("phoneNumber", ""); assertThat(row).containsEntry("phoneNumber", "");
assertThat(row).containsEntry("faxNumber", ""); assertThat(row).containsEntry("faxNumber", "");
assertThat(row).containsEntry("allowedTlds", ""); assertThat(row).containsEntry("allowedTlds", "");
assertThat(row).containsEntry("whoisServer", assertThat(row).containsEntry("whoisServer", getRegistrarDefaultWhoisServer());
ENVIRONMENT.config().getRegistrarDefaultWhoisServer());
assertThat(row).containsEntry("blockPremiumNames", "false"); assertThat(row).containsEntry("blockPremiumNames", "false");
assertThat(row).containsEntry("ipAddressWhitelist", ""); assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", ""); assertThat(row).containsEntry("url", "");

View file

@ -21,7 +21,6 @@ import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.config.RegistryEnvironment;
import google.registry.flows.EppTestComponent.FakesAndMocksModule; import google.registry.flows.EppTestComponent.FakesAndMocksModule;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
@ -60,7 +59,7 @@ public class CheckApiActionTest {
private Map<String, Object> getCheckResponse(String domain) { private Map<String, Object> getCheckResponse(String domain) {
action.domain = domain; action.domain = domain;
action.response = new FakeResponse(); action.response = new FakeResponse();
action.config = RegistryEnvironment.UNITTEST.config(); action.checkApiServletRegistrarClientId = "TheRegistrar";
action.eppController = DaggerEppTestComponent.builder() action.eppController = DaggerEppTestComponent.builder()
.fakesAndMocksModule(new FakesAndMocksModule()) .fakesAndMocksModule(new FakesAndMocksModule())
.build() .build()

View file

@ -22,7 +22,7 @@ import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import google.registry.config.RegistryEnvironment; import google.registry.config.ConfigModule.LocalTestConfig;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.exceptions.AlreadyPendingTransferException; import google.registry.flows.exceptions.AlreadyPendingTransferException;
@ -57,8 +57,7 @@ public class ContactTransferRequestFlowTest
private void doSuccessfulTest(String commandFilename, String expectedXmlFilename) private void doSuccessfulTest(String commandFilename, String expectedXmlFilename)
throws Exception { throws Exception {
setEppInput(commandFilename); setEppInput(commandFilename);
DateTime afterTransfer = DateTime afterTransfer = clock.nowUtc().plus(LocalTestConfig.CONTACT_AUTOMATIC_TRANSFER_LENGTH);
clock.nowUtc().plus(RegistryEnvironment.get().config().getContactAutomaticTransferLength());
// Setup done; run the test. // Setup done; run the test.
assertTransactionalFlow(true); assertTransactionalFlow(true);

View file

@ -17,11 +17,11 @@ package google.registry.mapreduce.inputs;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_; import static com.google.common.truth.Truth.assert_;
import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput; import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.index.EppResourceIndexBucket.getBucketKey; import static google.registry.model.index.EppResourceIndexBucket.getBucketKey;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistEppResourceInFirstBucket;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResource; import static google.registry.testing.DatastoreHelper.persistSimpleResource;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
@ -30,7 +30,6 @@ import static org.joda.money.CurrencyUnit.USD;
import com.google.appengine.tools.mapreduce.InputReader; import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.TestRegistryConfig;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
@ -41,7 +40,6 @@ import google.registry.model.index.EppResourceIndex;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule; import google.registry.testing.ExceptionRule;
import google.registry.testing.RegistryConfigRule;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
@ -69,9 +67,6 @@ public class ChildEntityInputTest {
@Rule @Rule
public final ExceptionRule thrown = new ExceptionRule(); public final ExceptionRule thrown = new ExceptionRule();
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule();
DomainResource domainA; DomainResource domainA;
DomainResource domainB; DomainResource domainB;
HistoryEntry domainHistoryEntryA; HistoryEntry domainHistoryEntryA;
@ -82,19 +77,10 @@ public class ChildEntityInputTest {
BillingEvent.Recurring recurringA; BillingEvent.Recurring recurringA;
BillingEvent.Recurring recurringB; BillingEvent.Recurring recurringB;
private void overrideBucketCount(final int count) {
configRule.override(new TestRegistryConfig() {
@Override
public int getEppResourceIndexBucketCount() {
return count;
}
});
}
private void setupResources() { private void setupResources() {
createTld("tld"); createTld("tld");
overrideBucketCount(1); ContactResource contact = persistEppResourceInFirstBucket(newContactResource("contact1234"));
domainA = persistActiveDomain("a.tld"); domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld", contact));
domainHistoryEntryA = persistResource( domainHistoryEntryA = persistResource(
new HistoryEntry.Builder() new HistoryEntry.Builder()
.setParent(domainA) .setParent(domainA)
@ -102,7 +88,7 @@ public class ChildEntityInputTest {
.build()); .build());
contactHistoryEntry = persistResource( contactHistoryEntry = persistResource(
new HistoryEntry.Builder() new HistoryEntry.Builder()
.setParent(loadByForeignKey(ContactResource.class, "contact1234", now)) .setParent(contact)
.setModificationTime(now) .setModificationTime(now)
.build()); .build());
oneTimeA = persistResource( oneTimeA = persistResource(
@ -129,7 +115,7 @@ public class ChildEntityInputTest {
} }
private void setupSecondDomainResources() { private void setupSecondDomainResources() {
domainB = persistActiveDomain("b.tld"); domainB = persistEppResourceInFirstBucket(newDomainResource("b.tld"));
domainHistoryEntryB = persistResource( domainHistoryEntryB = persistResource(
new HistoryEntry.Builder() new HistoryEntry.Builder()
.setParent(domainB) .setParent(domainB)
@ -211,110 +197,81 @@ public class ChildEntityInputTest {
@Test @Test
public void testSuccess_childEntityReader_multipleChildTypes() throws Exception { public void testSuccess_childEntityReader_multipleChildTypes() throws Exception {
setupResources(); setupResources();
Set<ImmutableObject> seen = new HashSet<>();
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput( InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class), ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of( ImmutableSet.<Class<? extends ImmutableObject>>of(
HistoryEntry.class, BillingEvent.OneTime.class, BillingEvent.Recurring.class)) HistoryEntry.class, BillingEvent.OneTime.class, BillingEvent.Recurring.class))
.createReaders().get(0); .createReaders().get(0);
assertThat(getAllFromReader(reader)).containsExactly(
domainHistoryEntryA, contactHistoryEntry, oneTimeA, recurringA);
}
private static Set<ImmutableObject> getAllFromReader(InputReader<ImmutableObject> reader)
throws Exception {
reader.beginShard(); reader.beginShard();
reader.beginSlice(); reader.beginSlice();
ImmutableSet.Builder<ImmutableObject> seen = new ImmutableSet.Builder<>();
try {
while (true) {
seen.add(reader.next()); seen.add(reader.next());
seen.add(reader.next()); }
seen.add(reader.next()); } catch (NoSuchElementException e) {
seen.add(reader.next()); // Swallow; this is expected.
assertThat(seen).containsExactly( }
domainHistoryEntryA, contactHistoryEntry, oneTimeA, recurringA); return seen.build();
thrown.expect(NoSuchElementException.class);
reader.next();
} }
@Test @Test
public void testSuccess_childEntityReader_filterParentTypes() throws Exception { public void testSuccess_childEntityReader_filterParentTypes() throws Exception {
setupResources(); setupResources();
Set<ImmutableObject> seen = new HashSet<>();
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput( InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(ContactResource.class), ImmutableSet.<Class<? extends EppResource>>of(ContactResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of( ImmutableSet.<Class<? extends ImmutableObject>>of(
HistoryEntry.class, BillingEvent.OneTime.class, BillingEvent.Recurring.class)) HistoryEntry.class, BillingEvent.OneTime.class, BillingEvent.Recurring.class))
.createReaders().get(0); .createReaders().get(0);
assertThat(getAllFromReader(reader)).containsExactly(contactHistoryEntry);
reader.beginShard();
reader.beginSlice();
seen.add(reader.next());
assertThat(seen).containsExactly(contactHistoryEntry);
thrown.expect(NoSuchElementException.class);
reader.next();
} }
@Test @Test
public void testSuccess_childEntityReader_polymorphicChildFiltering() throws Exception { public void testSuccess_childEntityReader_polymorphicChildFiltering() throws Exception {
setupResources(); setupResources();
Set<ImmutableObject> seen = new HashSet<>();
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput( InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class), ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of(BillingEvent.OneTime.class)) ImmutableSet.<Class<? extends ImmutableObject>>of(BillingEvent.OneTime.class))
.createReaders().get(0); .createReaders().get(0);
assertThat(getAllFromReader(reader)).containsExactly(oneTimeA);
reader.beginShard();
reader.beginSlice();
seen.add(reader.next());
assertThat(seen).containsExactly(oneTimeA);
thrown.expect(NoSuchElementException.class);
reader.next();
} }
@Test @Test
public void testSuccess_childEntityReader_polymorphicChildClass() throws Exception { public void testSuccess_childEntityReader_polymorphicChildClass() throws Exception {
setupResources(); setupResources();
Set<ImmutableObject> seen = new HashSet<>();
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput( InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class), ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of(BillingEvent.class)) ImmutableSet.<Class<? extends ImmutableObject>>of(BillingEvent.class))
.createReaders().get(0); .createReaders().get(0);
assertThat(getAllFromReader(reader)).containsExactly(oneTimeA, recurringA);
reader.beginShard();
reader.beginSlice();
seen.add(reader.next());
seen.add(reader.next());
assertThat(seen).containsExactly(oneTimeA, recurringA);
thrown.expect(NoSuchElementException.class);
reader.next();
} }
@Test @Test
public void testSuccess_childEntityReader_noneReturned() throws Exception { public void testSuccess_childEntityReader_noneReturned() throws Exception {
createTld("tld"); createTld("tld");
overrideBucketCount(1);
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput( InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(ContactResource.class), ImmutableSet.<Class<? extends EppResource>>of(ContactResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of( ImmutableSet.<Class<? extends ImmutableObject>>of(
BillingEvent.OneTime.class)).createReaders().get(0); BillingEvent.OneTime.class)).createReaders().get(0);
assertThat(getAllFromReader(reader)).isEmpty();
reader.beginShard();
reader.beginSlice();
thrown.expect(NoSuchElementException.class);
reader.next();
} }
@Test @Test
public void testSuccess_childEntityReader_readerCountMatchesBucketCount() throws Exception { public void testSuccess_childEntityReader_readerCountMatchesBucketCount() throws Exception {
overrideBucketCount(123);
assertThat(EppResourceInputs.createChildEntityInput( assertThat(EppResourceInputs.createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(DomainResource.class), ImmutableSet.<Class<? extends EppResource>>of(DomainResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of( ImmutableSet.<Class<? extends ImmutableObject>>of(
BillingEvent.OneTime.class)).createReaders()).hasSize(123); BillingEvent.OneTime.class)).createReaders()).hasSize(3);
} }
@Test @Test
public void testSuccess_childEntityReader_oneReaderPerBucket() throws Exception { public void testSuccess_childEntityReader_oneReaderPerBucket() throws Exception {
overrideBucketCount(3);
createTld("tld"); createTld("tld");
Set<ImmutableObject> historyEntries = new HashSet<>(); Set<ImmutableObject> historyEntries = new HashSet<>();
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {

View file

@ -20,18 +20,17 @@ import static google.registry.mapreduce.inputs.EppResourceInputs.createEntityInp
import static google.registry.mapreduce.inputs.EppResourceInputs.createKeyInput; import static google.registry.mapreduce.inputs.EppResourceInputs.createKeyInput;
import static google.registry.model.index.EppResourceIndexBucket.getBucketKey; import static google.registry.model.index.EppResourceIndexBucket.getBucketKey;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistEppResourceInFirstBucket;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResource; import static google.registry.testing.DatastoreHelper.persistSimpleResource;
import com.google.appengine.tools.mapreduce.InputReader; import com.google.appengine.tools.mapreduce.InputReader;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.TestRegistryConfig;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainApplication;
@ -41,7 +40,6 @@ import google.registry.model.host.HostResource;
import google.registry.model.index.EppResourceIndex; import google.registry.model.index.EppResourceIndex;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule; import google.registry.testing.ExceptionRule;
import google.registry.testing.RegistryConfigRule;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
@ -66,18 +64,6 @@ public class EppResourceInputsTest {
@Rule @Rule
public final ExceptionRule thrown = new ExceptionRule(); public final ExceptionRule thrown = new ExceptionRule();
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule();
private void overrideBucketCount(final int count) {
configRule.override(new TestRegistryConfig() {
@Override
public int getEppResourceIndexBucketCount() {
return count;
}
});
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T> T serializeAndDeserialize(T obj) throws Exception { private <T> T serializeAndDeserialize(T obj) throws Exception {
try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
@ -128,14 +114,12 @@ public class EppResourceInputsTest {
@Test @Test
public void testReaderCountMatchesBucketCount() throws Exception { public void testReaderCountMatchesBucketCount() throws Exception {
overrideBucketCount(123); assertThat(createKeyInput(DomainBase.class).createReaders()).hasSize(3);
assertThat(createKeyInput(DomainBase.class).createReaders()).hasSize(123); assertThat(createEntityInput(DomainBase.class).createReaders()).hasSize(3);
assertThat(createEntityInput(DomainBase.class).createReaders()).hasSize(123);
} }
@Test @Test
public void testKeyInput_oneReaderPerBucket() throws Exception { public void testKeyInput_oneReaderPerBucket() throws Exception {
overrideBucketCount(3);
createTld("tld"); createTld("tld");
Set<Key<DomainResource>> domains = new HashSet<>(); Set<Key<DomainResource>> domains = new HashSet<>();
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
@ -159,7 +143,6 @@ public class EppResourceInputsTest {
@Test @Test
public void testEntityInput_oneReaderPerBucket() throws Exception { public void testEntityInput_oneReaderPerBucket() throws Exception {
overrideBucketCount(3);
createTld("tld"); createTld("tld");
Set<DomainResource> domains = new HashSet<>(); Set<DomainResource> domains = new HashSet<>();
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
@ -186,9 +169,8 @@ public class EppResourceInputsTest {
@Test @Test
public void testSuccess_keyReader_survivesAcrossSerialization() throws Exception { public void testSuccess_keyReader_survivesAcrossSerialization() throws Exception {
createTld("tld"); createTld("tld");
overrideBucketCount(1); DomainResource domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
DomainResource domainA = persistActiveDomain("a.tld"); DomainResource domainB = persistEppResourceInFirstBucket(newDomainResource("b.tld"));
DomainResource domainB = persistActiveDomain("b.tld");
// Should be ignored. We'll know if it isn't because the progress counts will be off. // Should be ignored. We'll know if it isn't because the progress counts will be off.
persistActiveContact("contact"); persistActiveContact("contact");
Set<Key<DomainBase>> seen = new HashSet<>(); Set<Key<DomainBase>> seen = new HashSet<>();
@ -212,9 +194,8 @@ public class EppResourceInputsTest {
@Test @Test
public void testSuccess_entityReader_survivesAcrossSerialization() throws Exception { public void testSuccess_entityReader_survivesAcrossSerialization() throws Exception {
createTld("tld"); createTld("tld");
overrideBucketCount(1); DomainResource domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
DomainResource domainA = persistActiveDomain("a.tld"); DomainResource domainB = persistEppResourceInFirstBucket(newDomainResource("b.tld"));
DomainResource domainB = persistActiveDomain("b.tld");
// Should be ignored. We'll know if it isn't because the progress counts will be off. // Should be ignored. We'll know if it isn't because the progress counts will be off.
persistActiveContact("contact"); persistActiveContact("contact");
Set<DomainResource> seen = new HashSet<>(); Set<DomainResource> seen = new HashSet<>();
@ -241,12 +222,10 @@ public class EppResourceInputsTest {
@Test @Test
public void testSuccess_entityReader_allowsPolymorphicMatches() throws Exception { public void testSuccess_entityReader_allowsPolymorphicMatches() throws Exception {
createTld("tld"); createTld("tld");
overrideBucketCount(1); DomainResource domain = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
DomainResource domain = persistActiveDomain("a.tld"); DomainApplication application = persistEppResourceInFirstBucket(newDomainApplication("b.tld"));
DomainApplication application = persistActiveDomainApplication("b.tld");
Set<DomainBase> seen = new HashSet<>(); Set<DomainBase> seen = new HashSet<>();
InputReader<DomainBase> reader = InputReader<DomainBase> reader = createEntityInput(DomainBase.class).createReaders().get(0);
createEntityInput(DomainBase.class).createReaders().get(0);
reader.beginShard(); reader.beginShard();
reader.beginSlice(); reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0); assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
@ -262,9 +241,8 @@ public class EppResourceInputsTest {
@Test @Test
public void testSuccess_entityReader_skipsPolymorphicMismatches() throws Exception { public void testSuccess_entityReader_skipsPolymorphicMismatches() throws Exception {
createTld("tld"); createTld("tld");
overrideBucketCount(1); persistEppResourceInFirstBucket(newDomainApplication("b.tld"));
persistActiveDomainApplication("b.tld"); DomainResource domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
DomainResource domainA = persistActiveDomain("a.tld");
InputReader<DomainResource> reader = InputReader<DomainResource> reader =
createEntityInput(DomainResource.class).createReaders().get(0); createEntityInput(DomainResource.class).createReaders().get(0);
reader.beginShard(); reader.beginShard();
@ -281,10 +259,9 @@ public class EppResourceInputsTest {
@Test @Test
public void testSuccess_entityReader_filtersOnMultipleTypes() throws Exception { public void testSuccess_entityReader_filtersOnMultipleTypes() throws Exception {
createTld("tld"); createTld("tld");
overrideBucketCount(1); DomainResource domain = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
DomainResource domain = persistActiveDomain("a.tld"); HostResource host = persistEppResourceInFirstBucket(newHostResource("ns1.example.com"));
HostResource host = persistActiveHost("ns1.example.com"); persistEppResourceInFirstBucket(newContactResource("contact"));
persistActiveContact("contact");
Set<EppResource> seen = new HashSet<>(); Set<EppResource> seen = new HashSet<>();
InputReader<EppResource> reader = InputReader<EppResource> reader =
EppResourceInputs.<EppResource>createEntityInput( EppResourceInputs.<EppResource>createEntityInput(
@ -304,12 +281,12 @@ public class EppResourceInputsTest {
@Test @Test
public void testSuccess_entityReader_noFilteringWhenUsingEppResource() throws Exception { public void testSuccess_entityReader_noFilteringWhenUsingEppResource() throws Exception {
createTld("tld"); createTld("tld");
overrideBucketCount(1); ContactResource contact = persistEppResourceInFirstBucket(newContactResource("contact"));
ContactResource contact = persistActiveContact("contact");
// Specify the contact since persistActiveDomain{Application} creates a hidden one. // Specify the contact since persistActiveDomain{Application} creates a hidden one.
DomainResource domain = persistResource(newDomainResource("a.tld", contact)); DomainResource domain = persistEppResourceInFirstBucket(newDomainResource("a.tld", contact));
DomainApplication application = persistResource(newDomainApplication("b.tld", contact)); DomainApplication application =
HostResource host = persistActiveHost("ns1.example.com"); persistEppResourceInFirstBucket(newDomainApplication("b.tld", contact));
HostResource host = persistEppResourceInFirstBucket(newHostResource("ns1.example.com"));
Set<EppResource> seen = new HashSet<>(); Set<EppResource> seen = new HashSet<>();
InputReader<EppResource> reader = createEntityInput(EppResource.class).createReaders().get(0); InputReader<EppResource> reader = createEntityInput(EppResource.class).createReaders().get(0);
reader.beginShard(); reader.beginShard();

View file

@ -15,6 +15,7 @@
package google.registry.model.index; package google.registry.model.index;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.RegistryConfig.getEppResourceIndexBucketCount;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
@ -23,7 +24,6 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.RegistryEnvironment;
import google.registry.model.EntityTestCase; import google.registry.model.EntityTestCase;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import org.junit.Before; import org.junit.Before;
@ -62,10 +62,9 @@ public class EppResourceIndexTest extends EntityTestCase {
/** /**
* Returns all EppResourceIndex objects across all buckets. * Returns all EppResourceIndex objects across all buckets.
*/ */
private ImmutableList<EppResourceIndex> getEppResourceIndexObjects() { private static ImmutableList<EppResourceIndex> getEppResourceIndexObjects() {
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount();
ImmutableList.Builder<EppResourceIndex> indexEntities = new ImmutableList.Builder<>(); ImmutableList.Builder<EppResourceIndex> indexEntities = new ImmutableList.Builder<>();
for (int i = 0; i < numBuckets; i++) { for (int i = 0; i < getEppResourceIndexBucketCount(); i++) {
indexEntities.addAll(ofy().load() indexEntities.addAll(ofy().load()
.type(EppResourceIndex.class) .type(EppResourceIndex.class)
.ancestor(Key.create(EppResourceIndexBucket.class, i + 1))); .ancestor(Key.create(EppResourceIndexBucket.class, i + 1)));

View file

@ -42,8 +42,6 @@ import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import google.registry.config.RegistryConfig;
import google.registry.config.RegistryEnvironment;
import google.registry.gcs.GcsUtils; import google.registry.gcs.GcsUtils;
import google.registry.model.common.Cursor; import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType; import google.registry.model.common.Cursor.CursorType;
@ -97,13 +95,11 @@ public class RdeReportActionTest {
private final HTTPResponse httpResponse = mock(HTTPResponse.class); private final HTTPResponse httpResponse = mock(HTTPResponse.class);
private final GcsService gcsService = GcsServiceFactory.createGcsService(); private final GcsService gcsService = GcsServiceFactory.createGcsService();
private final RegistryConfig config = RegistryEnvironment.get().config();
private final GcsFilename reportFile = private final GcsFilename reportFile =
new GcsFilename("tub", "test_2006-06-06_full_S1_R0-report.xml.ghostryde"); new GcsFilename("tub", "test_2006-06-06_full_S1_R0-report.xml.ghostryde");
private RdeReportAction createAction() { private RdeReportAction createAction() {
RdeReporter reporter = new RdeReporter(); RdeReporter reporter = new RdeReporter();
reporter.config = config;
reporter.reportUrlPrefix = "https://rde-report.example"; reporter.reportUrlPrefix = "https://rde-report.example";
reporter.urlFetchService = urlFetchService; reporter.urlFetchService = urlFetchService;
reporter.password = "foo"; reporter.password = "foo";

View file

@ -21,6 +21,7 @@ import static com.google.common.collect.Iterables.toArray;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.config.ConfigModule.LocalTestConfig.CONTACT_AND_HOST_ROID_SUFFIX; import static google.registry.config.ConfigModule.LocalTestConfig.CONTACT_AND_HOST_ROID_SUFFIX;
import static google.registry.config.ConfigModule.LocalTestConfig.CONTACT_AUTOMATIC_TRANSFER_LENGTH;
import static google.registry.flows.ResourceFlowUtils.createTransferResponse; import static google.registry.flows.ResourceFlowUtils.createTransferResponse;
import static google.registry.model.EppResourceUtils.createDomainRepoId; import static google.registry.model.EppResourceUtils.createDomainRepoId;
import static google.registry.model.EppResourceUtils.createRepoId; import static google.registry.model.EppResourceUtils.createRepoId;
@ -52,7 +53,6 @@ import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
import com.googlecode.objectify.Work; import com.googlecode.objectify.Work;
import com.googlecode.objectify.cmd.Saver; import com.googlecode.objectify.cmd.Saver;
import google.registry.config.RegistryEnvironment;
import google.registry.dns.writer.VoidDnsWriter; import google.registry.dns.writer.VoidDnsWriter;
import google.registry.model.Buildable; import google.registry.model.Buildable;
import google.registry.model.EppResource; import google.registry.model.EppResource;
@ -75,6 +75,7 @@ import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.index.DomainApplicationIndex; import google.registry.model.index.DomainApplicationIndex;
import google.registry.model.index.EppResourceIndex; import google.registry.model.index.EppResourceIndex;
import google.registry.model.index.EppResourceIndexBucket;
import google.registry.model.index.ForeignKeyIndex; import google.registry.model.index.ForeignKeyIndex;
import google.registry.model.ofy.ObjectifyService; import google.registry.model.ofy.ObjectifyService;
import google.registry.model.poll.PollMessage; import google.registry.model.poll.PollMessage;
@ -479,8 +480,7 @@ public class DatastoreHelper {
.setCurrentSponsorClientId("TheRegistrar") .setCurrentSponsorClientId("TheRegistrar")
.addStatusValue(StatusValue.PENDING_TRANSFER) .addStatusValue(StatusValue.PENDING_TRANSFER)
.setTransferData(createTransferDataBuilder(requestTime, expirationTime) .setTransferData(createTransferDataBuilder(requestTime, expirationTime)
.setPendingTransferExpirationTime(now.plus( .setPendingTransferExpirationTime(now.plus(CONTACT_AUTOMATIC_TRANSFER_LENGTH))
RegistryEnvironment.get().config().getContactAutomaticTransferLength()))
.setServerApproveEntities( .setServerApproveEntities(
ImmutableSet.<Key<? extends TransferServerApproveEntity>>of( ImmutableSet.<Key<? extends TransferServerApproveEntity>>of(
// Pretend it's 3 days since the request // Pretend it's 3 days since the request
@ -770,22 +770,27 @@ public class DatastoreHelper {
return persistResource(resource, true); return persistResource(resource, true);
} }
private static <R> void saveResource(final R resource, final boolean wantBackup) { private static <R> void saveResource(R resource, boolean wantBackup) {
Saver saver = wantBackup ? ofy().save() : ofy().saveWithoutBackup(); Saver saver = wantBackup ? ofy().save() : ofy().saveWithoutBackup();
saver.entity(resource); saver.entity(resource);
if (resource instanceof EppResource) { if (resource instanceof EppResource) {
EppResource eppResource = (EppResource) resource; EppResource eppResource = (EppResource) resource;
persistEppResourceExtras(
eppResource, EppResourceIndex.create(Key.create(eppResource)), saver);
}
}
private static <R extends EppResource> void persistEppResourceExtras(
R resource, EppResourceIndex index, Saver saver) {
assertWithMessage("Cannot persist an EppResource with a missing repoId in tests") assertWithMessage("Cannot persist an EppResource with a missing repoId in tests")
.that(eppResource.getRepoId()).isNotEmpty(); .that(resource.getRepoId())
Key<EppResource> eppResourceKey = Key.create(eppResource); .isNotEmpty();
saver.entity(EppResourceIndex.create(eppResourceKey)); saver.entity(index);
if (resource instanceof ForeignKeyedEppResource) { if (resource instanceof ForeignKeyedEppResource) {
saver.entity(ForeignKeyIndex.create(eppResource, eppResource.getDeletionTime())); saver.entity(ForeignKeyIndex.create(resource, resource.getDeletionTime()));
} }
if (resource instanceof DomainApplication) { if (resource instanceof DomainApplication) {
saver.entity( saver.entity(DomainApplicationIndex.createUpdatedInstance((DomainApplication) resource));
DomainApplicationIndex.createUpdatedInstance((DomainApplication) resource));
}
} }
} }
@ -804,6 +809,21 @@ public class DatastoreHelper {
return ofy().load().entity(resource).now(); return ofy().load().entity(resource).now();
} }
/** Persists an EPP resource with the {@link EppResourceIndex} always going into bucket one. */
public static <R extends EppResource> R persistEppResourceInFirstBucket(final R resource) {
final EppResourceIndex eppResourceIndex =
EppResourceIndex.create(Key.create(EppResourceIndexBucket.class, 1), Key.create(resource));
ofy().transact(new VoidWork() {
@Override
public void vrun() {
Saver saver = ofy().save();
saver.entity(resource);
persistEppResourceExtras(resource, eppResourceIndex, saver);
}});
ofy().clearSessionCache();
return ofy().load().entity(resource).now();
}
public static <R> void persistResources(final Iterable<R> resources) { public static <R> void persistResources(final Iterable<R> resources) {
persistResources(resources, false); persistResources(resources, false);
} }

View file

@ -15,6 +15,7 @@
package google.registry.testing.mapreduce; package google.registry.testing.mapreduce;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.RegistryConfig.getEppResourceIndexBucketCount;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -33,7 +34,6 @@ import com.google.appengine.tools.pipeline.impl.servlets.TaskHandler;
import com.google.apphosting.api.ApiProxy; import com.google.apphosting.api.ApiProxy;
import com.google.common.base.CharMatcher; import com.google.common.base.CharMatcher;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import google.registry.config.RegistryEnvironment;
import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.MapreduceRunner;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
@ -88,8 +88,8 @@ public abstract class MapreduceTestCase<T> extends ShardableTestCase {
} }
protected MapreduceRunner makeDefaultRunner() { protected MapreduceRunner makeDefaultRunner() {
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount(); return new MapreduceRunner(
return new MapreduceRunner(Optional.<Integer>of(numBuckets), Optional.<Integer>of(1)); Optional.<Integer>of(getEppResourceIndexBucketCount()), Optional.<Integer>of(1));
} }
protected List<QueueStateInfo.TaskStateInfo> getTasks(String queueName) { protected List<QueueStateInfo.TaskStateInfo> getTasks(String queueName) {

View file

@ -27,7 +27,7 @@ import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
import google.registry.config.TestRegistryConfig; import google.registry.config.RegistryConfig;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
@ -77,7 +77,7 @@ public class GenerateEscrowDepositCommandTest
inject.setStaticField(Ofy.class, "clock", clock); inject.setStaticField(Ofy.class, "clock", clock);
command.encryptor = EncryptEscrowDepositCommandTest.createEncryptor(); command.encryptor = EncryptEscrowDepositCommandTest.createEncryptor();
command.counter = new RdeCounter(); command.counter = new RdeCounter();
command.eppResourceIndexBucketCount = new TestRegistryConfig().getEppResourceIndexBucketCount(); command.eppResourceIndexBucketCount = RegistryConfig.getEppResourceIndexBucketCount();
} }
@Test @Test

View file

@ -15,6 +15,8 @@
package google.registry.ui.server.registrar; package google.registry.ui.server.registrar;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.RegistryConfig.getRegistrarDefaultReferralUrl;
import static google.registry.config.RegistryConfig.getRegistrarDefaultWhoisServer;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT; import static google.registry.testing.CertificateSamples.SAMPLE_CERT;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2; import static google.registry.testing.CertificateSamples.SAMPLE_CERT2;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2_HASH; import static google.registry.testing.CertificateSamples.SAMPLE_CERT2_HASH;
@ -23,7 +25,6 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import google.registry.config.RegistryEnvironment;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
@ -48,10 +49,11 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
"op", "update", "op", "update",
"args", modified.toJsonMap())); "args", modified.toJsonMap()));
// Empty whoisServer and referralUrl fields should be set to defaults by server. // Empty whoisServer and referralUrl fields should be set to defaults by server.
modified = modified.asBuilder() modified =
.setWhoisServer(RegistryEnvironment.get().config().getRegistrarDefaultWhoisServer()) modified
.setReferralUrl( .asBuilder()
RegistryEnvironment.get().config().getRegistrarDefaultReferralUrl().toString()) .setWhoisServer(getRegistrarDefaultWhoisServer())
.setReferralUrl(getRegistrarDefaultReferralUrl().toString())
.build(); .build();
assertThat(response).containsEntry("status", "SUCCESS"); assertThat(response).containsEntry("status", "SUCCESS");
assertThat(response).containsEntry("results", asList(modified.toJsonMap())); assertThat(response).containsEntry("results", asList(modified.toJsonMap()));