mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Change commit log bucket counts in tests
I'm setting it to three buckets across all tests, because the default one bucket wasn't realistic enough, and allowed some tests to pass that shouldn't have, essentially by accident. This also changes RegistryConfig from being an interface to being an abstract base class. The medium term goal here is to have it be a static class so that it can provide fields from the YAML-derived POJO in situations where Dagger injection isn't feasible. The expected end state is as follows: default-config.yaml -- The master config file that provides defaults for all values. nomulus-config.yaml -- A per-environment config file that overrides the defaults from the previous file. YamlConfig.java -- The POJO that the aforementioned YAML files are deserialized into. RegistryConfig.java -- Contains a static, memoized instance of YamlConfig and provides static methods for getting some of those values. ConfigModule -- Will become a static inner class of RegistryConfig, using Dagger to provide most of the fields from the memoized YamlConfig instance. This way, all configuration will be coming from a single place: RegistryConfig.java. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=143567288
This commit is contained in:
parent
734130aa73
commit
c35c3a678b
18 changed files with 119 additions and 206 deletions
|
@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.common.base.Verify.verify;
|
||||
import static google.registry.bigquery.BigqueryUtils.toJobReferenceString;
|
||||
import static google.registry.config.RegistryConfig.getProjectId;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||
|
@ -60,7 +61,6 @@ import google.registry.bigquery.BigqueryUtils.DestinationFormat;
|
|||
import google.registry.bigquery.BigqueryUtils.SourceFormat;
|
||||
import google.registry.bigquery.BigqueryUtils.TableType;
|
||||
import google.registry.bigquery.BigqueryUtils.WriteDisposition;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.util.FormattingLogger;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import google.registry.util.Sleeper;
|
||||
|
@ -246,7 +246,7 @@ public class BigqueryConnection implements AutoCloseable {
|
|||
}
|
||||
|
||||
public DestinationTable build() {
|
||||
tableRef.setProjectId(getEnvironmentProjectId());
|
||||
tableRef.setProjectId(getProjectId());
|
||||
table.setTableReference(tableRef);
|
||||
checkState(!isNullOrEmpty(table.getTableReference().getDatasetId()));
|
||||
checkState(!isNullOrEmpty(table.getTableReference().getTableId()));
|
||||
|
@ -704,16 +704,6 @@ public class BigqueryConnection implements AutoCloseable {
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns the projectId set by the environment, or {@code null} if none is set. */
|
||||
public static String getEnvironmentProjectId() {
|
||||
return RegistryEnvironment.get().config().getProjectId();
|
||||
}
|
||||
|
||||
/** Returns the projectId associated with this bigquery connection. */
|
||||
public String getProjectId() {
|
||||
return getEnvironmentProjectId();
|
||||
}
|
||||
|
||||
/** Returns the dataset name that this bigquery connection uses by default. */
|
||||
public String getDatasetId() {
|
||||
return datasetId;
|
||||
|
|
|
@ -79,8 +79,8 @@ public final class ConfigModule {
|
|||
|
||||
@Provides
|
||||
@Config("projectId")
|
||||
public static String provideProjectId(RegistryConfig config) {
|
||||
return config.getProjectId();
|
||||
public static String provideProjectId() {
|
||||
return RegistryConfig.getProjectId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,6 @@ import static google.registry.config.ConfigUtils.makeUrl;
|
|||
import static org.joda.time.Duration.standardDays;
|
||||
|
||||
import com.google.appengine.api.utils.SystemProperty;
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.net.HostAndPort;
|
||||
import java.net.URL;
|
||||
|
@ -34,7 +33,7 @@ import org.joda.time.Duration;
|
|||
* described in the {@link RegistryConfigLoader} documentation.
|
||||
*/
|
||||
@Immutable
|
||||
public final class ProductionRegistryConfigExample implements RegistryConfig {
|
||||
public final class ProductionRegistryConfigExample extends RegistryConfig {
|
||||
|
||||
private final RegistryEnvironment environment;
|
||||
|
||||
|
@ -49,22 +48,6 @@ public final class ProductionRegistryConfigExample implements RegistryConfig {
|
|||
this.environment = checkNotNull(environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectId() {
|
||||
String prodProjectId = "domain-registry";
|
||||
switch (environment) {
|
||||
case PRODUCTION:
|
||||
return prodProjectId;
|
||||
default:
|
||||
return prodProjectId + "-" + Ascii.toLowerCase(environment.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCommitLogBucketCount() {
|
||||
return 100; // if you decrease this number, the world ends
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -79,7 +62,7 @@ public final class ProductionRegistryConfigExample implements RegistryConfig {
|
|||
|
||||
@Override
|
||||
public String getSnapshotsBucket() {
|
||||
return getProjectId() + "-snapshots";
|
||||
return RegistryConfig.getProjectId() + "-snapshots";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.config;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.net.HostAndPort;
|
||||
import java.net.URL;
|
||||
|
@ -24,22 +25,31 @@ import org.joda.time.Duration;
|
|||
*
|
||||
* <p>The goal of this custom configuration system is to have our project environments configured
|
||||
* in type-safe Java code that can be refactored, rather than XML files and system properties.
|
||||
*
|
||||
* <p><b>Note:</b> This interface is deprecated by {@link ConfigModule}.
|
||||
*/
|
||||
public interface RegistryConfig {
|
||||
public abstract class RegistryConfig {
|
||||
|
||||
/**
|
||||
* Returns the App Engine project ID, which is based off the environment name.
|
||||
*/
|
||||
public String getProjectId();
|
||||
public static String getProjectId() {
|
||||
String prodProjectId = "domain-registry";
|
||||
RegistryEnvironment environment = RegistryEnvironment.get();
|
||||
switch (environment) {
|
||||
case PRODUCTION:
|
||||
case UNITTEST:
|
||||
case LOCAL:
|
||||
return prodProjectId;
|
||||
default:
|
||||
return prodProjectId + "-" + Ascii.toLowerCase(environment.name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Google Cloud Storage bucket for storing backup snapshots.
|
||||
*
|
||||
* @see google.registry.export.ExportSnapshotServlet
|
||||
*/
|
||||
public String getSnapshotsBucket();
|
||||
public abstract String getSnapshotsBucket();
|
||||
|
||||
/**
|
||||
* Number of sharded commit log buckets.
|
||||
|
@ -54,7 +64,14 @@ public interface RegistryConfig {
|
|||
*
|
||||
* @see google.registry.model.ofy.CommitLogBucket
|
||||
*/
|
||||
public int getCommitLogBucketCount();
|
||||
public static int getCommitLogBucketCount() {
|
||||
switch (RegistryEnvironment.get()) {
|
||||
case UNITTEST:
|
||||
return 3;
|
||||
default:
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of time before commit logs should be deleted from datastore.
|
||||
|
@ -65,26 +82,26 @@ public interface RegistryConfig {
|
|||
* @see google.registry.backup.DeleteOldCommitLogsAction
|
||||
* @see google.registry.model.translators.CommitLogRevisionsTranslatorFactory
|
||||
*/
|
||||
public Duration getCommitLogDatastoreRetention();
|
||||
public abstract Duration getCommitLogDatastoreRetention();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if TMCH certificate authority should be in testing mode.
|
||||
*
|
||||
* @see google.registry.tmch.TmchCertificateAuthority
|
||||
*/
|
||||
public boolean getTmchCaTestingMode();
|
||||
public abstract boolean getTmchCaTestingMode();
|
||||
|
||||
public Optional<String> getECatcherAddress();
|
||||
public abstract Optional<String> getECatcherAddress();
|
||||
|
||||
/**
|
||||
* Returns the address of the Nomulus app HTTP server.
|
||||
*
|
||||
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
|
||||
*/
|
||||
public HostAndPort getServer();
|
||||
public abstract HostAndPort getServer();
|
||||
|
||||
/** Returns the amount of time a singleton should be cached, before expiring. */
|
||||
public Duration getSingletonCacheRefreshDuration();
|
||||
public abstract Duration getSingletonCacheRefreshDuration();
|
||||
|
||||
/**
|
||||
* Returns the amount of time a domain label list should be cached in memory before expiring.
|
||||
|
@ -92,31 +109,31 @@ public interface RegistryConfig {
|
|||
* @see google.registry.model.registry.label.ReservedList
|
||||
* @see google.registry.model.registry.label.PremiumList
|
||||
*/
|
||||
public Duration getDomainLabelListCacheDuration();
|
||||
public abstract Duration getDomainLabelListCacheDuration();
|
||||
|
||||
/** Returns the amount of time a singleton should be cached in persist mode, before expiring. */
|
||||
public Duration getSingletonCachePersistDuration();
|
||||
public abstract Duration getSingletonCachePersistDuration();
|
||||
|
||||
/**
|
||||
* Returns the header text at the top of the reserved terms exported list.
|
||||
*
|
||||
* @see google.registry.export.ExportUtils#exportReservedTerms
|
||||
*/
|
||||
public String getReservedTermsExportDisclaimer();
|
||||
public abstract String getReservedTermsExportDisclaimer();
|
||||
|
||||
/**
|
||||
* Returns a display name that is used on outgoing emails sent by Nomulus.
|
||||
*
|
||||
* @see google.registry.util.SendEmailUtils
|
||||
*/
|
||||
public String getGoogleAppsAdminEmailDisplayName();
|
||||
public abstract String getGoogleAppsAdminEmailDisplayName();
|
||||
|
||||
/**
|
||||
* Returns the email address that outgoing emails from the app are sent from.
|
||||
*
|
||||
* @see google.registry.util.SendEmailUtils
|
||||
*/
|
||||
public String getGoogleAppsSendFromEmailAddress();
|
||||
public abstract String getGoogleAppsSendFromEmailAddress();
|
||||
|
||||
/**
|
||||
* Returns default WHOIS server to use when {@code Registrar#getWhoisServer()} is {@code null}.
|
||||
|
@ -124,33 +141,33 @@ public interface RegistryConfig {
|
|||
* @see "google.registry.whois.DomainWhoisResponse"
|
||||
* @see "google.registry.whois.RegistrarWhoisResponse"
|
||||
*/
|
||||
public String getRegistrarDefaultWhoisServer();
|
||||
public abstract String getRegistrarDefaultWhoisServer();
|
||||
|
||||
/**
|
||||
* Returns the default referral URL that is used unless registrars have specified otherwise.
|
||||
*/
|
||||
public URL getRegistrarDefaultReferralUrl();
|
||||
public abstract URL getRegistrarDefaultReferralUrl();
|
||||
|
||||
/**
|
||||
* Returns the number of EppResourceIndex buckets to be used.
|
||||
*/
|
||||
public int getEppResourceIndexBucketCount();
|
||||
public abstract int getEppResourceIndexBucketCount();
|
||||
|
||||
/**
|
||||
* Returns the base duration that gets doubled on each retry within {@code Ofy}.
|
||||
*/
|
||||
public Duration getBaseOfyRetryDuration();
|
||||
public abstract Duration getBaseOfyRetryDuration();
|
||||
|
||||
/**
|
||||
* Returns the global automatic transfer length for contacts. After this amount of time has
|
||||
* elapsed, the transfer is automatically approved.
|
||||
*/
|
||||
public Duration getContactAutomaticTransferLength();
|
||||
public abstract Duration getContactAutomaticTransferLength();
|
||||
|
||||
/**
|
||||
* Returns the clientId of the registrar used by the {@code CheckApiServlet}.
|
||||
*/
|
||||
public String getCheckApiServletRegistrarClientId();
|
||||
public abstract String getCheckApiServletRegistrarClientId();
|
||||
|
||||
// XXX: Please consider using ConfigModule instead of adding new methods to this file.
|
||||
}
|
||||
|
|
|
@ -25,20 +25,10 @@ import org.joda.time.Duration;
|
|||
/**
|
||||
* An implementation of RegistryConfig for unit testing that contains suitable testing data.
|
||||
*/
|
||||
public class TestRegistryConfig implements RegistryConfig {
|
||||
public class TestRegistryConfig extends RegistryConfig {
|
||||
|
||||
public TestRegistryConfig() {}
|
||||
|
||||
@Override
|
||||
public String getProjectId() {
|
||||
return "domain-registry";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCommitLogBucketCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Duration getCommitLogDatastoreRetention() {
|
||||
return Duration.standardDays(30);
|
||||
|
@ -46,7 +36,7 @@ public class TestRegistryConfig implements RegistryConfig {
|
|||
|
||||
@Override
|
||||
public String getSnapshotsBucket() {
|
||||
return getProjectId() + "-snapshots";
|
||||
return RegistryConfig.getProjectId() + "-snapshots";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.model.ofy;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.DiscreteDomain.integers;
|
||||
import static com.googlecode.objectify.ObjectifyService.ofy;
|
||||
import static google.registry.config.RegistryConfig.getCommitLogBucketCount;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -29,7 +30,7 @@ import com.google.common.collect.Range;
|
|||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.config.RegistryConfig;
|
||||
import google.registry.model.Buildable;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.annotations.NotBackedUp;
|
||||
|
@ -41,8 +42,8 @@ import org.joda.time.DateTime;
|
|||
/**
|
||||
* Root for a random commit log bucket.
|
||||
*
|
||||
* <p>This is used to shard {@link CommitLogManifest} objects into {@link
|
||||
* google.registry.config.RegistryConfig#getCommitLogBucketCount() N} entity groups. This increases
|
||||
* <p>This is used to shard {@link CommitLogManifest} objects into
|
||||
* {@link RegistryConfig#getCommitLogBucketCount() N} entity groups. This increases
|
||||
* transaction throughput, while maintaining the ability to perform strongly-consistent ancestor
|
||||
* queries.
|
||||
*
|
||||
|
@ -53,11 +54,11 @@ import org.joda.time.DateTime;
|
|||
@NotBackedUp(reason = Reason.COMMIT_LOGS)
|
||||
public class CommitLogBucket extends ImmutableObject implements Buildable {
|
||||
|
||||
private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get();
|
||||
|
||||
/** Ranges from 1 to {@link #getNumBuckets()}, inclusive; starts at 1 since IDs can't be 0. */
|
||||
@Id
|
||||
long bucketNum;
|
||||
/**
|
||||
* Ranges from 1 to {@link RegistryConfig#getCommitLogBucketCount()}, inclusive; starts at 1 since
|
||||
* IDs can't be 0.
|
||||
*/
|
||||
@Id long bucketNum;
|
||||
|
||||
/** The timestamp of the last {@link CommitLogManifest} written to this bucket. */
|
||||
DateTime lastWrittenTime = START_OF_TIME;
|
||||
|
@ -90,12 +91,8 @@ public class CommitLogBucket extends ImmutableObject implements Buildable {
|
|||
return ContiguousSet.create(getBucketIdRange(), integers());
|
||||
}
|
||||
|
||||
private static int getNumBuckets() {
|
||||
return ENVIRONMENT.config().getCommitLogBucketCount();
|
||||
}
|
||||
|
||||
private static Range<Integer> getBucketIdRange() {
|
||||
return Range.closed(1, getNumBuckets());
|
||||
return Range.closed(1, getCommitLogBucketCount());
|
||||
}
|
||||
|
||||
/** Returns an arbitrary numeric bucket ID. Default behavior is randomly chosen IDs. */
|
||||
|
@ -116,7 +113,7 @@ public class CommitLogBucket extends ImmutableObject implements Buildable {
|
|||
|
||||
@Override
|
||||
public Integer get() {
|
||||
return random.nextInt(getNumBuckets()) + 1; // Add 1 since IDs can't be 0.
|
||||
return random.nextInt(getCommitLogBucketCount()) + 1; // Add 1 since IDs can't be 0.
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue