Add SQL schema for GracePeriodHistory (#746)

* Add schema for GracePeriodHistory

Rebase on HEAD

Rebase on HEAD

Rebase on HEAD and rename column

Use OfyService to generate id

Refactor GracePeriodsSubject

Rebase on HEAD

Remove GracePeriodSubject and GracePeriodsSubject

Rebase on HEAD

Rebase on HEAD

Rebase on HEAD

Add gracePeriodHistoryRevisionId and remove some foreign key

* Rebase on HEAD
This commit is contained in:
Shicong Huang
2020-11-12 10:06:58 -05:00
committed by GitHub
parent 78bc967357
commit de20334a66
23 changed files with 4813 additions and 4091 deletions
@@ -805,7 +805,7 @@ class EppLifecycleDomainTest extends EppTestCase {
// As the losing registrar, read the request poll message, and then ack it.
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
String messageId = "1-C-EXAMPLE-20-26-2001";
String messageId = "1-C-EXAMPLE-18-24-2001";
assertThatCommand("poll.xml")
.atTime("2001-01-01T00:01:00Z")
.hasResponse("poll_response_domain_transfer_request.xml", ImmutableMap.of("ID", messageId));
@@ -814,7 +814,7 @@ class EppLifecycleDomainTest extends EppTestCase {
.hasResponse("poll_ack_response_empty.xml");
// Five days in the future, expect a server approval poll message to the loser, and ack it.
messageId = "1-C-EXAMPLE-20-25-2001";
messageId = "1-C-EXAMPLE-18-23-2001";
assertThatCommand("poll.xml")
.atTime("2001-01-06T00:01:00Z")
.hasResponse(
@@ -826,7 +826,7 @@ class EppLifecycleDomainTest extends EppTestCase {
assertThatLogoutSucceeds();
// Also expect a server approval poll message to the winner, with the transfer request trid.
messageId = "1-C-EXAMPLE-20-24-2001";
messageId = "1-C-EXAMPLE-18-22-2001";
assertThatLoginSucceeds("TheRegistrar", "password2");
assertThatCommand("poll.xml")
.atTime("2001-01-06T00:02:00Z")
@@ -183,7 +183,8 @@ public abstract class FlowTestCase<F extends Flow> {
entry.getKey().getDomainRepoId(),
entry.getKey().getExpirationTime(),
entry.getKey().getClientId(),
null),
null,
1L),
stripBillingEventId(entry.getValue()));
}
return builder.build();
@@ -436,7 +436,8 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
domain.getRepoId(),
clock.nowUtc().plus(Registry.get("tld").getRedemptionGracePeriodLength()),
"TheRegistrar",
null));
null,
resource.getGracePeriods().iterator().next().getGracePeriodId()));
assertDeletionPollMessageFor(resource, "Domain deleted.");
}
@@ -637,7 +638,8 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
domain.getRepoId(),
clock.nowUtc().plus(Registry.get("tld").getRedemptionGracePeriodLength()),
"TheRegistrar",
null));
null,
domain.getGracePeriods().iterator().next().getGracePeriodId()));
// The poll message (in the future) to the losing registrar for implicit ack should be gone.
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).isEmpty();
// The poll message in the future to the gaining registrar should be gone too, but there
@@ -1104,7 +1106,8 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
domain.getRepoId(),
clock.nowUtc().plus(standardDays(15)),
"TheRegistrar",
null));
null,
resource.getGracePeriods().iterator().next().getGracePeriodId()));
assertDeletionPollMessageFor(resource, "Deleted by registry administrator.");
}
@@ -1151,7 +1154,8 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
domain.getRepoId(),
clock.nowUtc().plus(standardDays(15)),
"TheRegistrar",
null));
null,
resource.getGracePeriods().iterator().next().getGracePeriodId()));
assertDeletionPollMessageFor(resource, "Deleted by registry administrator.");
}
@@ -87,8 +87,7 @@ public final class ImmutableObjectSubject extends Subject {
}
}
private static Map<Field, Object> filterFields(
ImmutableObject original, String... ignoredFields) {
public static Map<Field, Object> filterFields(ImmutableObject original, String... ignoredFields) {
ImmutableSet<String> ignoredFieldSet = ImmutableSet.copyOf(ignoredFields);
Map<Field, Object> originalFields = ModelUtils.getFieldValues(original);
// don't use ImmutableMap or a stream->collect model since we can have nulls
@@ -24,7 +24,6 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.fail;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@@ -118,7 +117,8 @@ public class DomainBaseSqlTest {
LaunchNotice.create("tcnid", "validatorId", START_OF_TIME, START_OF_TIME))
.setSmdId("smdid")
.addGracePeriod(
GracePeriod.create(GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null))
GracePeriod.create(
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null, 100L))
.build();
host =
@@ -240,7 +240,12 @@ public class DomainBaseSqlTest {
.asBuilder()
.addGracePeriod(
GracePeriod.create(
GracePeriodStatus.RENEW, "4-COM", END_OF_TIME, "registrar1", null))
GracePeriodStatus.RENEW,
"4-COM",
END_OF_TIME,
"registrar1",
null,
200L))
.build();
jpaTm().put(modified);
});
@@ -249,38 +254,12 @@ public class DomainBaseSqlTest {
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
assertThat(persisted.getGracePeriods().size()).isEqualTo(2);
persisted
.getGracePeriods()
.forEach(
gracePeriod -> {
assertThat(gracePeriod.id).isNotNull();
if (gracePeriod.getType() == GracePeriodStatus.ADD) {
assertAboutImmutableObjects()
.that(gracePeriod)
.isEqualExceptFields(
GracePeriod.create(
GracePeriodStatus.ADD,
"4-COM",
END_OF_TIME,
"registrar1",
null),
"id");
} else if (gracePeriod.getType() == GracePeriodStatus.RENEW) {
assertAboutImmutableObjects()
.that(gracePeriod)
.isEqualExceptFields(
GracePeriod.create(
GracePeriodStatus.RENEW,
"4-COM",
END_OF_TIME,
"registrar1",
null),
"id");
} else {
fail("Unexpected GracePeriod: " + gracePeriod);
}
});
assertThat(persisted.getGracePeriods())
.containsExactly(
GracePeriod.create(
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null, 100L),
GracePeriod.create(
GracePeriodStatus.RENEW, "4-COM", END_OF_TIME, "registrar1", null, 200L));
assertEqualDomainExcept(persisted, "gracePeriods");
});
@@ -327,7 +306,12 @@ public class DomainBaseSqlTest {
.asBuilder()
.addGracePeriod(
GracePeriod.create(
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null))
GracePeriodStatus.ADD,
"4-COM",
END_OF_TIME,
"registrar1",
null,
100L))
.build();
jpaTm().put(modified);
});
@@ -336,13 +320,10 @@ public class DomainBaseSqlTest {
.transact(
() -> {
DomainBase persisted = jpaTm().load(domain.createVKey());
assertThat(persisted.getGracePeriods().size()).isEqualTo(1);
assertAboutImmutableObjects()
.that(persisted.getGracePeriods().iterator().next())
.isEqualExceptFields(
assertThat(persisted.getGracePeriods())
.containsExactly(
GracePeriod.create(
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null),
"id");
GracePeriodStatus.ADD, "4-COM", END_OF_TIME, "registrar1", null, 100L));
assertEqualDomainExcept(persisted, "gracePeriods");
});
}
@@ -413,7 +413,8 @@ public class DomainBaseTest extends EntityTestCase {
.plusDays(1)
.plus(Registry.get("com").getTransferGracePeriodLength()),
"winner",
transferBillingEvent.createVKey()));
transferBillingEvent.createVKey(),
afterTransfer.getGracePeriods().iterator().next().getGracePeriodId()));
// If we project after the grace period expires all should be the same except the grace period.
DomainBase afterGracePeriod =
domain.cloneProjectedAtTime(
@@ -653,7 +654,8 @@ public class DomainBaseTest extends EntityTestCase {
.plusYears(2)
.plus(Registry.get("com").getAutoRenewGracePeriodLength()),
renewedThreeTimes.getCurrentSponsorClientId(),
renewedThreeTimes.autorenewBillingEvent));
renewedThreeTimes.autorenewBillingEvent,
renewedThreeTimes.getGracePeriods().iterator().next().getGracePeriodId()));
}
@Test
@@ -24,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid;
import static google.registry.testing.DatastoreHelper.newDomainBase;
import static google.registry.testing.DatastoreHelper.newHostResourceWithRoid;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableSet;
@@ -33,7 +34,9 @@ import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainContent;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.Period;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostResource;
@@ -55,7 +58,7 @@ public class DomainHistoryTest extends EntityTestCase {
@TestSqlOnly
void testPersistence() {
DomainBase domain = createDomainWithContactsAndHosts();
DomainBase domain = addGracePeriodForSql(createDomainWithContactsAndHosts());
DomainHistory domainHistory = createDomainHistory(domain);
jpaTm().transact(() -> jpaTm().insert(domainHistory));
@@ -70,7 +73,7 @@ public class DomainHistoryTest extends EntityTestCase {
@TestSqlOnly
void testLegacyPersistence_nullResource() {
DomainBase domain = createDomainWithContactsAndHosts();
DomainBase domain = addGracePeriodForSql(createDomainWithContactsAndHosts());
DomainHistory domainHistory =
createDomainHistory(domain).asBuilder().setDomainContent(null).build();
jpaTm().transact(() -> jpaTm().insert(domainHistory));
@@ -146,6 +149,17 @@ public class DomainHistoryTest extends EntityTestCase {
return domain;
}
private static DomainBase addGracePeriodForSql(DomainBase domainBase) {
return domainBase
.asBuilder()
.setGracePeriods(
ImmutableSet.of(
GracePeriod.create(
GracePeriodStatus.ADD, "domainRepoId", END_OF_TIME, "clientId", null)
.cloneWithPrepopulatedId()))
.build();
}
static void assertDomainHistoriesEqual(DomainHistory one, DomainHistory two) {
assertAboutImmutableObjects()
.that(one)
@@ -118,7 +118,12 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
assertAboutImmutableObjects()
.that(legacyHistoryEntry)
.isEqualExceptFields(
fromObjectify, "domainContent", "domainRepoId", "nsHosts", "dsDataHistories");
fromObjectify,
"domainContent",
"domainRepoId",
"nsHosts",
"dsDataHistories",
"gracePeriodHistories");
assertThat(fromObjectify instanceof DomainHistory).isTrue();
DomainHistory legacyDomainHistory = (DomainHistory) fromObjectify;
@@ -136,7 +141,8 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
"domainTransactionRecords",
"otherClientId",
"nsHosts",
"dsDataHistories");
"dsDataHistories",
"gracePeriodHistories");
assertThat(nullToEmpty(legacyDomainHistory.getNsHosts()))
.isEqualTo(nullToEmpty(legacyHistoryFromSql.getNsHosts()));
}
@@ -124,19 +124,19 @@ class DedupeRecurringBillingEventIdsCommandTest
@Test
void testResaveAssociatedDomainAndOneTimeBillingEventCorrectly() throws Exception {
assertThat(recurring1.getId()).isEqualTo(recurring2.getId());
GracePeriod gracePeriod =
GracePeriod.createForRecurring(
GracePeriodStatus.AUTO_RENEW,
domain1.getRepoId(),
now.plusDays(45),
"a registrar",
recurring1.createVKey());
domain1 =
persistResource(
domain1
.asBuilder()
.setAutorenewBillingEvent(recurring1.createVKey())
.setGracePeriods(
ImmutableSet.of(
GracePeriod.createForRecurring(
GracePeriodStatus.AUTO_RENEW,
domain1.getRepoId(),
now.plusDays(45),
"a registrar",
recurring1.createVKey())))
.setGracePeriods(ImmutableSet.of(gracePeriod))
.setTransferData(
new DomainTransferData.Builder()
.setServerApproveAutorenewEvent(recurring1.createVKey())
@@ -201,7 +201,8 @@ class DedupeRecurringBillingEventIdsCommandTest
domain1.getRepoId(),
now.plusDays(45),
"a registrar",
newRecurring.createVKey()));
newRecurring.createVKey(),
gracePeriod.getGracePeriodId()));
assertThat(persistedDomain.getTransferData().getServerApproveAutorenewEvent())
.isEqualTo(newRecurring.createVKey());
assertThat(persistedDomain.getTransferData().getServerApproveEntities())
@@ -108,7 +108,7 @@ class EppLifecycleToolsTest extends EppTestCase {
.atTime("2001-06-08T00:00:00Z")
.hasResponse("poll_response_unrenew.xml");
assertThatCommand("poll_ack.xml", ImmutableMap.of("ID", "1-8-TLD-23-24-2001"))
assertThatCommand("poll_ack.xml", ImmutableMap.of("ID", "1-8-TLD-19-20-2001"))
.atTime("2001-06-08T00:00:01Z")
.hasResponse("poll_ack_response_empty.xml");
@@ -129,7 +129,7 @@ class EppLifecycleToolsTest extends EppTestCase {
.hasResponse(
"poll_response_autorenew.xml",
ImmutableMap.of(
"ID", "1-8-TLD-23-26-2003",
"ID", "1-8-TLD-19-22-2003",
"QDATE", "2003-06-01T00:02:00Z",
"DOMAIN", "example.tld",
"EXDATE", "2004-06-01T00:02:00Z"));
@@ -3,7 +3,7 @@
<result code="1301">
<msg>Command completed successfully; ack to dequeue</msg>
</result>
<msgQ count="1" id="1-8-TLD-23-24-2001">
<msgQ count="1" id="1-8-TLD-19-20-2001">
<qDate>2001-06-07T00:00:00Z</qDate>
<msg>Domain example.tld was unrenewed by 3 years; now expires at 2003-06-01T00:02:00.000Z.</msg>
</msgQ>
@@ -273,6 +273,7 @@ class google.registry.model.domain.DomainHistory {
java.lang.String clientId;
java.lang.String otherClientId;
java.lang.String reason;
java.util.Set<google.registry.model.domain.GracePeriod$GracePeriodHistory> gracePeriodHistories;
java.util.Set<google.registry.model.domain.secdns.DomainDsDataHistory> dsDataHistories;
java.util.Set<google.registry.model.reporting.DomainTransactionRecord> domainTransactionRecords;
org.joda.time.DateTime modificationTime;
@@ -281,6 +282,17 @@ class google.registry.model.domain.GracePeriod {
google.registry.model.domain.rgp.GracePeriodStatus type;
google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$OneTime> billingEventOneTime;
google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$Recurring> billingEventRecurring;
java.lang.Long gracePeriodId;
java.lang.String clientId;
org.joda.time.DateTime expirationTime;
}
class google.registry.model.domain.GracePeriod$GracePeriodHistory {
google.registry.model.domain.rgp.GracePeriodStatus type;
google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$OneTime> billingEventOneTime;
google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$Recurring> billingEventRecurring;
java.lang.Long domainHistoryRevisionId;
java.lang.Long gracePeriodHistoryRevisionId;
java.lang.Long gracePeriodId;
java.lang.String clientId;
org.joda.time.DateTime expirationTime;
}