mirror of
https://github.com/google/nomulus.git
synced 2025-07-26 04:28:34 +02:00
Use ReplaySpecializer to fix DomainBase replays (#991)
* Use ReplaySpecializer to fix DomainBase replays DomainBase currently has a number of ancillary objects that require a cascading delete that doesn't get propagated. Implement beforeSqlDelete() in DomainContent to delete these child entities. * Remove unnecessary Query variable * Fix rebase error
This commit is contained in:
parent
79b4cb0d82
commit
7b673c90db
8 changed files with 85 additions and 19 deletions
|
@ -24,6 +24,7 @@ import static com.google.common.collect.Sets.intersection;
|
|||
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
|
||||
import static google.registry.model.EppResourceUtils.setAutomaticTransferSuccessProperties;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static google.registry.util.CollectionUtils.forceEmptyToNull;
|
||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
|
@ -378,6 +379,25 @@ public class DomainContent extends EppResource
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to delete grace periods and DelegationSignerData records prior to domain delete.
|
||||
*
|
||||
* <p>See {@link google.registry.schema.replay.ReplaySpecializer}.
|
||||
*/
|
||||
public static void beforeSqlDelete(VKey<DomainBase> key) {
|
||||
// Delete all grace periods associated with the domain.
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("DELETE FROM GracePeriod WHERE domain_repo_id = :repo_id")
|
||||
.setParameter("repo_id", key.getSqlKey())
|
||||
.executeUpdate();
|
||||
jpaTm()
|
||||
.getEntityManager()
|
||||
.createQuery("DELETE FROM DelegationSignerData WHERE domain_repo_id = :repo_id")
|
||||
.setParameter("repo_id", key.getSqlKey())
|
||||
.executeUpdate();
|
||||
}
|
||||
|
||||
public static <T> VKey<T> restoreOfyFrom(Key<DomainBase> domainKey, VKey<T> key, Long historyId) {
|
||||
if (historyId == null) {
|
||||
// This is a legacy key (or a null key, in which case this works too)
|
||||
|
|
|
@ -25,6 +25,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
|||
import static google.registry.testing.DatabaseHelper.assertBillingEventsForResource;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.deleteResource;
|
||||
import static google.registry.testing.DatabaseHelper.getBillingEvents;
|
||||
import static google.registry.testing.DatabaseHelper.getOnlyHistoryEntryOfType;
|
||||
import static google.registry.testing.DatabaseHelper.getOnlyPollMessage;
|
||||
import static google.registry.testing.DatabaseHelper.getPollMessages;
|
||||
|
@ -71,18 +72,25 @@ import google.registry.model.transfer.DomainTransferData;
|
|||
import google.registry.model.transfer.TransferResponse.DomainTransferResponse;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.ReplayExtension;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link DomainTransferApproveFlow}. */
|
||||
class DomainTransferApproveFlowTest
|
||||
extends DomainTransferFlowTestCase<DomainTransferApproveFlow, DomainBase> {
|
||||
|
||||
@Order(value = Order.DEFAULT - 2)
|
||||
@RegisterExtension
|
||||
final ReplayExtension replayExtension = ReplayExtension.createWithCompare(clock);
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
setEppInput("domain_transfer_approve.xml");
|
||||
|
@ -521,7 +529,24 @@ class DomainTransferApproveFlowTest
|
|||
|
||||
@Test
|
||||
void testFailure_nonexistentDomain() throws Exception {
|
||||
deleteResource(domain);
|
||||
Iterable<BillingEvent> billingEvents = getBillingEvents();
|
||||
Iterable<HistoryEntry> historyEntries = tm().loadAllOf(HistoryEntry.class);
|
||||
Iterable<PollMessage> pollMessages = tm().loadAllOf(PollMessage.class);
|
||||
tm().transact(
|
||||
() -> {
|
||||
deleteResource(domain);
|
||||
for (BillingEvent event : billingEvents) {
|
||||
deleteResource(event);
|
||||
}
|
||||
for (PollMessage pollMessage : pollMessages) {
|
||||
deleteResource(pollMessage);
|
||||
}
|
||||
deleteResource(subordinateHost);
|
||||
for (HistoryEntry hist : historyEntries) {
|
||||
deleteResource(hist);
|
||||
}
|
||||
});
|
||||
|
||||
ResourceDoesNotExistException thrown =
|
||||
assertThrows(
|
||||
ResourceDoesNotExistException.class,
|
||||
|
|
|
@ -766,7 +766,7 @@ public class DatabaseHelper {
|
|||
return newRegistrars.build();
|
||||
}
|
||||
|
||||
private static Iterable<BillingEvent> getBillingEvents() {
|
||||
public static Iterable<BillingEvent> getBillingEvents() {
|
||||
return transactIfJpaTm(
|
||||
() ->
|
||||
Iterables.concat(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue