Ignore test TLDs when logging transaction creates/deletes

The probers make a constant stream of create and delete calls, which we don't
want to account for when constructing transaction reports. This change will
cause only real TLDs to log create and delete transaction records.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166737801
This commit is contained in:
larryruili 2017-08-28 12:08:28 -07:00 committed by Ben McIlwain
parent 16e8286dca
commit c86fd96654
4 changed files with 76 additions and 30 deletions

View file

@ -98,6 +98,7 @@ import google.registry.model.poll.PollMessage;
import google.registry.model.poll.PollMessage.Autorenew;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.Registry.TldType;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
import google.registry.model.reporting.HistoryEntry;
@ -262,7 +263,7 @@ public class DomainCreateFlow implements TransactionalFlow {
String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr());
DateTime registrationExpirationTime = leapSafeAddYears(now, years);
HistoryEntry historyEntry = buildHistoryEntry(
repoId, registry.getTldStr(), now, period, registry.getAddGracePeriodLength());
repoId, registry, now, period, registry.getAddGracePeriodLength());
// Bill for the create.
BillingEvent.OneTime createBillingEvent =
createOneTimeBillingEvent(
@ -365,19 +366,23 @@ public class DomainCreateFlow implements TransactionalFlow {
}
private HistoryEntry buildHistoryEntry(
String repoId, String tld, DateTime now, Period period, Duration addGracePeriod) {
String repoId, Registry registry, DateTime now, Period period, Duration addGracePeriod) {
// We ignore prober transactions
if (registry.getTldType() == TldType.REAL) {
historyBuilder
.setDomainTransactionRecords(
ImmutableSet.of(
DomainTransactionRecord.create(
registry.getTldStr(),
now.plus(addGracePeriod),
TransactionReportField.netAddsFieldFromYears(period.getValue()),
1)));
}
return historyBuilder
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setPeriod(period)
.setModificationTime(now)
.setParent(Key.create(DomainResource.class, repoId))
.setDomainTransactionRecords(
ImmutableSet.of(
DomainTransactionRecord.create(
tld,
now.plus(addGracePeriod),
TransactionReportField.netAddsFieldFromYears(period.getValue()),
1)))
.build();
}

View file

@ -82,6 +82,7 @@ import google.registry.model.poll.PendingActionNotificationResponse.DomainPendin
import google.registry.model.poll.PollMessage;
import google.registry.model.poll.PollMessage.OneTime;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldType;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
import google.registry.model.reporting.HistoryEntry;
@ -239,6 +240,8 @@ public final class DomainDeleteFlow implements TransactionalFlow {
DateTime now,
Duration durationUntilDelete,
boolean inAddGracePeriod) {
// We ignore prober transactions
if (registry.getTldType() == TldType.REAL) {
Duration maxGracePeriod = Collections.max(
ImmutableSet.of(
registry.getAddGracePeriodLength(),
@ -250,10 +253,7 @@ public final class DomainDeleteFlow implements TransactionalFlow {
now,
maxGracePeriod,
Sets.immutableEnumSet(Sets.union(ADD_FIELDS, RENEW_FIELDS)));
return historyBuilder
.setType(HistoryEntry.Type.DOMAIN_DELETE)
.setModificationTime(now)
.setParent(Key.create(existingResource))
historyBuilder
.setDomainTransactionRecords(
union(
cancelledRecords,
@ -263,7 +263,12 @@ public final class DomainDeleteFlow implements TransactionalFlow {
inAddGracePeriod
? TransactionReportField.DELETED_DOMAINS_GRACE
: TransactionReportField.DELETED_DOMAINS_NOGRACE,
1)))
1)));
}
return historyBuilder
.setType(HistoryEntry.Type.DOMAIN_DELETE)
.setModificationTime(now)
.setParent(Key.create(existingResource))
.build();
}

View file

@ -127,6 +127,7 @@ import google.registry.model.eppcommon.StatusValue;
import google.registry.model.poll.PollMessage;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.Registry.TldType;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
import google.registry.model.reporting.HistoryEntry;
@ -2010,6 +2011,17 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
1));
}
@Test
public void testIcannTransactionRecord_testTld_notStored() throws Exception {
persistContactsAndHosts();
persistResource(Registry.get("tld").asBuilder().setTldType(TldType.TEST).build());
runFlow();
DomainResource domain = reloadResourceByForeignKey();
HistoryEntry historyEntry = getHistoryEntries(domain).get(0);
// No transaction records should be stored for test TLDs
assertThat(historyEntry.getDomainTransactionRecords()).isEmpty();
}
@Test
public void testEppMetric_isSuccessfullyCreated() throws Exception {
persistContactsAndHosts();

View file

@ -76,6 +76,7 @@ import google.registry.model.poll.PendingActionNotificationResponse;
import google.registry.model.poll.PollMessage;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.Registry.TldType;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferData;
@ -787,6 +788,29 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
assertTldsFieldLogged("tld");
}
@Test
public void testIcannTransactionRecord_testTld_notStored() throws Exception {
setUpSuccessfulTest();
setUpGracePeriodDurations();
persistResource(Registry.get("tld").asBuilder().setTldType(TldType.TEST).build());
clock.advanceOneMilli();
earlierHistoryEntry =
persistResource(
earlierHistoryEntry
.asBuilder()
.setType(DOMAIN_CREATE)
.setModificationTime(TIME_BEFORE_FLOW.minusDays(2))
.setDomainTransactionRecords(
ImmutableSet.of(
DomainTransactionRecord.create(
"tld", TIME_BEFORE_FLOW.plusDays(1), NET_ADDS_1_YR, 1)))
.build());
runFlow();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE);
// No transaction records should be recorded for test TLDs
assertThat(persistedEntry.getDomainTransactionRecords()).isEmpty();
}
@Test
public void testIcannTransactionRecord_noGrace_entryOutsideMaxGracePeriod() throws Exception {
setUpSuccessfulTest();