mirror of
https://github.com/google/nomulus.git
synced 2025-08-16 22:44:06 +02:00
DeReference the codebase
This change replaces all Ref objects in the code with Key objects. These are stored in datastore as the same object (raw datastore keys), so this is not a model change. Our best practices doc says to use Keys not Refs because: * The .get() method obscures what's actually going on - Much harder to visually audit the code for datastore loads - Hard to distinguish Ref<T> get()'s from Optional get()'s and Supplier get()'s * Implicit ofy().load() offers much less control - Antipattern for ultimate goal of making Ofy injectable - Can't control cache use or batch loading without making ofy() explicit anyway * Serialization behavior is surprising and could be quite dangerous/incorrect - Can lead to serialization errors. If it actually worked "as intended", it would lead to a Ref<> on a serialized object being replaced upon deserialization with a stale copy of the old value, which could potentially break all kinds of transactional expectations * Having both Ref<T> and Key<T> introduces extra boilerplate everywhere - E.g. helper methods all need to have Ref and Key overloads, or you need to call .key() to get the Key<T> for every Ref<T> you want to pass in - Creating a Ref<T> is more cumbersome, since it doesn't have all the create() overloads that Key<T> has, only create(Key<T>) and create(Entity) - no way to create directly from kind+ID/name, raw Key, websafe key string, etc. (Note that Refs are treated specially by Objectify's @Load method and Keys are not; we don't use that feature, but it is the one advantage Refs have over Keys.) The direct impetus for this change is that I am trying to audit our use of memcache, and the implicit .get() calls to datastore were making that very hard. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=131965491
This commit is contained in:
parent
1a60073b24
commit
5098b03af4
119 changed files with 772 additions and 817 deletions
|
@ -42,7 +42,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Ref;
|
||||
import google.registry.flows.EppRequestSource;
|
||||
import google.registry.flows.ResourceCreateOrMutateFlow.OnlyToolCanPassMetadataException;
|
||||
import google.registry.flows.ResourceFlowTestCase;
|
||||
|
@ -111,8 +110,8 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
PollMessage.Autorenew autorenewPollMessage = persistResource(
|
||||
createAutorenewPollMessage("TheRegistrar").build());
|
||||
domain = persistResource(domain.asBuilder()
|
||||
.setAutorenewBillingEvent(Ref.create(autorenewBillingEvent))
|
||||
.setAutorenewPollMessage(Ref.create(autorenewPollMessage))
|
||||
.setAutorenewBillingEvent(Key.create(autorenewBillingEvent))
|
||||
.setAutorenewPollMessage(Key.create(autorenewPollMessage))
|
||||
.build());
|
||||
assertTransactionalFlow(true);
|
||||
}
|
||||
|
@ -122,7 +121,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
ContactResource contact = persistActiveContact("sh8013");
|
||||
domain = newDomainResource(getUniqueIdFromCommand()).asBuilder()
|
||||
.setCreationTimeForTest(TIME_BEFORE_FLOW)
|
||||
.setRegistrant(Ref.create(contact))
|
||||
.setRegistrant(Key.create(contact))
|
||||
.setRegistrationExpirationTime(expirationTime)
|
||||
.build();
|
||||
earlierHistoryEntry = persistResource(
|
||||
|
@ -153,9 +152,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
GracePeriodStatus.AUTO_RENEW,
|
||||
A_MONTH_AGO.plusDays(45),
|
||||
"TheRegistrar",
|
||||
Ref.create(autorenewBillingEvent))))
|
||||
.setAutorenewBillingEvent(Ref.create(autorenewBillingEvent))
|
||||
.setAutorenewPollMessage(Ref.create(autorenewPollMessage))
|
||||
Key.create(autorenewBillingEvent))))
|
||||
.setAutorenewBillingEvent(Key.create(autorenewBillingEvent))
|
||||
.setAutorenewPollMessage(Key.create(autorenewPollMessage))
|
||||
.build());
|
||||
assertTransactionalFlow(true);
|
||||
}
|
||||
|
@ -175,7 +174,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
.setClientId("TheRegistrar")
|
||||
.setEventTime(eventTime)
|
||||
.setBillingTime(TIME_BEFORE_FLOW.plusDays(1))
|
||||
.setOneTimeEventRef(Ref.create(graceBillingEvent))
|
||||
.setOneTimeEventKey(Key.create(graceBillingEvent))
|
||||
.setParent(historyEntryDomainDelete)
|
||||
.build());
|
||||
}
|
||||
|
@ -238,7 +237,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
throws Exception {
|
||||
doImmediateDeleteTest(gracePeriodStatus, responseFilename, ImmutableMap.<String, String>of());
|
||||
}
|
||||
|
||||
|
||||
private void doImmediateDeleteTest(
|
||||
GracePeriodStatus gracePeriodStatus,
|
||||
String responseFilename,
|
||||
|
@ -296,7 +295,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
private void doSuccessfulTest_noAddGracePeriod(String responseFilename) throws Exception {
|
||||
doSuccessfulTest_noAddGracePeriod(responseFilename, ImmutableMap.<String, String>of());
|
||||
}
|
||||
|
||||
|
||||
private void doSuccessfulTest_noAddGracePeriod(
|
||||
String responseFilename, Map<String, String> substitutions) throws Exception {
|
||||
// Persist the billing event so it can be retrieved for cancellation generation and checking.
|
||||
|
@ -373,7 +372,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
// Modify the autorenew poll message so that it has unacked messages in the past. This should
|
||||
// prevent it from being deleted when the domain is deleted.
|
||||
persistResource(
|
||||
reloadResourceByUniqueId().getAutorenewPollMessage().get().asBuilder()
|
||||
ofy().load().key(reloadResourceByUniqueId().getAutorenewPollMessage()).now().asBuilder()
|
||||
.setEventTime(A_MONTH_FROM_NOW.minusYears(3))
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
|
@ -531,9 +530,10 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
assertThat(domain.getTransferData().getServerApproveBillingEvent()).isNull();
|
||||
assertThat(domain.getTransferData().getServerApproveAutorenewEvent()).isNull();
|
||||
assertThat(domain.getTransferData().getServerApproveAutorenewPollMessage()).isNull();
|
||||
assertThat(oldTransferData.getServerApproveBillingEvent().get()).isNull();
|
||||
assertThat(oldTransferData.getServerApproveAutorenewEvent().get()).isNull();
|
||||
assertThat(oldTransferData.getServerApproveAutorenewPollMessage().get()).isNull();
|
||||
assertThat(ofy().load().key(oldTransferData.getServerApproveBillingEvent()).now()).isNull();
|
||||
assertThat(ofy().load().key(oldTransferData.getServerApproveAutorenewEvent()).now()).isNull();
|
||||
assertThat(ofy().load().key(oldTransferData.getServerApproveAutorenewPollMessage()).now())
|
||||
.isNull();
|
||||
assertThat(oldTransferData.getServerApproveEntities()).isNotEmpty(); // Just a sanity check.
|
||||
assertThat(ofy().load()
|
||||
.keys(oldTransferData.getServerApproveEntities().toArray(new Key<?>[]{})))
|
||||
|
@ -554,12 +554,12 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
persistResource(loadByUniqueId(
|
||||
DomainResource.class, getUniqueIdFromCommand(), clock.nowUtc())
|
||||
.asBuilder()
|
||||
.setNameservers(ImmutableSet.of(Ref.create(host)))
|
||||
.setNameservers(ImmutableSet.of(Key.create(host)))
|
||||
.build());
|
||||
// Persist another domain that's already been deleted and references this contact and host.
|
||||
persistResource(newDomainResource("example1.tld").asBuilder()
|
||||
.setRegistrant(Ref.create(loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())))
|
||||
.setNameservers(ImmutableSet.of(Ref.create(host)))
|
||||
.setRegistrant(Key.create(loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())))
|
||||
.setNameservers(ImmutableSet.of(Key.create(host)))
|
||||
.setDeletionTime(START_OF_TIME)
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
|
@ -575,7 +575,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
setupSuccessfulTest();
|
||||
persistResource(
|
||||
newHostResource("ns1." + getUniqueIdFromCommand()).asBuilder()
|
||||
.setSuperordinateDomain(Ref.create(reloadResourceByUniqueId()))
|
||||
.setSuperordinateDomain(Key.create(reloadResourceByUniqueId()))
|
||||
.setDeletionTime(clock.nowUtc().minusDays(1))
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
|
@ -607,7 +607,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
|
|||
DomainResource domain = persistActiveDomain(getUniqueIdFromCommand());
|
||||
HostResource subordinateHost = persistResource(
|
||||
newHostResource("ns1." + getUniqueIdFromCommand()).asBuilder()
|
||||
.setSuperordinateDomain(Ref.create(reloadResourceByUniqueId()))
|
||||
.setSuperordinateDomain(Key.create(reloadResourceByUniqueId()))
|
||||
.build());
|
||||
domain = persistResource(domain.asBuilder()
|
||||
.addSubordinateHost(subordinateHost.getFullyQualifiedHostName())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue