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:
mcilwain 2017-01-04 10:18:52 -08:00 committed by Ben McIlwain
parent 734130aa73
commit c35c3a678b
18 changed files with 119 additions and 206 deletions

View file

@ -62,8 +62,10 @@ public class CommitLogCheckpointActionTest {
task.clock = new FakeClock(now);
task.strategy = strategy;
task.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
when(strategy.computeCheckpoint()).thenReturn(
CommitLogCheckpoint.create(now, ImmutableMap.of(1, START_OF_TIME)));
when(strategy.computeCheckpoint())
.thenReturn(
CommitLogCheckpoint.create(
now, ImmutableMap.of(1, START_OF_TIME, 2, START_OF_TIME, 3, START_OF_TIME)));
}
@Test

View file

@ -24,7 +24,6 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.VoidWork;
import google.registry.config.TestRegistryConfig;
import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.ofy.CommitLogBucket;
@ -93,13 +92,6 @@ public class CommitLogCheckpointStrategyTest {
strategy.clock = clock;
strategy.ofy = ofy;
// Use three commit log buckets for easier but sufficiently complex testing.
configRule.override(new TestRegistryConfig() {
@Override
public int getCommitLogBucketCount() {
return 3;
}});
// Need to inject clock into Ofy so that createTld() below will get the right time.
inject.setStaticField(Ofy.class, "clock", clock);
// Inject a fake bucket ID supplier so we can dole out specific bucket IDs to commit logs.

View file

@ -15,10 +15,11 @@
package google.registry.backup;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.RegistryConfig.getCommitLogBucketCount;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static org.joda.time.Duration.millis;
import com.googlecode.objectify.VoidWork;
import google.registry.config.TestRegistryConfig;
import google.registry.model.ofy.CommitLogManifest;
import google.registry.model.ofy.CommitLogMutation;
import google.registry.model.ofy.Ofy;
@ -26,10 +27,8 @@ import google.registry.model.registrar.Registrar;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.RegistryConfigRule;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -44,29 +43,28 @@ public class DeleteOldCommitLogsActionTest {
.withDatastore()
.build();
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
private final Ofy ofy = new Ofy(clock);
private final DeleteOldCommitLogsAction task = new DeleteOldCommitLogsAction();
@Before
public void before() throws Exception {
task.bucketNum = 1;
task.clock = clock;
task.maxAge = Duration.millis(2);
task.maxDeletes = 4;
task.ofy = ofy;
private void runInAllBuckets(int maxDeletes) {
for (int bucketNum = 1; bucketNum <= getCommitLogBucketCount(); bucketNum++) {
DeleteOldCommitLogsAction task = new DeleteOldCommitLogsAction();
task.bucketNum = bucketNum;
task.clock = clock;
task.maxAge = Duration.millis(2);
task.maxDeletes = maxDeletes;
task.ofy = ofy;
task.run();
}
}
@Test
public void testRun_noCommitLogs_doesNothing() throws Exception {
assertManifestAndMutationCounts(0, 0);
task.run();
runInAllBuckets(4);
assertManifestAndMutationCounts(0, 0);
}
@ -75,7 +73,7 @@ public class DeleteOldCommitLogsActionTest {
createCommitLog();
clock.advanceOneMilli();
assertManifestAndMutationCounts(1, 2);
task.run();
runInAllBuckets(4);
assertManifestAndMutationCounts(1, 2);
}
@ -83,7 +81,7 @@ public class DeleteOldCommitLogsActionTest {
public void testRun_commitLogEqualToThreshold_doesntGetDeleted() throws Exception {
createCommitLog();
clock.advanceBy(millis(2));
task.run();
runInAllBuckets(4);
assertManifestAndMutationCounts(1, 2);
}
@ -91,7 +89,7 @@ public class DeleteOldCommitLogsActionTest {
public void testRun_commitLogOlderThanThreshold_getsDeleted() throws Exception {
createCommitLog();
clock.advanceBy(millis(3));
task.run();
runInAllBuckets(4);
assertManifestAndMutationCounts(0, 0);
}
@ -101,34 +99,31 @@ public class DeleteOldCommitLogsActionTest {
clock.advanceBy(millis(3));
createCommitLog();
assertManifestAndMutationCounts(2, 4);
task.run();
runInAllBuckets(4);
assertManifestAndMutationCounts(1, 2);
}
@Test
public void testRun_twoOlderThanThreshold_bothGetDeletedInSameTransaction() throws Exception {
task.maxDeletes = 2;
createCommitLog();
clock.advanceOneMilli();
createCommitLog();
clock.advanceBy(millis(3));
assertManifestAndMutationCounts(2, 4);
task.run();
runInAllBuckets(2);
assertManifestAndMutationCounts(0, 0);
}
@Test
public void testRun_twoOlderThanThreshold_bothGetDeletedInTwoTransactions() throws Exception {
task.maxDeletes = 1;
createCommitLog();
clock.advanceOneMilli();
createCommitLog();
clock.advanceBy(millis(3));
createCommitLog();
assertManifestAndMutationCounts(3, 6);
task.run();
assertManifestAndMutationCounts(2, 4);
task.run();
runInAllBuckets(1);
runInAllBuckets(1);
assertManifestAndMutationCounts(1, 2);
}
@ -136,20 +131,22 @@ public class DeleteOldCommitLogsActionTest {
public void testRun_commitLogOlderButInADifferentBucket_doesntGetDeleted() throws Exception {
createCommitLog();
clock.advanceBy(millis(31337));
configRule.override(new TestRegistryConfig() {
@Override public int getCommitLogBucketCount() { return 2; }
});
task.bucketNum = 2;
int usedBucketNum = ofy().load().type(CommitLogManifest.class).list().get(0).getBucketId();
DeleteOldCommitLogsAction task = new DeleteOldCommitLogsAction();
task.bucketNum = (usedBucketNum % getCommitLogBucketCount()) + 1;
task.clock = clock;
task.maxAge = Duration.millis(2);
task.maxDeletes = 20;
task.ofy = ofy;
task.run();
assertManifestAndMutationCounts(1, 2);
}
@Test
public void testRun_lessThanATenthOfOldData_doesntGetDeleted() throws Exception {
task.maxDeletes = 20;
createCommitLog();
clock.advanceBy(millis(2));
task.run();
runInAllBuckets(20);
assertManifestAndMutationCounts(1, 2);
}

View file

@ -30,7 +30,6 @@ import com.google.appengine.tools.cloudstorage.GcsServiceFactory;
import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;
import google.registry.config.TestRegistryConfig;
import google.registry.model.ImmutableObject;
import google.registry.model.ofy.CommitLogBucket;
import google.registry.model.ofy.CommitLogCheckpoint;
@ -38,7 +37,6 @@ import google.registry.model.ofy.CommitLogManifest;
import google.registry.model.ofy.CommitLogMutation;
import google.registry.testing.AppEngineRule;
import google.registry.testing.GcsTestingUtils;
import google.registry.testing.RegistryConfigRule;
import google.registry.testing.TestObject;
import java.util.List;
import org.joda.time.DateTime;
@ -52,20 +50,11 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ExportCommitLogDiffActionTest {
private static final int NUM_BUCKETS = 3;
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule(
new TestRegistryConfig() {
@Override public int getCommitLogBucketCount() {
return NUM_BUCKETS;
}});
/** Local GCS service available for testing. */
private final GcsService gcsService = GcsServiceFactory.createGcsService();

View file

@ -40,7 +40,6 @@ import com.google.common.collect.Lists;
import com.google.common.primitives.Longs;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;
import google.registry.config.TestRegistryConfig;
import google.registry.model.ImmutableObject;
import google.registry.model.ofy.CommitLogBucket;
import google.registry.model.ofy.CommitLogCheckpoint;
@ -96,11 +95,6 @@ public class RestoreCommitLogsActionTest {
action.diffLister.gcsService = gcsService;
action.diffLister.gcsBucket = GCS_BUCKET;
action.diffLister.executor = newDirectExecutorService();
configRule.override(new TestRegistryConfig() {
@Override
public int getCommitLogBucketCount() {
return 3;
}});
}
@Test