mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 20:23:24 +02:00
Make VKey persist to datastore as a key (#591)
* Make VKey persist to datastore as a key Convert nsHosts entirely to VKey as a proof-of-concept. Tested as follows: 1) Deployed to crash, verified that nameservers were visible for several domains (indicating that we are able to load a set of Keys as VKeys) 2) Updated the set of nameservers for a domain (removing some initial hosts) and verified that the changes went through. 3) Deployed the old version to crash, verified that I was able to retrieve the newly saved VKeys as Keys. 4) Modified the hosts for the same domain (adding back one of the hosts) and verified that the change took effect. 5) Redeployed this change to crash, again updated the nameservers to add another host. 6) Again restored the old version, verified that the new hosts were visible. * Changes in response to review * Convert to a single VKeyTranslatorFactory instance * Moved vkey field rename to V25
This commit is contained in:
parent
5fe929b027
commit
579a3d0ac1
9 changed files with 69 additions and 152 deletions
|
@ -28,6 +28,7 @@ import com.googlecode.objectify.annotation.Parent;
|
|||
import com.googlecode.objectify.annotation.Serialize;
|
||||
import com.googlecode.objectify.cmd.Query;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.InjectRule;
|
||||
|
@ -164,7 +165,8 @@ public abstract class EntityTestCase {
|
|||
: (Class<?>) inner;
|
||||
}
|
||||
// Descend into persisted ImmutableObject classes, but not anything else.
|
||||
if (ImmutableObject.class.isAssignableFrom(fieldClass)) {
|
||||
if (ImmutableObject.class.isAssignableFrom(fieldClass)
|
||||
&& !VKey.class.isAssignableFrom(fieldClass)) {
|
||||
getAllPotentiallyIndexedFieldPaths(fieldClass).stream()
|
||||
.map(subfield -> field.getName() + "." + subfield)
|
||||
.distinct()
|
||||
|
|
|
@ -771,60 +771,4 @@ public class DomainBaseTest extends EntityTestCase {
|
|||
assertThat(getOnlyElement(clone.getGracePeriods()).getType())
|
||||
.isEqualTo(GracePeriodStatus.TRANSFER);
|
||||
}
|
||||
|
||||
private static ImmutableSet<Key<HostResource>> getOfyNameservers(DomainBase domain) {
|
||||
return domain.getNameservers().stream().map(key -> key.getOfyKey()).collect(toImmutableSet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameservers_nsHostsOfyKeys() {
|
||||
assertThat(domain.nsHosts).isEqualTo(getOfyNameservers(domain));
|
||||
|
||||
// Test the setNameserver that functions on a function.
|
||||
VKey<HostResource> host1Key =
|
||||
persistResource(
|
||||
new HostResource.Builder()
|
||||
.setFullyQualifiedHostName("ns2.example.com")
|
||||
.setSuperordinateDomain(domainKey)
|
||||
.setRepoId("2-COM")
|
||||
.build())
|
||||
.createKey();
|
||||
|
||||
DomainBase dom = new DomainBase.Builder(domain).setNameservers(host1Key).build();
|
||||
assertThat(dom.getNameservers()).isEqualTo(ImmutableSet.of(host1Key));
|
||||
assertThat(getOfyNameservers(dom)).isEqualTo(ImmutableSet.of(host1Key.getOfyKey()));
|
||||
|
||||
// Test that setting to a single host of null throws an NPE.
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> new DomainBase.Builder(domain).setNameservers((VKey<HostResource>) null));
|
||||
|
||||
// Test that setting to a set of values works.
|
||||
VKey<HostResource> host2Key =
|
||||
persistResource(
|
||||
new HostResource.Builder()
|
||||
.setFullyQualifiedHostName("ns3.example.com")
|
||||
.setSuperordinateDomain(domainKey)
|
||||
.setRepoId("3-COM")
|
||||
.build())
|
||||
.createKey();
|
||||
dom =
|
||||
new DomainBase.Builder(domain).setNameservers(ImmutableSet.of(host1Key, host2Key)).build();
|
||||
assertThat(dom.getNameservers()).isEqualTo(ImmutableSet.of(host1Key, host2Key));
|
||||
assertThat(getOfyNameservers(dom))
|
||||
.isEqualTo(ImmutableSet.of(host1Key.getOfyKey(), host2Key.getOfyKey()));
|
||||
|
||||
// Set of values, passing null.
|
||||
dom =
|
||||
new DomainBase.Builder(domain)
|
||||
.setNameservers((ImmutableSet<VKey<HostResource>>) null)
|
||||
.build();
|
||||
assertThat(dom.nsHostVKeys).isNull();
|
||||
assertThat(dom.nsHosts).isNull();
|
||||
|
||||
// Empty set of values gets translated to null.
|
||||
dom = new DomainBase.Builder(domain).setNameservers(ImmutableSet.of()).build();
|
||||
assertThat(dom.nsHostVKeys).isNull();
|
||||
assertThat(dom.nsHosts).isNull();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,11 +179,11 @@ class google.registry.model.domain.DomainBase {
|
|||
java.lang.String lastEppUpdateClientId;
|
||||
java.lang.String smdId;
|
||||
java.lang.String tld;
|
||||
java.util.Set<com.googlecode.objectify.Key<google.registry.model.host.HostResource>> nsHosts;
|
||||
java.util.Set<google.registry.model.domain.DesignatedContact> allContacts;
|
||||
java.util.Set<google.registry.model.domain.GracePeriod> gracePeriods;
|
||||
java.util.Set<google.registry.model.domain.secdns.DelegationSignerData> dsData;
|
||||
java.util.Set<google.registry.model.eppcommon.StatusValue> status;
|
||||
java.util.Set<google.registry.persistence.VKey<google.registry.model.host.HostResource>> nsHosts;
|
||||
java.util.Set<java.lang.String> subordinateHosts;
|
||||
org.joda.time.DateTime deletionTime;
|
||||
org.joda.time.DateTime lastEppUpdateTime;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue