mirror of
https://github.com/google/nomulus.git
synced 2025-07-23 03:06:01 +02:00
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:
parent
7fba7c1e4f
commit
c5c74961bb
23 changed files with 224 additions and 324 deletions
|
@ -17,11 +17,11 @@ package google.registry.mapreduce.inputs;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
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.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.newContactResource;
|
||||
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.persistSimpleResource;
|
||||
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.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.TestRegistryConfig;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.ImmutableObject;
|
||||
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.testing.AppEngineRule;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.RegistryConfigRule;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@ -69,9 +67,6 @@ public class ChildEntityInputTest {
|
|||
@Rule
|
||||
public final ExceptionRule thrown = new ExceptionRule();
|
||||
|
||||
@Rule
|
||||
public final RegistryConfigRule configRule = new RegistryConfigRule();
|
||||
|
||||
DomainResource domainA;
|
||||
DomainResource domainB;
|
||||
HistoryEntry domainHistoryEntryA;
|
||||
|
@ -82,19 +77,10 @@ public class ChildEntityInputTest {
|
|||
BillingEvent.Recurring recurringA;
|
||||
BillingEvent.Recurring recurringB;
|
||||
|
||||
private void overrideBucketCount(final int count) {
|
||||
configRule.override(new TestRegistryConfig() {
|
||||
@Override
|
||||
public int getEppResourceIndexBucketCount() {
|
||||
return count;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupResources() {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
domainA = persistActiveDomain("a.tld");
|
||||
ContactResource contact = persistEppResourceInFirstBucket(newContactResource("contact1234"));
|
||||
domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld", contact));
|
||||
domainHistoryEntryA = persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domainA)
|
||||
|
@ -102,7 +88,7 @@ public class ChildEntityInputTest {
|
|||
.build());
|
||||
contactHistoryEntry = persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(loadByForeignKey(ContactResource.class, "contact1234", now))
|
||||
.setParent(contact)
|
||||
.setModificationTime(now)
|
||||
.build());
|
||||
oneTimeA = persistResource(
|
||||
|
@ -129,7 +115,7 @@ public class ChildEntityInputTest {
|
|||
}
|
||||
|
||||
private void setupSecondDomainResources() {
|
||||
domainB = persistActiveDomain("b.tld");
|
||||
domainB = persistEppResourceInFirstBucket(newDomainResource("b.tld"));
|
||||
domainHistoryEntryB = persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domainB)
|
||||
|
@ -211,110 +197,81 @@ public class ChildEntityInputTest {
|
|||
@Test
|
||||
public void testSuccess_childEntityReader_multipleChildTypes() throws Exception {
|
||||
setupResources();
|
||||
Set<ImmutableObject> seen = new HashSet<>();
|
||||
|
||||
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
|
||||
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
|
||||
ImmutableSet.<Class<? extends ImmutableObject>>of(
|
||||
HistoryEntry.class, BillingEvent.OneTime.class, BillingEvent.Recurring.class))
|
||||
.createReaders().get(0);
|
||||
assertThat(getAllFromReader(reader)).containsExactly(
|
||||
domainHistoryEntryA, contactHistoryEntry, oneTimeA, recurringA);
|
||||
}
|
||||
|
||||
private static Set<ImmutableObject> getAllFromReader(InputReader<ImmutableObject> reader)
|
||||
throws Exception {
|
||||
reader.beginShard();
|
||||
reader.beginSlice();
|
||||
seen.add(reader.next());
|
||||
seen.add(reader.next());
|
||||
seen.add(reader.next());
|
||||
seen.add(reader.next());
|
||||
assertThat(seen).containsExactly(
|
||||
domainHistoryEntryA, contactHistoryEntry, oneTimeA, recurringA);
|
||||
thrown.expect(NoSuchElementException.class);
|
||||
reader.next();
|
||||
ImmutableSet.Builder<ImmutableObject> seen = new ImmutableSet.Builder<>();
|
||||
try {
|
||||
while (true) {
|
||||
seen.add(reader.next());
|
||||
}
|
||||
} catch (NoSuchElementException e) {
|
||||
// Swallow; this is expected.
|
||||
}
|
||||
return seen.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_childEntityReader_filterParentTypes() throws Exception {
|
||||
setupResources();
|
||||
Set<ImmutableObject> seen = new HashSet<>();
|
||||
|
||||
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
|
||||
ImmutableSet.<Class<? extends EppResource>>of(ContactResource.class),
|
||||
ImmutableSet.<Class<? extends ImmutableObject>>of(
|
||||
HistoryEntry.class, BillingEvent.OneTime.class, BillingEvent.Recurring.class))
|
||||
.createReaders().get(0);
|
||||
|
||||
reader.beginShard();
|
||||
reader.beginSlice();
|
||||
seen.add(reader.next());
|
||||
assertThat(seen).containsExactly(contactHistoryEntry);
|
||||
thrown.expect(NoSuchElementException.class);
|
||||
reader.next();
|
||||
assertThat(getAllFromReader(reader)).containsExactly(contactHistoryEntry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_childEntityReader_polymorphicChildFiltering() throws Exception {
|
||||
setupResources();
|
||||
Set<ImmutableObject> seen = new HashSet<>();
|
||||
|
||||
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
|
||||
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
|
||||
ImmutableSet.<Class<? extends ImmutableObject>>of(BillingEvent.OneTime.class))
|
||||
.createReaders().get(0);
|
||||
|
||||
reader.beginShard();
|
||||
reader.beginSlice();
|
||||
seen.add(reader.next());
|
||||
assertThat(seen).containsExactly(oneTimeA);
|
||||
thrown.expect(NoSuchElementException.class);
|
||||
reader.next();
|
||||
assertThat(getAllFromReader(reader)).containsExactly(oneTimeA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_childEntityReader_polymorphicChildClass() throws Exception {
|
||||
setupResources();
|
||||
Set<ImmutableObject> seen = new HashSet<>();
|
||||
|
||||
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
|
||||
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
|
||||
ImmutableSet.<Class<? extends ImmutableObject>>of(BillingEvent.class))
|
||||
.createReaders().get(0);
|
||||
|
||||
reader.beginShard();
|
||||
reader.beginSlice();
|
||||
seen.add(reader.next());
|
||||
seen.add(reader.next());
|
||||
assertThat(seen).containsExactly(oneTimeA, recurringA);
|
||||
thrown.expect(NoSuchElementException.class);
|
||||
reader.next();
|
||||
assertThat(getAllFromReader(reader)).containsExactly(oneTimeA, recurringA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_childEntityReader_noneReturned() throws Exception {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
|
||||
InputReader<ImmutableObject> reader = EppResourceInputs.createChildEntityInput(
|
||||
ImmutableSet.<Class<? extends EppResource>>of(ContactResource.class),
|
||||
ImmutableSet.<Class<? extends ImmutableObject>>of(
|
||||
BillingEvent.OneTime.class)).createReaders().get(0);
|
||||
|
||||
reader.beginShard();
|
||||
reader.beginSlice();
|
||||
thrown.expect(NoSuchElementException.class);
|
||||
reader.next();
|
||||
assertThat(getAllFromReader(reader)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_childEntityReader_readerCountMatchesBucketCount() throws Exception {
|
||||
overrideBucketCount(123);
|
||||
assertThat(EppResourceInputs.createChildEntityInput(
|
||||
ImmutableSet.<Class<? extends EppResource>>of(DomainResource.class),
|
||||
ImmutableSet.<Class<? extends ImmutableObject>>of(
|
||||
BillingEvent.OneTime.class)).createReaders()).hasSize(123);
|
||||
BillingEvent.OneTime.class)).createReaders()).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_childEntityReader_oneReaderPerBucket() throws Exception {
|
||||
overrideBucketCount(3);
|
||||
createTld("tld");
|
||||
Set<ImmutableObject> historyEntries = new HashSet<>();
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
|
|
|
@ -20,18 +20,17 @@ import static google.registry.mapreduce.inputs.EppResourceInputs.createEntityInp
|
|||
import static google.registry.mapreduce.inputs.EppResourceInputs.createKeyInput;
|
||||
import static google.registry.model.index.EppResourceIndexBucket.getBucketKey;
|
||||
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.newDomainResource;
|
||||
import static google.registry.testing.DatastoreHelper.newHostResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
||||
import static google.registry.testing.DatastoreHelper.persistEppResourceInFirstBucket;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
|
||||
import com.google.appengine.tools.mapreduce.InputReader;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.TestRegistryConfig;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
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.testing.AppEngineRule;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.RegistryConfigRule;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@ -66,18 +64,6 @@ public class EppResourceInputsTest {
|
|||
@Rule
|
||||
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")
|
||||
private <T> T serializeAndDeserialize(T obj) throws Exception {
|
||||
try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
||||
|
@ -128,14 +114,12 @@ public class EppResourceInputsTest {
|
|||
|
||||
@Test
|
||||
public void testReaderCountMatchesBucketCount() throws Exception {
|
||||
overrideBucketCount(123);
|
||||
assertThat(createKeyInput(DomainBase.class).createReaders()).hasSize(123);
|
||||
assertThat(createEntityInput(DomainBase.class).createReaders()).hasSize(123);
|
||||
assertThat(createKeyInput(DomainBase.class).createReaders()).hasSize(3);
|
||||
assertThat(createEntityInput(DomainBase.class).createReaders()).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyInput_oneReaderPerBucket() throws Exception {
|
||||
overrideBucketCount(3);
|
||||
createTld("tld");
|
||||
Set<Key<DomainResource>> domains = new HashSet<>();
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
|
@ -159,7 +143,6 @@ public class EppResourceInputsTest {
|
|||
|
||||
@Test
|
||||
public void testEntityInput_oneReaderPerBucket() throws Exception {
|
||||
overrideBucketCount(3);
|
||||
createTld("tld");
|
||||
Set<DomainResource> domains = new HashSet<>();
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
|
@ -186,9 +169,8 @@ public class EppResourceInputsTest {
|
|||
@Test
|
||||
public void testSuccess_keyReader_survivesAcrossSerialization() throws Exception {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
DomainResource domainA = persistActiveDomain("a.tld");
|
||||
DomainResource domainB = persistActiveDomain("b.tld");
|
||||
DomainResource domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
|
||||
DomainResource domainB = persistEppResourceInFirstBucket(newDomainResource("b.tld"));
|
||||
// Should be ignored. We'll know if it isn't because the progress counts will be off.
|
||||
persistActiveContact("contact");
|
||||
Set<Key<DomainBase>> seen = new HashSet<>();
|
||||
|
@ -212,9 +194,8 @@ public class EppResourceInputsTest {
|
|||
@Test
|
||||
public void testSuccess_entityReader_survivesAcrossSerialization() throws Exception {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
DomainResource domainA = persistActiveDomain("a.tld");
|
||||
DomainResource domainB = persistActiveDomain("b.tld");
|
||||
DomainResource domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
|
||||
DomainResource domainB = persistEppResourceInFirstBucket(newDomainResource("b.tld"));
|
||||
// Should be ignored. We'll know if it isn't because the progress counts will be off.
|
||||
persistActiveContact("contact");
|
||||
Set<DomainResource> seen = new HashSet<>();
|
||||
|
@ -241,12 +222,10 @@ public class EppResourceInputsTest {
|
|||
@Test
|
||||
public void testSuccess_entityReader_allowsPolymorphicMatches() throws Exception {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
DomainResource domain = persistActiveDomain("a.tld");
|
||||
DomainApplication application = persistActiveDomainApplication("b.tld");
|
||||
DomainResource domain = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
|
||||
DomainApplication application = persistEppResourceInFirstBucket(newDomainApplication("b.tld"));
|
||||
Set<DomainBase> seen = new HashSet<>();
|
||||
InputReader<DomainBase> reader =
|
||||
createEntityInput(DomainBase.class).createReaders().get(0);
|
||||
InputReader<DomainBase> reader = createEntityInput(DomainBase.class).createReaders().get(0);
|
||||
reader.beginShard();
|
||||
reader.beginSlice();
|
||||
assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
|
||||
|
@ -262,9 +241,8 @@ public class EppResourceInputsTest {
|
|||
@Test
|
||||
public void testSuccess_entityReader_skipsPolymorphicMismatches() throws Exception {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
persistActiveDomainApplication("b.tld");
|
||||
DomainResource domainA = persistActiveDomain("a.tld");
|
||||
persistEppResourceInFirstBucket(newDomainApplication("b.tld"));
|
||||
DomainResource domainA = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
|
||||
InputReader<DomainResource> reader =
|
||||
createEntityInput(DomainResource.class).createReaders().get(0);
|
||||
reader.beginShard();
|
||||
|
@ -281,10 +259,9 @@ public class EppResourceInputsTest {
|
|||
@Test
|
||||
public void testSuccess_entityReader_filtersOnMultipleTypes() throws Exception {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
DomainResource domain = persistActiveDomain("a.tld");
|
||||
HostResource host = persistActiveHost("ns1.example.com");
|
||||
persistActiveContact("contact");
|
||||
DomainResource domain = persistEppResourceInFirstBucket(newDomainResource("a.tld"));
|
||||
HostResource host = persistEppResourceInFirstBucket(newHostResource("ns1.example.com"));
|
||||
persistEppResourceInFirstBucket(newContactResource("contact"));
|
||||
Set<EppResource> seen = new HashSet<>();
|
||||
InputReader<EppResource> reader =
|
||||
EppResourceInputs.<EppResource>createEntityInput(
|
||||
|
@ -304,12 +281,12 @@ public class EppResourceInputsTest {
|
|||
@Test
|
||||
public void testSuccess_entityReader_noFilteringWhenUsingEppResource() throws Exception {
|
||||
createTld("tld");
|
||||
overrideBucketCount(1);
|
||||
ContactResource contact = persistActiveContact("contact");
|
||||
ContactResource contact = persistEppResourceInFirstBucket(newContactResource("contact"));
|
||||
// Specify the contact since persistActiveDomain{Application} creates a hidden one.
|
||||
DomainResource domain = persistResource(newDomainResource("a.tld", contact));
|
||||
DomainApplication application = persistResource(newDomainApplication("b.tld", contact));
|
||||
HostResource host = persistActiveHost("ns1.example.com");
|
||||
DomainResource domain = persistEppResourceInFirstBucket(newDomainResource("a.tld", contact));
|
||||
DomainApplication application =
|
||||
persistEppResourceInFirstBucket(newDomainApplication("b.tld", contact));
|
||||
HostResource host = persistEppResourceInFirstBucket(newHostResource("ns1.example.com"));
|
||||
Set<EppResource> seen = new HashSet<>();
|
||||
InputReader<EppResource> reader = createEntityInput(EppResource.class).createReaders().get(0);
|
||||
reader.beginShard();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue