Remove the ofy().load() inside of HostResource.cloneProjectedAtTime

In fact, completely eviscerate cloneProjectedAtTime (to be removed in
a followup CL) in favor of doing the projection of transfers and the
loading of values from the superordinate domain at call sites. This
is one of the issues that blocked the memcache audit work, since the
load inside of cloneProjectedAtTime could not be controlled by the
caller.

Note: fixed a minor bug where a subordinate host created after its superordinate domain was last transferred should have lastTransferTime==null but was previously reporting the domain's lastTransferTime.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=149769125
This commit is contained in:
cgoldfeder 2017-03-10 10:05:26 -08:00 committed by Ben McIlwain
parent 1f000b94e6
commit 9174855a47
67 changed files with 970 additions and 471 deletions

View file

@ -93,7 +93,7 @@ public class DomainApplicationInfoFlowTest
.setRepoId("123-TLD")
.setFullyQualifiedDomainName("example.tld")
.setPhase(LaunchPhase.SUNRUSH)
.setCurrentSponsorClientId("NewRegistrar")
.setPersistedCurrentSponsorClientId("NewRegistrar")
.setCreationClientId("TheRegistrar")
.setLastEppUpdateClientId("NewRegistrar")
.setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z"))

View file

@ -91,7 +91,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
domain = persistResource(new DomainResource.Builder()
.setFullyQualifiedDomainName(domainName)
.setRepoId("2FF-TLD")
.setCurrentSponsorClientId("NewRegistrar")
.setPersistedCurrentSponsorClientId("NewRegistrar")
.setCreationClientId("TheRegistrar")
.setLastEppUpdateClientId("NewRegistrar")
.setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z"))

View file

@ -16,7 +16,6 @@ package google.registry.flows.domain;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.assertBillingEventsForResource;
import static google.registry.testing.DatastoreHelper.createTld;
@ -27,7 +26,6 @@ import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.USD;
@ -55,7 +53,6 @@ import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostResource;
import google.registry.model.poll.PendingActionNotificationResponse;
import google.registry.model.poll.PollMessage;
import google.registry.model.registrar.Registrar;
@ -107,13 +104,6 @@ public class DomainTransferApproveFlowTest
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER);
}
private void assertTransferApproved(HostResource host) {
assertAboutHosts().that(host)
.hasCurrentSponsorClientId("NewRegistrar").and()
.hasLastTransferTime(clock.nowUtc()).and()
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER);
}
private void setEppLoader(String commandFilename) {
setEppInput(commandFilename);
// Replace the ROID in the xml file with the one generated in our test.
@ -161,7 +151,6 @@ public class DomainTransferApproveFlowTest
assertAboutDomains().that(domain).hasRegistrationExpirationTime(expectedExpirationTime);
assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime())
.isEqualTo(expectedExpirationTime);
assertTransferApproved(reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc()));
// We expect three billing events: one for the transfer, a closed autorenew for the losing
// client and an open autorenew for the gaining client that begins at the new expiration time.
BillingEvent.OneTime transferBillingEvent = new BillingEvent.OneTime.Builder()
@ -287,60 +276,6 @@ public class DomainTransferApproveFlowTest
"domain_transfer_approve_response_net.xml");
}
@Test
public void testSuccess_lastTransferTime_reflectedOnSubordinateHost() throws Exception {
domain = reloadResourceByForeignKey();
// Set an older last transfer time on the subordinate host.
subordinateHost = persistResource(
subordinateHost.asBuilder()
.setLastTransferTime(DateTime.parse("2000-02-03T22:00:00.0Z"))
.build());
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
subordinateHost = loadByForeignKey(
HostResource.class, subordinateHost.getFullyQualifiedHostName(), clock.nowUtc());
// Verify that the host's last transfer time is now that of when the superordinate domain was
// transferred.
assertThat(subordinateHost.getLastTransferTime()).isEqualTo(clock.nowUtc());
}
@Test
public void testSuccess_lastTransferTime_overridesExistingOnSubordinateHost() throws Exception {
domain = reloadResourceByForeignKey();
// Set an older last transfer time on the subordinate host.
subordinateHost = persistResource(
subordinateHost.asBuilder()
.setLastTransferTime(DateTime.parse("2000-02-03T22:00:00.0Z"))
.setLastSuperordinateChange(DateTime.parse("2000-03-03T22:00:00.0Z"))
.build());
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
subordinateHost = loadByForeignKey(
HostResource.class, subordinateHost.getFullyQualifiedHostName(), clock.nowUtc());
// Verify that the host's last transfer time is now that of when the superordinate domain was
// transferred.
assertThat(subordinateHost.getLastTransferTime()).isEqualTo(clock.nowUtc());
}
@Test
public void testSuccess_lastTransferTime_overridesExistingOnSubordinateHostWithNullTransferTime()
throws Exception {
domain = reloadResourceByForeignKey();
// Set an older last transfer time on the subordinate host.
subordinateHost = persistResource(
subordinateHost.asBuilder()
.setLastTransferTime(null)
.setLastSuperordinateChange(DateTime.parse("2000-03-03T22:00:00.0Z"))
.build());
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
subordinateHost = loadByForeignKey(
HostResource.class, subordinateHost.getFullyQualifiedHostName(), clock.nowUtc());
// Verify that the host's last transfer time is now that of when the superordinate domain was
// transferred.
assertThat(subordinateHost.getLastTransferTime()).isEqualTo(clock.nowUtc());
}
@Test
public void testSuccess_domainAuthInfo() throws Exception {
doSuccessfulTest(

View file

@ -113,7 +113,6 @@ public class DomainTransferCancelFlowTest
assertAboutDomains().that(domain)
.hasRegistrationExpirationTime(originalExpirationTime).and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc());
assertTransferFailed(reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc()));
assertAboutDomains().that(domain).hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE,
HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST,

View file

@ -24,7 +24,6 @@ import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDomainWithPendingTransfer;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.GenericEppResourceSubject.assertAboutEppResources;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.base.Ascii;
@ -113,7 +112,7 @@ public class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
domain = new DomainResource.Builder()
.setRepoId("1-".concat(Ascii.toUpperCase(tld)))
.setFullyQualifiedDomainName(label + "." + tld)
.setCurrentSponsorClientId("TheRegistrar")
.setPersistedCurrentSponsorClientId("TheRegistrar")
.setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z"))
.setRegistrationExpirationTime(REGISTRATION_EXPIRATION_TIME)
@ -158,7 +157,7 @@ public class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
new HostResource.Builder()
.setRepoId("2-".concat(Ascii.toUpperCase(tld)))
.setFullyQualifiedHostName("ns1." + label + "." + tld)
.setCurrentSponsorClientId("TheRegistrar")
.setPersistedCurrentSponsorClientId("TheRegistrar")
.setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z"))
.setSuperordinateDomain(Key.create(domain))
@ -220,12 +219,6 @@ public class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
assertThat(transferData.getServerApproveEntities()).isEmpty();
}
protected void assertTransferFailed(HostResource resource) {
assertAboutEppResources().that(resource)
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER).and()
.hasCurrentSponsorClientId("TheRegistrar");
}
/** Adds a domain that has a pending transfer on it from TheRegistrar to NewRegistrar. */
protected void setupDomainWithPendingTransfer(String label, String tld) throws Exception {
setupDomain(label, tld);

View file

@ -84,7 +84,6 @@ public class DomainTransferRejectFlowTest
// Transfer should have been rejected. Verify correct fields were set.
domain = reloadResourceByForeignKey();
assertTransferFailed(domain, TransferStatus.CLIENT_REJECTED);
assertTransferFailed(reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc()));
assertAboutDomains().that(domain)
.hasRegistrationExpirationTime(originalExpirationTime).and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc()).and()

View file

@ -24,7 +24,6 @@ import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.GenericEppResourceSubject.assertAboutEppResources;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -64,7 +63,6 @@ import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.model.poll.PendingActionNotificationResponse;
import google.registry.model.poll.PollMessage;
import google.registry.model.registrar.Registrar;
@ -126,12 +124,6 @@ public class DomainTransferRequestFlowTest
.hasStatusValue(StatusValue.PENDING_TRANSFER);
}
private void assertTransferRequested(HostResource host) throws Exception {
assertAboutEppResources().that(host)
.hasCurrentSponsorClientId("TheRegistrar").and()
.hasStatusValue(StatusValue.PENDING_TRANSFER);
}
private void assertTransferApproved(DomainResource domain) {
DateTime afterAutoAck =
clock.nowUtc().plus(Registry.get(domain.getTld()).getAutomaticTransferLength());
@ -143,15 +135,6 @@ public class DomainTransferRequestFlowTest
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER);
}
private void assertTransferApproved(HostResource host) {
DateTime afterAutoAck =
clock.nowUtc().plus(Registry.get(domain.getTld()).getAutomaticTransferLength());
assertAboutHosts().that(host)
.hasCurrentSponsorClientId("NewRegistrar").and()
.hasLastTransferTime(afterAutoAck).and()
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER);
}
/**
* Runs a successful test. The extraExpectedBillingEvents parameter consists of cancellation
* billing event builders that have had all of their attributes set except for the parent history
@ -183,7 +166,6 @@ public class DomainTransferRequestFlowTest
int registrationYears = domain.getTransferData().getExtendedRegistrationYears();
subordinateHost = reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc());
assertTransferRequested(domain);
assertTransferRequested(subordinateHost);
assertAboutDomains().that(domain)
.hasPendingTransferExpirationTime(implicitTransferTime).and()
.hasOneHistoryEntryEachOfTypes(
@ -252,8 +234,6 @@ public class DomainTransferRequestFlowTest
null),
transferBillingEvent));
assertTransferApproved(domainAfterAutomaticTransfer);
assertTransferApproved(
subordinateHost.cloneProjectedAtTime(implicitTransferTime));
// Two poll messages on the gaining registrar's side at the expected expiration time: a
// (OneTime) transfer approved message, and an Autorenew poll message.