mv com/google/domain/registry google/registry

This change renames directories in preparation for the great package
rename. The repository is now in a broken state because the code
itself hasn't been updated. However this should ensure that git
correctly preserves history for each file.
This commit is contained in:
Justine Tunney 2016-05-13 18:55:08 -04:00
parent a41677aea1
commit 5012893c1d
2396 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,36 @@
package(
default_visibility = ["//java/com/google/domain/registry:registry_project"],
)
load("//java/com/google/testing/builddefs:GenTestRules.bzl", "GenTestRules")
java_library(
name = "inputs",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/base",
"//java/com/google/common/collect",
"//java/com/google/domain/registry/config",
"//java/com/google/domain/registry/mapreduce/inputs",
"//java/com/google/domain/registry/model",
"//java/com/google/domain/registry/util",
"//javatests/com/google/domain/registry/testing",
"//third_party/java/appengine:appengine-api-testonly",
"//third_party/java/appengine:appengine-testing",
"//third_party/java/appengine_mapreduce2:appengine_mapreduce",
"//third_party/java/joda_money",
"//third_party/java/joda_time",
"//third_party/java/junit",
"//third_party/java/objectify:objectify-v4_1",
"//third_party/java/truth",
],
)
GenTestRules(
name = "GeneratedTestRules",
default_test_size = "medium",
jvm_flags = ["-XX:MaxPermSize=256m"],
test_files = glob(["*Test.java"]),
deps = [":inputs"],
)

View file

@ -0,0 +1,373 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.mapreduce.inputs;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_;
import static com.google.domain.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
import static com.google.domain.registry.model.EppResourceUtils.loadByUniqueId;
import static com.google.domain.registry.model.index.EppResourceIndexBucket.getBucketKey;
import static com.google.domain.registry.testing.DatastoreHelper.createTld;
import static com.google.domain.registry.testing.DatastoreHelper.newDomainResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveDomain;
import static com.google.domain.registry.testing.DatastoreHelper.persistResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistSimpleResource;
import static com.google.domain.registry.util.DateTimeUtils.END_OF_TIME;
import static org.joda.money.CurrencyUnit.USD;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.collect.ImmutableSet;
import com.google.domain.registry.config.TestRegistryConfig;
import com.google.domain.registry.model.EppResource;
import com.google.domain.registry.model.ImmutableObject;
import com.google.domain.registry.model.billing.BillingEvent;
import com.google.domain.registry.model.billing.BillingEvent.Reason;
import com.google.domain.registry.model.contact.ContactResource;
import com.google.domain.registry.model.domain.DomainResource;
import com.google.domain.registry.model.index.EppResourceIndex;
import com.google.domain.registry.model.reporting.HistoryEntry;
import com.google.domain.registry.testing.AppEngineRule;
import com.google.domain.registry.testing.ExceptionRule;
import com.google.domain.registry.testing.RegistryConfigRule;
import com.googlecode.objectify.Key;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;
/** Tests {@link ChildEntityInput} */
@RunWith(JUnit4.class)
public class ChildEntityInputTest {
private static final DateTime now = DateTime.now(DateTimeZone.UTC);
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@Rule
public final RegistryConfigRule configRule = new RegistryConfigRule();
DomainResource domainA;
DomainResource domainB;
HistoryEntry domainHistoryEntryA;
HistoryEntry domainHistoryEntryB;
HistoryEntry contactHistoryEntry;
BillingEvent.OneTime oneTimeA;
BillingEvent.OneTime oneTimeB;
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");
domainHistoryEntryA = persistResource(
new HistoryEntry.Builder()
.setParent(domainA)
.setModificationTime(now)
.build());
contactHistoryEntry = persistResource(
new HistoryEntry.Builder()
.setParent(loadByUniqueId(ContactResource.class, "contact1234", now))
.setModificationTime(now)
.build());
oneTimeA = persistResource(
new BillingEvent.OneTime.Builder()
.setParent(domainHistoryEntryA)
.setReason(Reason.CREATE)
.setFlags(ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT))
.setPeriodYears(2)
.setCost(Money.of(USD, 1))
.setEventTime(now)
.setBillingTime(now.plusDays(5))
.setClientId("TheRegistrar")
.setTargetId("a.tld")
.build());
recurringA = persistResource(
new BillingEvent.Recurring.Builder()
.setParent(domainHistoryEntryA)
.setReason(Reason.AUTO_RENEW)
.setEventTime(now.plusYears(1))
.setRecurrenceEndTime(END_OF_TIME)
.setClientId("TheRegistrar")
.setTargetId("a.tld")
.build());
}
private void setupSecondDomainResources() {
domainB = persistActiveDomain("b.tld");
domainHistoryEntryB = persistResource(
new HistoryEntry.Builder()
.setParent(domainB)
.setModificationTime(now)
.build());
oneTimeB = persistResource(
new BillingEvent.OneTime.Builder()
.setParent(domainHistoryEntryA)
.setReason(Reason.CREATE)
.setFlags(ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT))
.setPeriodYears(2)
.setCost(Money.of(USD, 1))
.setEventTime(now)
.setBillingTime(now.plusDays(5))
.setClientId("TheRegistrar")
.setTargetId("a.tld")
.build());
recurringB = persistResource(
new BillingEvent.Recurring.Builder()
.setParent(domainHistoryEntryA)
.setReason(Reason.AUTO_RENEW)
.setEventTime(now.plusYears(1))
.setRecurrenceEndTime(END_OF_TIME)
.setClientId("TheRegistrar")
.setTargetId("a.tld")
.build());
}
@SuppressWarnings("unchecked")
private <T> T serializeAndDeserialize(T obj) throws Exception {
try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream objectOut = new ObjectOutputStream(byteOut)) {
objectOut.writeObject(obj);
try (ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream objectIn = new ObjectInputStream(byteIn)) {
return (T) objectIn.readObject();
}
}
}
@Test
public void testSuccess_childEntityReader_multipleParentsAndChildren() throws Exception {
setupResources();
setupSecondDomainResources();
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);
reader.beginShard();
reader.beginSlice();
for (int i = 0; i < 8; i++) {
reader.endSlice();
reader = serializeAndDeserialize(reader);
reader.beginSlice();
if (i == 7) {
thrown.expect(NoSuchElementException.class);
}
seen.add(reader.next());
}
assertThat(seen).containsExactly(
domainHistoryEntryA,
domainHistoryEntryB,
contactHistoryEntry,
oneTimeA,
recurringA,
oneTimeB,
recurringB);
}
@Test
public void testSuccess_childEntityInput_polymorphicBaseType() throws Exception {
createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(EppResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of(BillingEvent.class));
}
@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);
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();
}
@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();
}
@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();
}
@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();
}
@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();
}
@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);
}
@Test
public void testSuccess_childEntityReader_oneReaderPerBucket() throws Exception {
overrideBucketCount(3);
createTld("tld");
Set<ImmutableObject> historyEntries = new HashSet<>();
for (int i = 1; i <= 3; i++) {
DomainResource domain = persistSimpleResource(newDomainResource(i + ".tld"));
historyEntries.add(persistResource(
new HistoryEntry.Builder()
.setParent(domain)
.setModificationTime(now)
.setClientId(i + ".tld")
.build()));
persistResource(EppResourceIndex.create(getBucketKey(i), Key.create(domain)));
}
Set<ImmutableObject> seen = new HashSet<>();
for (InputReader<ImmutableObject> reader : EppResourceInputs.createChildEntityInput(
ImmutableSet.<Class<? extends EppResource>>of(DomainResource.class),
ImmutableSet.<Class<? extends ImmutableObject>>of(HistoryEntry.class)).createReaders()) {
reader.beginShard();
reader.beginSlice();
seen.add(reader.next());
try {
ImmutableObject o = reader.next();
assert_().fail("Unexpected element: " + o);
} catch (NoSuchElementException expected) {
}
}
assertThat(seen).containsExactlyElementsIn(historyEntries);
}
@Test
public void testSuccess_childEntityReader_survivesAcrossSerialization() 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);
reader.beginShard();
reader.beginSlice();
seen.add(reader.next());
seen.add(reader.next());
reader.endSlice();
reader = serializeAndDeserialize(reader);
reader.beginSlice();
seen.add(reader.next());
seen.add(reader.next());
assertThat(seen).containsExactly(
domainHistoryEntryA, contactHistoryEntry, oneTimeA, recurringA);
thrown.expect(NoSuchElementException.class);
reader.next();
}
}

View file

@ -0,0 +1,333 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.mapreduce.inputs;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_;
import static com.google.domain.registry.mapreduce.inputs.EppResourceInputs.createEntityInput;
import static com.google.domain.registry.mapreduce.inputs.EppResourceInputs.createKeyInput;
import static com.google.domain.registry.model.index.EppResourceIndexBucket.getBucketKey;
import static com.google.domain.registry.testing.DatastoreHelper.createTld;
import static com.google.domain.registry.testing.DatastoreHelper.newDomainApplication;
import static com.google.domain.registry.testing.DatastoreHelper.newDomainResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveContact;
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveDomain;
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveHost;
import static com.google.domain.registry.testing.DatastoreHelper.persistResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistSimpleResource;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.domain.registry.config.TestRegistryConfig;
import com.google.domain.registry.model.EppResource;
import com.google.domain.registry.model.contact.ContactResource;
import com.google.domain.registry.model.domain.DomainApplication;
import com.google.domain.registry.model.domain.DomainBase;
import com.google.domain.registry.model.domain.DomainResource;
import com.google.domain.registry.model.host.HostResource;
import com.google.domain.registry.model.index.EppResourceIndex;
import com.google.domain.registry.testing.AppEngineRule;
import com.google.domain.registry.testing.ExceptionRule;
import com.google.domain.registry.testing.RegistryConfigRule;
import com.googlecode.objectify.Key;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;
/** Tests {@link EppResourceInputs} */
@RunWith(JUnit4.class)
public class EppResourceInputsTest {
private static final double EPSILON = 0.0001;
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@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();
ObjectOutputStream objectOut = new ObjectOutputStream(byteOut)) {
objectOut.writeObject(obj);
try (ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream objectIn = new ObjectInputStream(byteIn)) {
return (T) objectIn.readObject();
}
}
}
@Test
public void testSuccess_keyInputType_polymorphicBaseType() throws Exception {
createKeyInput(DomainBase.class);
}
@Test
public void testFailure_keyInputType_polymorphicSubclass() throws Exception {
thrown.expect(IllegalArgumentException.class, "non-polymorphic");
createKeyInput(DomainResource.class);
}
@Test
public void testFailure_keyInputType_noInheritanceBetweenTypes_eppResource() throws Exception {
thrown.expect(IllegalArgumentException.class, "inheritance");
createKeyInput(EppResource.class, DomainBase.class);
}
@Test
public void testSuccess_entityInputTypesMayBePolymorphic() throws Exception {
// Both polymorphic and not should work.
createEntityInput(DomainBase.class);
createEntityInput(DomainResource.class);
}
@Test
public void testFailure_entityInputType_noInheritanceBetweenTypes_eppResource() throws Exception {
thrown.expect(IllegalArgumentException.class, "inheritance");
createEntityInput(EppResource.class, DomainResource.class);
}
@Test
public void testFailure_entityInputType_noInheritanceBetweenTypes_subclasses() throws Exception {
thrown.expect(IllegalArgumentException.class, "inheritance");
createEntityInput(DomainBase.class, DomainResource.class);
}
@Test
public void testReaderCountMatchesBucketCount() throws Exception {
overrideBucketCount(123);
assertThat(createKeyInput(DomainBase.class).createReaders()).hasSize(123);
assertThat(createEntityInput(DomainBase.class).createReaders()).hasSize(123);
}
@Test
public void testKeyInput_oneReaderPerBucket() throws Exception {
overrideBucketCount(3);
createTld("tld");
Set<Key<DomainResource>> domains = new HashSet<>();
for (int i = 1; i <= 3; i++) {
Key<DomainResource> key = Key.create(newDomainResource(i + ".tld"));
domains.add(key);
persistResource(EppResourceIndex.create(getBucketKey(i), key));
}
Set<Key<DomainBase>> seen = new HashSet<>();
for (InputReader<Key<DomainBase>> reader : createKeyInput(DomainBase.class).createReaders()) {
reader.beginShard();
reader.beginSlice();
seen.add(reader.next());
try {
reader.next();
assert_().fail("Unexpected element");
} catch (NoSuchElementException expected) {
}
}
assertThat(seen).containsExactlyElementsIn(domains);
}
@Test
public void testEntityInput_oneReaderPerBucket() throws Exception {
overrideBucketCount(3);
createTld("tld");
Set<DomainResource> domains = new HashSet<>();
for (int i = 1; i <= 3; i++) {
// Persist the domain as a simple resource so that it doesn't automatically get an ERI.
DomainResource domain = persistSimpleResource(newDomainResource(i + ".tld"));
domains.add(domain);
persistResource(EppResourceIndex.create(getBucketKey(i), Key.create(domain)));
}
Set<DomainResource> seen = new HashSet<>();
for (InputReader<DomainResource> reader
: createEntityInput(DomainResource.class).createReaders()) {
reader.beginShard();
reader.beginSlice();
seen.add(reader.next());
try {
reader.next();
assert_().fail("Unexpected element");
} catch (NoSuchElementException expected) {
}
}
assertThat(seen).containsExactlyElementsIn(domains);
}
@Test
public void testSuccess_keyReader_survivesAcrossSerialization() throws Exception {
createTld("tld");
overrideBucketCount(1);
DomainResource domainA = persistActiveDomain("a.tld");
DomainResource domainB = persistActiveDomain("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<>();
InputReader<Key<DomainBase>> reader = createKeyInput(DomainBase.class).createReaders().get(0);
reader.beginShard();
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.5);
reader.endSlice();
reader = serializeAndDeserialize(reader);
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.5);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(1);
assertThat(seen).containsExactly(Key.create(domainA), Key.create(domainB));
thrown.expect(NoSuchElementException.class);
reader.next();
}
@Test
public void testSuccess_entityReader_survivesAcrossSerialization() throws Exception {
createTld("tld");
overrideBucketCount(1);
DomainResource domainA = persistActiveDomain("a.tld");
DomainResource domainB = persistActiveDomain("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<>();
InputReader<DomainResource> reader =
createEntityInput(DomainResource.class).createReaders().get(0);
reader.beginShard();
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.5);
reader.endSlice();
reader = serializeAndDeserialize(reader);
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.5);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(1);
reader.endSlice();
reader.endShard();
assertThat(seen).containsExactly(domainA, domainB);
thrown.expect(NoSuchElementException.class);
reader.next();
}
@Test
public void testSuccess_entityReader_allowsPolymorphicMatches() throws Exception {
createTld("tld");
overrideBucketCount(1);
DomainResource domain = persistActiveDomain("a.tld");
DomainApplication application = persistActiveDomainApplication("b.tld");
Set<DomainBase> seen = new HashSet<>();
InputReader<DomainBase> reader =
createEntityInput(DomainBase.class).createReaders().get(0);
reader.beginShard();
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.5);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(1.0);
assertThat(seen).containsExactly(domain, application);
thrown.expect(NoSuchElementException.class);
reader.next();
}
@Test
public void testSuccess_entityReader_skipsPolymorphicMismatches() throws Exception {
createTld("tld");
overrideBucketCount(1);
persistActiveDomainApplication("b.tld");
DomainResource domainA = persistActiveDomain("a.tld");
InputReader<DomainResource> reader =
createEntityInput(DomainResource.class).createReaders().get(0);
reader.beginShard();
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
assertThat(reader.next()).isEqualTo(domainA);
// We can't reliably assert getProgress() here, since it counts before the postfilter that weeds
// out polymorphic mismatches, and so depending on whether the domain or the application was
// seen first it will be 0.5 or 1.0. However, there should be nothing left when we call next().
thrown.expect(NoSuchElementException.class);
reader.next();
}
@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");
Set<EppResource> seen = new HashSet<>();
InputReader<EppResource> reader =
EppResourceInputs.<EppResource>createEntityInput(
DomainResource.class, HostResource.class).createReaders().get(0);
reader.beginShard();
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.5);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(1.0);
assertThat(seen).containsExactly(domain, host);
thrown.expect(NoSuchElementException.class);
reader.next();
}
@Test
public void testSuccess_entityReader_noFilteringWhenUsingEppResource() throws Exception {
createTld("tld");
overrideBucketCount(1);
ContactResource contact = persistActiveContact("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");
Set<EppResource> seen = new HashSet<>();
InputReader<EppResource> reader = createEntityInput(EppResource.class).createReaders().get(0);
reader.beginShard();
reader.beginSlice();
assertThat(reader.getProgress()).isWithin(EPSILON).of(0);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.25);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.5);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(0.75);
seen.add(reader.next());
assertThat(reader.getProgress()).isWithin(EPSILON).of(1.0);
assertThat(seen).containsExactly(domain, host, application, contact);
thrown.expect(NoSuchElementException.class);
reader.next();
}
}