mirror of
https://github.com/google/nomulus
synced 2026-09-06 16:17:13 +00:00
Convert even more classes to auditedOfy() (#1157)
* Convert even more classes to auditedOfy() This covers almost all of the classes in the second round of the sheet. There are still some classes that need conversion but this is the vast majority of them. https://docs.google.com/spreadsheets/d/1aFEFuyH6vVW6b-h71O9f5CuUc6Y7YjZ2kdRL3lwXcVk/edit?resourcekey=0-guwZVKfSH-pntER1tUit6w#gid=1355213322 for notes
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
package google.registry.backup;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
@@ -63,18 +63,20 @@ public class DeleteOldCommitLogsActionTest
|
||||
action.maxAge = maxAge;
|
||||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce");
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
}
|
||||
|
||||
private void mutateContact(String email) {
|
||||
ofy().clearSessionCache();
|
||||
ContactResource contact = ofy().load()
|
||||
.type(ContactResource.class)
|
||||
.first()
|
||||
.now()
|
||||
.asBuilder()
|
||||
.setEmailAddress(email)
|
||||
.build();
|
||||
auditedOfy().clearSessionCache();
|
||||
ContactResource contact =
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(ContactResource.class)
|
||||
.first()
|
||||
.now()
|
||||
.asBuilder()
|
||||
.setEmailAddress(email)
|
||||
.build();
|
||||
DatabaseHelper.persistResourceWithCommitLog(contact);
|
||||
}
|
||||
|
||||
@@ -85,22 +87,22 @@ public class DeleteOldCommitLogsActionTest
|
||||
String email = String.format("pumpkin_%d@cat.test", i);
|
||||
mutateContact(email);
|
||||
}
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
|
||||
contact = ofy().load().type(ContactResource.class).first().now();
|
||||
contact = auditedOfy().load().type(ContactResource.class).first().now();
|
||||
|
||||
// The following value might change if {@link CommitLogRevisionsTranslatorFactory} changes.
|
||||
assertThat(contact.getRevisions().size()).isEqualTo(6);
|
||||
|
||||
// Before deleting the unneeded manifests - we have 11 of them (one for the first
|
||||
// creation, and 10 more for the mutateContacts)
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).count()).isEqualTo(11);
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).count()).isEqualTo(11);
|
||||
// And each DatabaseHelper.persistResourceWithCommitLog creates 3 mutations
|
||||
assertThat(ofy().load().type(CommitLogMutation.class).count()).isEqualTo(33);
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class).count()).isEqualTo(33);
|
||||
}
|
||||
|
||||
private <T> ImmutableList<T> ofyLoadType(Class<T> clazz) {
|
||||
return ImmutableList.copyOf(ofy().load().type(clazz).iterable());
|
||||
return ImmutableList.copyOf(auditedOfy().load().type(clazz).iterable());
|
||||
}
|
||||
|
||||
/** Check that with very short maxAge, only the referenced elements remain. */
|
||||
@@ -108,7 +110,9 @@ public class DeleteOldCommitLogsActionTest
|
||||
void test_shortMaxAge() throws Exception {
|
||||
runMapreduce(Duration.millis(1));
|
||||
|
||||
assertThat(ImmutableList.copyOf(ofy().load().type(CommitLogManifest.class).keys().iterable()))
|
||||
assertThat(
|
||||
ImmutableList.copyOf(
|
||||
auditedOfy().load().type(CommitLogManifest.class).keys().iterable()))
|
||||
.containsExactlyElementsIn(contact.getRevisions().values());
|
||||
|
||||
// And each DatabaseHelper.persistResourceWithCommitLog creates 3 mutations
|
||||
|
||||
@@ -24,7 +24,7 @@ import static google.registry.backup.BackupUtils.serializeEntity;
|
||||
import static google.registry.backup.ExportCommitLogDiffAction.DIFF_FILE_PREFIX;
|
||||
import static google.registry.model.ofy.CommitLogBucket.getBucketIds;
|
||||
import static google.registry.model.ofy.CommitLogBucket.getBucketKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.appengine.api.datastore.DatastoreServiceFactory;
|
||||
@@ -89,7 +89,7 @@ public class RestoreCommitLogsActionTest {
|
||||
|
||||
@Test
|
||||
void testRestore_multipleDiffFiles() throws Exception {
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.saveWithoutBackup()
|
||||
.entities(TestObject.create("previous to keep"), TestObject.create("previous to delete"))
|
||||
.now();
|
||||
@@ -134,7 +134,7 @@ public class RestoreCommitLogsActionTest {
|
||||
CommitLogMutation.create(manifest2Key, TestObject.create("f")));
|
||||
action.fromTime = now.minusMinutes(1).minusMillis(1);
|
||||
action.run();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertExpectedIds("previous to keep", "b", "d", "e", "f");
|
||||
assertInDatastore(file1CommitLogs);
|
||||
assertInDatastore(file2CommitLogs);
|
||||
@@ -144,11 +144,11 @@ public class RestoreCommitLogsActionTest {
|
||||
|
||||
@Test
|
||||
void testRestore_noManifests() throws Exception {
|
||||
ofy().saveWithoutBackup().entity(TestObject.create("previous to keep")).now();
|
||||
auditedOfy().saveWithoutBackup().entity(TestObject.create("previous to keep")).now();
|
||||
saveDiffFileNotToRestore(gcsService, now.minusMinutes(1));
|
||||
Iterable<ImmutableObject> commitLogs = saveDiffFile(gcsService, createCheckpoint(now));
|
||||
action.run();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertExpectedIds("previous to keep");
|
||||
assertInDatastore(commitLogs);
|
||||
assertInDatastore(CommitLogCheckpointRoot.create(now));
|
||||
@@ -157,7 +157,7 @@ public class RestoreCommitLogsActionTest {
|
||||
|
||||
@Test
|
||||
void testRestore_manifestWithNoDeletions() throws Exception {
|
||||
ofy().saveWithoutBackup().entity(TestObject.create("previous to keep")).now();
|
||||
auditedOfy().saveWithoutBackup().entity(TestObject.create("previous to keep")).now();
|
||||
Key<CommitLogBucket> bucketKey = getBucketKey(1);
|
||||
Key<CommitLogManifest> manifestKey = CommitLogManifest.createKey(bucketKey, now);
|
||||
saveDiffFileNotToRestore(gcsService, now.minusMinutes(1));
|
||||
@@ -169,7 +169,7 @@ public class RestoreCommitLogsActionTest {
|
||||
CommitLogMutation.create(manifestKey, TestObject.create("a")),
|
||||
CommitLogMutation.create(manifestKey, TestObject.create("b")));
|
||||
action.run();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertExpectedIds("previous to keep", "a", "b");
|
||||
assertInDatastore(commitLogs);
|
||||
assertInDatastore(CommitLogCheckpointRoot.create(now));
|
||||
@@ -178,7 +178,7 @@ public class RestoreCommitLogsActionTest {
|
||||
|
||||
@Test
|
||||
void testRestore_manifestWithNoMutations() throws Exception {
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.saveWithoutBackup()
|
||||
.entities(TestObject.create("previous to keep"), TestObject.create("previous to delete"))
|
||||
.now();
|
||||
@@ -192,7 +192,7 @@ public class RestoreCommitLogsActionTest {
|
||||
now,
|
||||
ImmutableSet.of(Key.create(TestObject.create("previous to delete")))));
|
||||
action.run();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertExpectedIds("previous to keep");
|
||||
assertInDatastore(commitLogs);
|
||||
assertInDatastore(CommitLogCheckpointRoot.create(now));
|
||||
@@ -202,7 +202,7 @@ public class RestoreCommitLogsActionTest {
|
||||
// This is a pathological case that shouldn't be possible, but we should be robust to it.
|
||||
@Test
|
||||
void testRestore_manifestWithNoMutationsOrDeletions() throws Exception {
|
||||
ofy().saveWithoutBackup().entities(TestObject.create("previous to keep")).now();
|
||||
auditedOfy().saveWithoutBackup().entities(TestObject.create("previous to keep")).now();
|
||||
saveDiffFileNotToRestore(gcsService, now.minusMinutes(1));
|
||||
Iterable<ImmutableObject> commitLogs =
|
||||
saveDiffFile(
|
||||
@@ -210,7 +210,7 @@ public class RestoreCommitLogsActionTest {
|
||||
createCheckpoint(now),
|
||||
CommitLogManifest.create(getBucketKey(1), now, null));
|
||||
action.run();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertExpectedIds("previous to keep");
|
||||
assertInDatastore(commitLogs);
|
||||
assertInDatastore(CommitLogCheckpointRoot.create(now));
|
||||
@@ -219,7 +219,7 @@ public class RestoreCommitLogsActionTest {
|
||||
|
||||
@Test
|
||||
void testRestore_mutateExistingEntity() throws Exception {
|
||||
ofy().saveWithoutBackup().entity(TestObject.create("existing", "a")).now();
|
||||
auditedOfy().saveWithoutBackup().entity(TestObject.create("existing", "a")).now();
|
||||
Key<CommitLogManifest> manifestKey = CommitLogManifest.createKey(getBucketKey(1), now);
|
||||
saveDiffFileNotToRestore(gcsService, now.minusMinutes(1));
|
||||
Iterable<ImmutableObject> commitLogs =
|
||||
@@ -229,8 +229,9 @@ public class RestoreCommitLogsActionTest {
|
||||
CommitLogManifest.create(getBucketKey(1), now, null),
|
||||
CommitLogMutation.create(manifestKey, TestObject.create("existing", "b")));
|
||||
action.run();
|
||||
ofy().clearSessionCache();
|
||||
assertThat(ofy().load().entity(TestObject.create("existing")).now().getField()).isEqualTo("b");
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(auditedOfy().load().entity(TestObject.create("existing")).now().getField())
|
||||
.isEqualTo("b");
|
||||
assertInDatastore(commitLogs);
|
||||
assertInDatastore(CommitLogCheckpointRoot.create(now));
|
||||
assertCommitLogBuckets(ImmutableMap.of(1, now));
|
||||
@@ -239,7 +240,7 @@ public class RestoreCommitLogsActionTest {
|
||||
// This should be harmless; deletes are idempotent.
|
||||
@Test
|
||||
void testRestore_deleteMissingEntity() throws Exception {
|
||||
ofy().saveWithoutBackup().entity(TestObject.create("previous to keep", "a")).now();
|
||||
auditedOfy().saveWithoutBackup().entity(TestObject.create("previous to keep", "a")).now();
|
||||
saveDiffFileNotToRestore(gcsService, now.minusMinutes(1));
|
||||
Iterable<ImmutableObject> commitLogs =
|
||||
saveDiffFile(
|
||||
@@ -250,7 +251,7 @@ public class RestoreCommitLogsActionTest {
|
||||
now,
|
||||
ImmutableSet.of(Key.create(TestObject.create("previous to delete")))));
|
||||
action.run();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertExpectedIds("previous to keep");
|
||||
assertInDatastore(commitLogs);
|
||||
assertCommitLogBuckets(ImmutableMap.of(1, now));
|
||||
@@ -290,22 +291,24 @@ public class RestoreCommitLogsActionTest {
|
||||
}
|
||||
|
||||
private void assertExpectedIds(String... ids) {
|
||||
assertThat(transform(ofy().load().type(TestObject.class), TestObject::getId))
|
||||
assertThat(transform(auditedOfy().load().type(TestObject.class), TestObject::getId))
|
||||
.containsExactly((Object[]) ids);
|
||||
}
|
||||
|
||||
private void assertInDatastore(ImmutableObject entity) {
|
||||
assertThat(ofy().load().entity(entity).now()).isEqualTo(entity);
|
||||
assertThat(auditedOfy().load().entity(entity).now()).isEqualTo(entity);
|
||||
}
|
||||
|
||||
private void assertInDatastore(Iterable<? extends ImmutableObject> entities) {
|
||||
assertThat(ofy().load().entities(entities).values()).containsExactlyElementsIn(entities);
|
||||
assertThat(auditedOfy().load().entities(entities).values()).containsExactlyElementsIn(entities);
|
||||
}
|
||||
|
||||
private void assertCommitLogBuckets(Map<Integer, DateTime> bucketIdsAndTimestamps) {
|
||||
Map<Long, CommitLogBucket> buckets = ofy().load()
|
||||
.type(CommitLogBucket.class)
|
||||
.ids(Longs.asList(Longs.toArray(CommitLogBucket.getBucketIds())));
|
||||
Map<Long, CommitLogBucket> buckets =
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(CommitLogBucket.class)
|
||||
.ids(Longs.asList(Longs.toArray(CommitLogBucket.getBucketIds())));
|
||||
assertThat(buckets).hasSize(bucketIdsAndTimestamps.size());
|
||||
for (Entry<Integer, DateTime> bucketIdAndTimestamp : bucketIdsAndTimestamps.entrySet()) {
|
||||
assertThat(buckets.get((long) bucketIdAndTimestamp.getKey()).getLastWrittenTime())
|
||||
|
||||
@@ -22,7 +22,7 @@ import static google.registry.batch.AsyncTaskEnqueuer.QUEUE_ASYNC_DELETE;
|
||||
import static google.registry.batch.AsyncTaskMetrics.OperationResult.STALE;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.reporting.HistoryEntry.Type.CONTACT_DELETE;
|
||||
import static google.registry.model.reporting.HistoryEntry.Type.CONTACT_DELETE_FAILURE;
|
||||
import static google.registry.model.reporting.HistoryEntry.Type.CONTACT_TRANSFER_REQUEST;
|
||||
@@ -132,7 +132,7 @@ public class DeleteContactsAndHostsActionTest
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
sleeper.sleep(millis(50));
|
||||
clock.advanceBy(standardSeconds(5));
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
}
|
||||
|
||||
/** Kicks off, but does not run, the mapreduce tasks. Useful for testing validation/setup. */
|
||||
@@ -140,7 +140,7 @@ public class DeleteContactsAndHostsActionTest
|
||||
clock.advanceBy(standardSeconds(5));
|
||||
action.run();
|
||||
clock.advanceBy(standardSeconds(5));
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@@ -258,7 +258,7 @@ public class DeleteContactsAndHostsActionTest
|
||||
false);
|
||||
runMapreduce();
|
||||
assertThat(loadByForeignKey(ContactResource.class, "jim919", clock.nowUtc())).isEmpty();
|
||||
ContactResource contactAfterDeletion = ofy().load().entity(contact).now();
|
||||
ContactResource contactAfterDeletion = auditedOfy().load().entity(contact).now();
|
||||
assertAboutContacts()
|
||||
.that(contactAfterDeletion)
|
||||
.isNotActiveAt(clock.nowUtc())
|
||||
@@ -299,7 +299,7 @@ public class DeleteContactsAndHostsActionTest
|
||||
Trid.create("fakeClientTrid", "fakeServerTrid"),
|
||||
false);
|
||||
runMapreduce();
|
||||
ContactResource contactAfterDeletion = ofy().load().entity(contact).now();
|
||||
ContactResource contactAfterDeletion = auditedOfy().load().entity(contact).now();
|
||||
assertThat(contactAfterDeletion.getTransferData()).isEqualTo(ContactTransferData.EMPTY);
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ public class DeleteContactsAndHostsActionTest
|
||||
true);
|
||||
runMapreduce();
|
||||
assertThat(loadByForeignKey(ContactResource.class, "nate007", clock.nowUtc())).isEmpty();
|
||||
ContactResource contactAfterDeletion = ofy().load().entity(contact).now();
|
||||
ContactResource contactAfterDeletion = auditedOfy().load().entity(contact).now();
|
||||
assertAboutContacts()
|
||||
.that(contactAfterDeletion)
|
||||
.isNotActiveAt(clock.nowUtc())
|
||||
@@ -579,8 +579,8 @@ public class DeleteContactsAndHostsActionTest
|
||||
Trid.create("fakeClientTrid", "fakeServerTrid"),
|
||||
false);
|
||||
enqueueMapreduceOnly();
|
||||
assertThat(ofy().load().entity(contactDeleted).now()).isEqualTo(contactDeleted);
|
||||
assertThat(ofy().load().entity(hostDeleted).now()).isEqualTo(hostDeleted);
|
||||
assertThat(auditedOfy().load().entity(contactDeleted).now()).isEqualTo(contactDeleted);
|
||||
assertThat(auditedOfy().load().entity(hostDeleted).now()).isEqualTo(hostDeleted);
|
||||
assertNoTasksEnqueued(QUEUE_ASYNC_DELETE);
|
||||
assertThat(acquireLock()).isPresent();
|
||||
}
|
||||
@@ -844,12 +844,12 @@ public class DeleteContactsAndHostsActionTest
|
||||
}
|
||||
runMapreduce();
|
||||
for (EppResource resource : ImmutableList.<EppResource>of(c1, c2, c3, h1, h2, h3)) {
|
||||
EppResource loaded = ofy().load().entity(resource).now();
|
||||
EppResource loaded = auditedOfy().load().entity(resource).now();
|
||||
assertThat(loaded.getDeletionTime()).isLessThan(DateTime.now(UTC));
|
||||
assertThat(loaded.getStatusValues()).doesNotContain(PENDING_DELETE);
|
||||
}
|
||||
for (EppResource resource : ImmutableList.<EppResource>of(c4, h4)) {
|
||||
EppResource loaded = ofy().load().entity(resource).now();
|
||||
EppResource loaded = auditedOfy().load().entity(resource).now();
|
||||
assertThat(loaded.getDeletionTime()).isEqualTo(END_OF_TIME);
|
||||
assertThat(loaded.getStatusValues()).doesNotContain(PENDING_DELETE);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package google.registry.batch;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.newDomainBase;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
@@ -195,7 +195,8 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
|
||||
DateTime timeAfterDeletion = DateTime.now(UTC);
|
||||
assertThat(loadByForeignKey(DomainBase.class, "blah.ib-any.test", timeAfterDeletion))
|
||||
.isEmpty();
|
||||
assertThat(ofy().load().entity(domain).now().getDeletionTime()).isLessThan(timeAfterDeletion);
|
||||
assertThat(auditedOfy().load().entity(domain).now().getDeletionTime())
|
||||
.isLessThan(timeAfterDeletion);
|
||||
assertDnsTasksEnqueued("blah.ib-any.test");
|
||||
}
|
||||
|
||||
@@ -212,7 +213,8 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
|
||||
runMapreduce();
|
||||
assertThat(loadByForeignKey(DomainBase.class, "blah.ib-any.test", timeAfterDeletion))
|
||||
.isEmpty();
|
||||
assertThat(ofy().load().entity(domain).now().getDeletionTime()).isLessThan(timeAfterDeletion);
|
||||
assertThat(auditedOfy().load().entity(domain).now().getDeletionTime())
|
||||
.isLessThan(timeAfterDeletion);
|
||||
assertDnsTasksEnqueued("blah.ib-any.test");
|
||||
}
|
||||
|
||||
@@ -239,7 +241,7 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
|
||||
.build());
|
||||
action.isDryRun = true;
|
||||
runMapreduce();
|
||||
assertThat(ofy().load().entity(domain).now().getDeletionTime()).isEqualTo(END_OF_TIME);
|
||||
assertThat(auditedOfy().load().entity(domain).now().getDeletionTime()).isEqualTo(END_OF_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -255,8 +257,8 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
|
||||
.build(),
|
||||
DateTime.now(UTC).minusYears(1));
|
||||
runMapreduce();
|
||||
assertThat(ofy().load().entity(domainWithSubord).now()).isNotNull();
|
||||
assertThat(ofy().load().entity(nakedDomain).now()).isNull();
|
||||
assertThat(auditedOfy().load().entity(domainWithSubord).now()).isNotNull();
|
||||
assertThat(auditedOfy().load().entity(nakedDomain).now()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -303,7 +305,7 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
|
||||
ForeignKeyIndex<DomainBase> fki =
|
||||
ForeignKeyIndex.load(DomainBase.class, fqdn, START_OF_TIME);
|
||||
EppResourceIndex eppIndex =
|
||||
ofy().load().entity(EppResourceIndex.create(Key.create(domain))).now();
|
||||
auditedOfy().load().entity(EppResourceIndex.create(Key.create(domain))).now();
|
||||
return ImmutableSet.of(
|
||||
domain, historyEntry, billingEvent, pollMessage, fki, eppIndex);
|
||||
}
|
||||
@@ -318,13 +320,13 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
|
||||
|
||||
private static void assertNotDeleted(Iterable<ImmutableObject> entities) {
|
||||
for (ImmutableObject entity : entities) {
|
||||
assertThat(ofy().load().entity(entity).now()).isNotNull();
|
||||
assertThat(auditedOfy().load().entity(entity).now()).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertDeleted(Iterable<ImmutableObject> entities) {
|
||||
for (ImmutableObject entity : entities) {
|
||||
assertThat(ofy().load().entity(entity).now()).isNull();
|
||||
assertThat(auditedOfy().load().entity(entity).now()).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ package google.registry.batch;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.common.Cursor.CursorType.RECURRING_BILLING;
|
||||
import static google.registry.model.domain.Period.Unit.YEARS;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_AUTORENEW;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.assertBillingEvents;
|
||||
@@ -108,11 +108,11 @@ public class ExpandRecurringBillingEventsActionTest
|
||||
action.response = new FakeResponse();
|
||||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
}
|
||||
|
||||
private void assertCursorAt(DateTime expectedCursorTime) {
|
||||
Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now();
|
||||
Cursor cursor = auditedOfy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now();
|
||||
assertThat(cursor).isNotNull();
|
||||
assertThat(cursor.getCursorTime()).isEqualTo(expectedCursorTime);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.batch;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatabaseHelper.persistContactWithPendingTransfer;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
@@ -47,11 +47,11 @@ class ResaveAllEppResourcesActionTest extends MapreduceTestCase<ResaveAllEppReso
|
||||
void test_mapreduceSuccessfullyResavesEntity() throws Exception {
|
||||
ContactResource contact = persistActiveContact("test123");
|
||||
DateTime creationTime = contact.getUpdateTimestamp().getTimestamp();
|
||||
assertThat(ofy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
assertThat(auditedOfy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
.isEqualTo(creationTime);
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
runMapreduce();
|
||||
assertThat(ofy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
assertThat(auditedOfy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
.isGreaterThan(creationTime);
|
||||
}
|
||||
|
||||
@@ -59,12 +59,12 @@ class ResaveAllEppResourcesActionTest extends MapreduceTestCase<ResaveAllEppReso
|
||||
void test_fastMode_doesNotResaveEntityWithNoChanges() throws Exception {
|
||||
ContactResource contact = persistActiveContact("test123");
|
||||
DateTime creationTime = contact.getUpdateTimestamp().getTimestamp();
|
||||
assertThat(ofy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
assertThat(auditedOfy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
.isEqualTo(creationTime);
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
action.isFast = true;
|
||||
runMapreduce();
|
||||
assertThat(ofy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
assertThat(auditedOfy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||
.isEqualTo(creationTime);
|
||||
}
|
||||
|
||||
@@ -81,10 +81,10 @@ class ResaveAllEppResourcesActionTest extends MapreduceTestCase<ResaveAllEppReso
|
||||
assertThat(contact.getTransferData().getTransferStatus()).isEqualTo(TransferStatus.PENDING);
|
||||
runMapreduce();
|
||||
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
// The transfer should be effective after the contact is re-saved, as it should've been
|
||||
// projected to the current time.
|
||||
ContactResource resavedContact = ofy().load().entity(contact).now();
|
||||
ContactResource resavedContact = auditedOfy().load().entity(contact).now();
|
||||
assertThat(resavedContact.getTransferData().getTransferStatus())
|
||||
.isEqualTo(TransferStatus.SERVER_APPROVED);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.beam.initsql;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
|
||||
import com.google.appengine.api.datastore.DatastoreService;
|
||||
@@ -76,8 +76,8 @@ public final class BackupTestStore implements AutoCloseable {
|
||||
long timestamp = fakeClock.nowUtc().getMillis();
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().delete().entities(deletes);
|
||||
ofy().save().entities(newOrUpdated);
|
||||
auditedOfy().delete().entities(deletes);
|
||||
auditedOfy().save().entities(newOrUpdated);
|
||||
});
|
||||
fakeClock.advanceOneMilli();
|
||||
return timestamp;
|
||||
@@ -90,7 +90,7 @@ public final class BackupTestStore implements AutoCloseable {
|
||||
@SafeVarargs
|
||||
public final long insertOrUpdate(Object... entities) {
|
||||
long timestamp = fakeClock.nowUtc().getMillis();
|
||||
tm().transact(() -> ofy().save().entities(entities).now());
|
||||
tm().transact(() -> auditedOfy().save().entities(entities).now());
|
||||
fakeClock.advanceOneMilli();
|
||||
return timestamp;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public final class BackupTestStore implements AutoCloseable {
|
||||
@SafeVarargs
|
||||
public final long delete(Object... entities) {
|
||||
long timestamp = fakeClock.nowUtc().getMillis();
|
||||
tm().transact(() -> ofy().delete().entities(entities).now());
|
||||
tm().transact(() -> auditedOfy().delete().entities(entities).now());
|
||||
fakeClock.advanceOneMilli();
|
||||
return timestamp;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public final class BackupTestStore implements AutoCloseable {
|
||||
*/
|
||||
public Object loadAsOfyEntity(Object ofyEntity) {
|
||||
try {
|
||||
return ofy().load().fromEntity(datastoreService.get(Key.create(ofyEntity).getRaw()));
|
||||
return auditedOfy().load().fromEntity(datastoreService.get(Key.create(ofyEntity).getRaw()));
|
||||
} catch (EntityNotFoundException e) {
|
||||
throw new NoSuchElementException(e.getMessage());
|
||||
}
|
||||
@@ -161,10 +161,10 @@ public final class BackupTestStore implements AutoCloseable {
|
||||
private void exportOneKind(File perKindFile, Class<?> pojoType, Set<Key<?>> excludes)
|
||||
throws IOException {
|
||||
LevelDbFileBuilder builder = new LevelDbFileBuilder(perKindFile);
|
||||
for (Object pojo : ofy().load().type(pojoType).iterable()) {
|
||||
for (Object pojo : auditedOfy().load().type(pojoType).iterable()) {
|
||||
if (!excludes.contains(Key.create(pojo))) {
|
||||
try {
|
||||
// Must preserve UpdateTimestamp. Do not use ofy().save().toEntity(pojo)!
|
||||
// Must preserve UpdateTimestamp. Do not use auditedOfy().save().toEntity(pojo)!
|
||||
builder.addEntity(datastoreService.get(Key.create(pojo).getRaw()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.beam.initsql;
|
||||
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.cloneAndSetAutoTimestamps;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
@@ -166,7 +166,7 @@ public class DomainBaseUtilTest {
|
||||
"registrar",
|
||||
null))
|
||||
.build()));
|
||||
domainEntity = tm().transact(() -> ofy().toEntity(domain));
|
||||
domainEntity = tm().transact(() -> auditedOfy().toEntity(domain));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,7 +182,7 @@ public class DomainBaseUtilTest {
|
||||
.setGracePeriods(ImmutableSet.of())
|
||||
.build();
|
||||
DomainBase domainTransformedByUtil =
|
||||
(DomainBase) ofy().toPojo(DomainBaseUtil.removeBillingAndPollAndHosts(domainEntity));
|
||||
(DomainBase) auditedOfy().toPojo(DomainBaseUtil.removeBillingAndPollAndHosts(domainEntity));
|
||||
// Compensates for the missing INACTIVE status.
|
||||
domainTransformedByUtil = domainTransformedByUtil.asBuilder().build();
|
||||
assertAboutImmutableObjects()
|
||||
@@ -202,9 +202,10 @@ public class DomainBaseUtilTest {
|
||||
.setTransferData(null)
|
||||
.setGracePeriods(ImmutableSet.of())
|
||||
.build();
|
||||
Entity entityWithoutFkeys = tm().transact(() -> ofy().toEntity(domainWithoutFKeys));
|
||||
Entity entityWithoutFkeys = tm().transact(() -> auditedOfy().toEntity(domainWithoutFKeys));
|
||||
DomainBase domainTransformedByUtil =
|
||||
(DomainBase) ofy().toPojo(DomainBaseUtil.removeBillingAndPollAndHosts(entityWithoutFkeys));
|
||||
(DomainBase)
|
||||
auditedOfy().toPojo(DomainBaseUtil.removeBillingAndPollAndHosts(entityWithoutFkeys));
|
||||
// Compensates for the missing INACTIVE status.
|
||||
domainTransformedByUtil = domainTransformedByUtil.asBuilder().build();
|
||||
assertAboutImmutableObjects()
|
||||
@@ -215,7 +216,7 @@ public class DomainBaseUtilTest {
|
||||
@Test
|
||||
void removeBillingAndPollAndHosts_notDomainBase() {
|
||||
Entity contactEntity =
|
||||
tm().transact(() -> ofy().toEntity(DatabaseHelper.newContactResource("contact")));
|
||||
tm().transact(() -> auditedOfy().toEntity(DatabaseHelper.newContactResource("contact")));
|
||||
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.beam.initsql;
|
||||
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static org.apache.beam.sdk.values.TypeDescriptors.kvs;
|
||||
import static org.apache.beam.sdk.values.TypeDescriptors.strings;
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class InitSqlTestUtils {
|
||||
|
||||
/** Converts a Datastore {@link Entity} to an Objectify entity. */
|
||||
public static Object datastoreToOfyEntity(Entity entity) {
|
||||
return ofy().load().fromEntity(entity);
|
||||
return auditedOfy().load().fromEntity(entity);
|
||||
}
|
||||
|
||||
/** Serializes a Datastore {@link Entity} to byte array. */
|
||||
|
||||
@@ -16,7 +16,7 @@ package google.registry.flows;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.EppResourceUtils.loadAtPointInTime;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveHost;
|
||||
@@ -95,64 +95,64 @@ class EppCommitLogsTest {
|
||||
clock.setTo(timeAtCreate);
|
||||
eppLoader = new EppLoader(this, "domain_create.xml", ImmutableMap.of("DOMAIN", "example.tld"));
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
Key<DomainBase> key = Key.create(ofy().load().type(DomainBase.class).first().now());
|
||||
DomainBase domainAfterCreate = ofy().load().key(key).now();
|
||||
auditedOfy().clearSessionCache();
|
||||
Key<DomainBase> key = Key.create(auditedOfy().load().type(DomainBase.class).first().now());
|
||||
DomainBase domainAfterCreate = auditedOfy().load().key(key).now();
|
||||
assertThat(domainAfterCreate.getDomainName()).isEqualTo("example.tld");
|
||||
|
||||
clock.advanceBy(standardDays(2));
|
||||
DateTime timeAtFirstUpdate = clock.nowUtc();
|
||||
eppLoader = new EppLoader(this, "domain_update_dsdata_add.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
|
||||
DomainBase domainAfterFirstUpdate = ofy().load().key(key).now();
|
||||
DomainBase domainAfterFirstUpdate = auditedOfy().load().key(key).now();
|
||||
assertThat(domainAfterCreate).isNotEqualTo(domainAfterFirstUpdate);
|
||||
|
||||
clock.advanceOneMilli(); // same day as first update
|
||||
DateTime timeAtSecondUpdate = clock.nowUtc();
|
||||
eppLoader = new EppLoader(this, "domain_update_dsdata_rem.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
DomainBase domainAfterSecondUpdate = ofy().load().key(key).now();
|
||||
auditedOfy().clearSessionCache();
|
||||
DomainBase domainAfterSecondUpdate = auditedOfy().load().key(key).now();
|
||||
|
||||
clock.advanceBy(standardDays(2));
|
||||
DateTime timeAtDelete = clock.nowUtc(); // before 'add' grace period ends
|
||||
eppLoader = new EppLoader(this, "domain_delete.xml", ImmutableMap.of("DOMAIN", "example.tld"));
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
|
||||
assertThat(domainAfterFirstUpdate).isNotEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
// Point-in-time can only rewind an object from the current version, not roll forward.
|
||||
DomainBase latest = ofy().load().key(key).now();
|
||||
DomainBase latest = auditedOfy().load().key(key).now();
|
||||
|
||||
// Creation time has millisecond granularity due to isActive() check.
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.minusMillis(1)).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusMillis(1)).now()).isNotNull();
|
||||
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusDays(1)).now())
|
||||
.isEqualTo(domainAfterCreate);
|
||||
|
||||
// Both updates happened on the same day. Since the revisions field has day granularity, the
|
||||
// key to the first update should have been overwritten by the second, and its timestamp rolled
|
||||
// forward. So we have to fall back to the last revision before midnight.
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtFirstUpdate).now()).isEqualTo(domainAfterCreate);
|
||||
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate).now())
|
||||
.isEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate.plusDays(1)).now())
|
||||
.isEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
// Deletion time has millisecond granularity due to isActive() check.
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.minusMillis(1)).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.plusMillis(1)).now()).isNull();
|
||||
|
||||
@@ -18,7 +18,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
@@ -137,14 +137,14 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
|
||||
}
|
||||
ImmutableList<EppResourceIndex> indices =
|
||||
Streams.stream(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(EppResourceIndex.class)
|
||||
.filter("kind", Key.getKind(resource.getClass())))
|
||||
.filter(
|
||||
index ->
|
||||
Key.create(resource).equals(index.getKey())
|
||||
&& ofy().load().key(index.getKey()).now().equals(resource))
|
||||
&& auditedOfy().load().key(index.getKey()).now().equals(resource))
|
||||
.collect(toImmutableList());
|
||||
assertThat(indices).hasSize(1);
|
||||
assertThat(indices.get(0).getBucket())
|
||||
|
||||
@@ -16,7 +16,7 @@ package google.registry.model;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
@@ -135,7 +135,7 @@ public abstract class EntityTestCase {
|
||||
try {
|
||||
// Objectify happily filters on an unindexed field, and just returns zero results.
|
||||
// Do a query for that value and verify that the expected number of results are returned.
|
||||
Query<?> query = ofy().load().type(obj.getClass());
|
||||
Query<?> query = auditedOfy().load().type(obj.getClass());
|
||||
int results = query.filter(fieldPath, fieldValue).count();
|
||||
assertWithMessage(String.format("%s was %sindexed", fieldPath, indexed ? "not " : ""))
|
||||
.that(indexed)
|
||||
|
||||
@@ -16,7 +16,7 @@ package google.registry.model.billing;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerUtil.ofyTmOrDoNothing;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
@@ -197,21 +197,32 @@ public class BillingEventTest extends EntityTestCase {
|
||||
void testParenting() {
|
||||
// Note that these are all tested separately because BillingEvent is an abstract base class that
|
||||
// lacks the @Entity annotation, and thus we cannot call .type(BillingEvent.class)
|
||||
assertThat(ofy().load().type(BillingEvent.OneTime.class).ancestor(domain).list())
|
||||
assertThat(auditedOfy().load().type(BillingEvent.OneTime.class).ancestor(domain).list())
|
||||
.containsExactly(oneTime, oneTimeSynthetic);
|
||||
assertThat(ofy().load().type(BillingEvent.Recurring.class).ancestor(domain).list())
|
||||
assertThat(auditedOfy().load().type(BillingEvent.Recurring.class).ancestor(domain).list())
|
||||
.containsExactly(recurring);
|
||||
assertThat(ofy().load().type(BillingEvent.Cancellation.class).ancestor(domain).list())
|
||||
assertThat(auditedOfy().load().type(BillingEvent.Cancellation.class).ancestor(domain).list())
|
||||
.containsExactly(cancellationOneTime, cancellationRecurring);
|
||||
assertThat(ofy().load().type(BillingEvent.Modification.class).ancestor(domain).list())
|
||||
assertThat(auditedOfy().load().type(BillingEvent.Modification.class).ancestor(domain).list())
|
||||
.containsExactly(modification);
|
||||
assertThat(ofy().load().type(BillingEvent.OneTime.class).ancestor(domainHistory).list())
|
||||
assertThat(auditedOfy().load().type(BillingEvent.OneTime.class).ancestor(domainHistory).list())
|
||||
.containsExactly(oneTime, oneTimeSynthetic);
|
||||
assertThat(ofy().load().type(BillingEvent.Recurring.class).ancestor(domainHistory).list())
|
||||
assertThat(
|
||||
auditedOfy().load().type(BillingEvent.Recurring.class).ancestor(domainHistory).list())
|
||||
.containsExactly(recurring);
|
||||
assertThat(ofy().load().type(BillingEvent.Cancellation.class).ancestor(domainHistory2).list())
|
||||
assertThat(
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(BillingEvent.Cancellation.class)
|
||||
.ancestor(domainHistory2)
|
||||
.list())
|
||||
.containsExactly(cancellationOneTime, cancellationRecurring);
|
||||
assertThat(ofy().load().type(BillingEvent.Modification.class).ancestor(domainHistory2).list())
|
||||
assertThat(
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(BillingEvent.Modification.class)
|
||||
.ancestor(domainHistory2)
|
||||
.list())
|
||||
.containsExactly(modification);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
@@ -32,7 +32,7 @@ public class GaeUserIdConverterTest {
|
||||
|
||||
@AfterEach
|
||||
void verifyNoLingeringEntities() {
|
||||
assertThat(ofy().load().type(GaeUserIdConverter.class).count()).isEqualTo(0);
|
||||
assertThat(ofyTm().loadAllOf(GaeUserIdConverter.class)).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,8 +43,7 @@ public class GaeUserIdConverterTest {
|
||||
|
||||
@Test
|
||||
void testSuccess_inTransaction() {
|
||||
tm()
|
||||
.transactNew(
|
||||
tm().transactNew(
|
||||
() ->
|
||||
assertThat(GaeUserIdConverter.convertEmailAddressToGaeUserId("example@example.com"))
|
||||
.matches("[0-9]+"));
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.model.ofy;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
|
||||
@@ -86,6 +86,6 @@ public class CommitLogMutationTest {
|
||||
}
|
||||
|
||||
private static Entity convertToEntityInTxn(final ImmutableObject object) {
|
||||
return tm().transact(() -> ofy().save().toEntity(object));
|
||||
return tm().transact(() -> auditedOfy().save().toEntity(object));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import static com.google.appengine.api.datastore.EntityTranslator.convertToPb;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||
import static google.registry.model.ofy.CommitLogBucket.getBucketKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@@ -61,94 +61,96 @@ public class OfyCommitLogTest {
|
||||
@Test
|
||||
void testTransact_doesNothing_noCommitLogIsSaved() {
|
||||
tm().transact(() -> {});
|
||||
assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransact_savesDataAndCommitLog() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
assertThat(auditedOfy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||
.isEqualTo("value");
|
||||
assertThat(ofy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(ofy().load().type(CommitLogMutation.class)).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class)).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransact_saveWithoutBackup_noCommitLogIsSaved() {
|
||||
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||
tm().transact(
|
||||
() -> auditedOfy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||
assertThat(auditedOfy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||
.isEqualTo("value");
|
||||
assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty();
|
||||
assertThat(ofy().load().type(CommitLogMutation.class)).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class)).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransact_deleteWithoutBackup_noCommitLogIsSaved() {
|
||||
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||
tm().transact(() -> ofy().deleteWithoutBackup().key(Key.create(Root.class, 1)));
|
||||
assertThat(ofy().load().key(Key.create(Root.class, 1)).now()).isNull();
|
||||
assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty();
|
||||
assertThat(ofy().load().type(CommitLogMutation.class)).isEmpty();
|
||||
tm().transact(
|
||||
() -> auditedOfy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||
tm().transact(() -> auditedOfy().deleteWithoutBackup().key(Key.create(Root.class, 1)));
|
||||
assertThat(auditedOfy().load().key(Key.create(Root.class, 1)).now()).isNull();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class)).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransact_savesEntity_itsProtobufFormIsStoredInCommitLog() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
final byte[] entityProtoBytes =
|
||||
ofy().load().type(CommitLogMutation.class).first().now().entityProtoBytes;
|
||||
// This transaction is needed so that save().toEntity() can access ofy().getTransactionTime()
|
||||
auditedOfy().load().type(CommitLogMutation.class).first().now().entityProtoBytes;
|
||||
// This transaction is needed so that save().toEntity() can access
|
||||
// auditedOfy().getTransactionTime()
|
||||
// when it attempts to set the update timestamp.
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() ->
|
||||
assertThat(entityProtoBytes)
|
||||
.isEqualTo(
|
||||
convertToPb(ofy().save().toEntity(Root.create(1, getCrossTldKey())))
|
||||
convertToPb(auditedOfy().save().toEntity(Root.create(1, getCrossTldKey())))
|
||||
.toByteArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransact_savesEntity_mutationIsChildOfManifest() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(CommitLogMutation.class)
|
||||
.ancestor(ofy().load().type(CommitLogManifest.class).first().now()))
|
||||
.ancestor(auditedOfy().load().type(CommitLogManifest.class).first().now()))
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransactNew_savesDataAndCommitLog() {
|
||||
tm().transactNew(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||
tm().transactNew(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())).now());
|
||||
assertThat(auditedOfy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value)
|
||||
.isEqualTo("value");
|
||||
assertThat(ofy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(ofy().load().type(CommitLogMutation.class)).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class)).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransact_multipleSaves_logsMultipleMutations() {
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey())).now();
|
||||
ofy().save().entity(Root.create(2, getCrossTldKey())).now();
|
||||
auditedOfy().save().entity(Root.create(1, getCrossTldKey())).now();
|
||||
auditedOfy().save().entity(Root.create(2, getCrossTldKey())).now();
|
||||
});
|
||||
assertThat(ofy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(ofy().load().type(CommitLogMutation.class)).hasSize(2);
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransact_deletion_deletesAndLogsWithoutMutation() {
|
||||
tm().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||
tm().transact(
|
||||
() -> auditedOfy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now());
|
||||
clock.advanceOneMilli();
|
||||
final Key<Root> otherTldKey = Key.create(getCrossTldKey(), Root.class, 1);
|
||||
tm().transact(() -> ofy().delete().key(otherTldKey));
|
||||
assertThat(ofy().load().key(otherTldKey).now()).isNull();
|
||||
assertThat(ofy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(ofy().load().type(CommitLogMutation.class)).isEmpty();
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).first().now().getDeletions())
|
||||
tm().transact(() -> auditedOfy().delete().key(otherTldKey));
|
||||
assertThat(auditedOfy().load().key(otherTldKey).now()).isNull();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class)).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class)).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).first().now().getDeletions())
|
||||
.containsExactly(otherTldKey);
|
||||
}
|
||||
|
||||
@@ -159,7 +161,7 @@ public class OfyCommitLogTest {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> tm().transactNew(() -> ofy().delete().entity(backupsArentAllowedOnMe)));
|
||||
() -> tm().transactNew(() -> auditedOfy().delete().entity(backupsArentAllowedOnMe)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @NotBackedUp");
|
||||
}
|
||||
|
||||
@@ -170,7 +172,7 @@ public class OfyCommitLogTest {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> tm().transactNew(() -> ofy().save().entity(backupsArentAllowedOnMe)));
|
||||
() -> tm().transactNew(() -> auditedOfy().save().entity(backupsArentAllowedOnMe)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @NotBackedUp");
|
||||
}
|
||||
|
||||
@@ -180,7 +182,7 @@ public class OfyCommitLogTest {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> tm().transactNew(() -> ofy().delete().key(virtualEntityKey)));
|
||||
() -> tm().transactNew(() -> auditedOfy().delete().key(virtualEntityKey)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@@ -190,7 +192,7 @@ public class OfyCommitLogTest {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> tm().transactNew(() -> ofy().save().entity(virtualEntity)));
|
||||
() -> tm().transactNew(() -> auditedOfy().save().entity(virtualEntity)));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@@ -200,7 +202,7 @@ public class OfyCommitLogTest {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ofy().deleteWithoutBackup().key(virtualEntityKey));
|
||||
() -> auditedOfy().deleteWithoutBackup().key(virtualEntityKey));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@@ -209,7 +211,8 @@ public class OfyCommitLogTest {
|
||||
final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual");
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> ofy().saveWithoutBackup().entity(virtualEntity));
|
||||
IllegalArgumentException.class,
|
||||
() -> auditedOfy().saveWithoutBackup().entity(virtualEntity));
|
||||
assertThat(thrown).hasMessageThat().contains("Can't save/delete a @VirtualEntity");
|
||||
}
|
||||
|
||||
@@ -219,11 +222,10 @@ public class OfyCommitLogTest {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
auditedOfy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
auditedOfy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
@@ -234,21 +236,20 @@ public class OfyCommitLogTest {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().delete().entity(Root.create(1, getCrossTldKey()));
|
||||
auditedOfy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
auditedOfy().delete().entity(Root.create(1, getCrossTldKey()));
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSavingRootAndChild_updatesTimestampOnBackupGroupRoot() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
ofy().clearSessionCache();
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -256,15 +257,14 @@ public class OfyCommitLogTest {
|
||||
.getTimestamp())
|
||||
.isEqualTo(clock.nowUtc());
|
||||
clock.advanceOneMilli();
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().save().entity(new Child());
|
||||
auditedOfy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
auditedOfy().save().entity(new Child());
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -275,10 +275,10 @@ public class OfyCommitLogTest {
|
||||
|
||||
@Test
|
||||
void testSavingOnlyChild_updatesTimestampOnBackupGroupRoot() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
ofy().clearSessionCache();
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -286,10 +286,10 @@ public class OfyCommitLogTest {
|
||||
.getTimestamp())
|
||||
.isEqualTo(clock.nowUtc());
|
||||
clock.advanceOneMilli();
|
||||
tm().transact(() -> ofy().save().entity(new Child()));
|
||||
ofy().clearSessionCache();
|
||||
tm().transact(() -> auditedOfy().save().entity(new Child()));
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -300,10 +300,10 @@ public class OfyCommitLogTest {
|
||||
|
||||
@Test
|
||||
void testDeletingChild_updatesTimestampOnBackupGroupRoot() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
ofy().clearSessionCache();
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -312,10 +312,10 @@ public class OfyCommitLogTest {
|
||||
.isEqualTo(clock.nowUtc());
|
||||
clock.advanceOneMilli();
|
||||
// The fact that the child was never persisted is irrelevant.
|
||||
tm().transact(() -> ofy().delete().entity(new Child()));
|
||||
ofy().clearSessionCache();
|
||||
tm().transact(() -> auditedOfy().delete().entity(new Child()));
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -326,10 +326,10 @@ public class OfyCommitLogTest {
|
||||
|
||||
@Test
|
||||
void testReadingRoot_doesntUpdateTimestamp() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
ofy().clearSessionCache();
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -337,17 +337,16 @@ public class OfyCommitLogTest {
|
||||
.getTimestamp())
|
||||
.isEqualTo(clock.nowUtc());
|
||||
clock.advanceOneMilli();
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
// Don't remove this line, as without saving *something* the commit log code will
|
||||
// never be invoked and the test will trivially pass.
|
||||
ofy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
ofy().load().entity(Root.create(1, getCrossTldKey()));
|
||||
auditedOfy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
auditedOfy().load().entity(Root.create(1, getCrossTldKey()));
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -358,10 +357,10 @@ public class OfyCommitLogTest {
|
||||
|
||||
@Test
|
||||
void testReadingChild_doesntUpdateTimestampOnBackupGroupRoot() {
|
||||
tm().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
ofy().clearSessionCache();
|
||||
tm().transact(() -> auditedOfy().save().entity(Root.create(1, getCrossTldKey())));
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -369,17 +368,16 @@ public class OfyCommitLogTest {
|
||||
.getTimestamp())
|
||||
.isEqualTo(clock.nowUtc());
|
||||
clock.advanceOneMilli();
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
// Don't remove this line, as without saving *something* the commit log code will
|
||||
// never be invoked and the test will trivially pass
|
||||
ofy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
ofy().load().entity(new Child()); // All Child objects are under Root(1).
|
||||
auditedOfy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
auditedOfy().load().entity(new Child()); // All Child objects are under Root(1).
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -391,17 +389,16 @@ public class OfyCommitLogTest {
|
||||
@Test
|
||||
void testSavingAcrossBackupGroupRoots_updatesCorrectTimestamps() {
|
||||
// Create three roots.
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
ofy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
ofy().save().entity(Root.create(3, getCrossTldKey()));
|
||||
auditedOfy().save().entity(Root.create(1, getCrossTldKey()));
|
||||
auditedOfy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
auditedOfy().save().entity(Root.create(3, getCrossTldKey()));
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, i))
|
||||
.now()
|
||||
@@ -411,16 +408,15 @@ public class OfyCommitLogTest {
|
||||
}
|
||||
clock.advanceOneMilli();
|
||||
// Mutate one root, and a child of a second, ignoring the third.
|
||||
tm()
|
||||
.transact(
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(new Child()); // All Child objects are under Root(1).
|
||||
ofy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
auditedOfy().save().entity(new Child()); // All Child objects are under Root(1).
|
||||
auditedOfy().save().entity(Root.create(2, getCrossTldKey()));
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
// Child was touched.
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 1))
|
||||
.now()
|
||||
@@ -429,7 +425,7 @@ public class OfyCommitLogTest {
|
||||
.isEqualTo(clock.nowUtc());
|
||||
// Directly touched.
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 2))
|
||||
.now()
|
||||
@@ -438,7 +434,7 @@ public class OfyCommitLogTest {
|
||||
.isEqualTo(clock.nowUtc());
|
||||
// Wasn't touched.
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Key.create(getCrossTldKey(), Root.class, 3))
|
||||
.now()
|
||||
|
||||
@@ -18,7 +18,7 @@ import static com.google.appengine.api.datastore.DatastoreServiceFactory.getData
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
|
||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.ofy.Ofy.getBaseEntityClassFromEntityOrKey;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
@@ -82,7 +82,7 @@ public class OfyTest {
|
||||
|
||||
private void doBackupGroupRootTimestampInversionTest(Runnable runnable) {
|
||||
DateTime groupTimestamp =
|
||||
ofy().load().key(someObject.getParent()).now().getUpdateTimestamp().getTimestamp();
|
||||
auditedOfy().load().key(someObject.getParent()).now().getUpdateTimestamp().getTimestamp();
|
||||
// Set the clock in Ofy to the same time as the backup group root's save time.
|
||||
Ofy ofy = new Ofy(new FakeClock(groupTimestamp));
|
||||
TimestampInversionException thrown =
|
||||
@@ -98,12 +98,12 @@ public class OfyTest {
|
||||
|
||||
@Test
|
||||
void testBackupGroupRootTimestampsMustIncreaseOnSave() {
|
||||
doBackupGroupRootTimestampInversionTest(() -> ofy().save().entity(someObject));
|
||||
doBackupGroupRootTimestampInversionTest(() -> auditedOfy().save().entity(someObject));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBackupGroupRootTimestampsMustIncreaseOnDelete() {
|
||||
doBackupGroupRootTimestampInversionTest(() -> ofy().delete().entity(someObject));
|
||||
doBackupGroupRootTimestampInversionTest(() -> auditedOfy().delete().entity(someObject));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,8 +114,8 @@ public class OfyTest {
|
||||
() ->
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
auditedOfy().save().entity(someObject);
|
||||
auditedOfy().save().entity(someObject);
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
@@ -128,8 +128,8 @@ public class OfyTest {
|
||||
() ->
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
auditedOfy().delete().entity(someObject);
|
||||
auditedOfy().delete().entity(someObject);
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
@@ -142,8 +142,8 @@ public class OfyTest {
|
||||
() ->
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().save().entity(someObject);
|
||||
ofy().delete().entity(someObject);
|
||||
auditedOfy().save().entity(someObject);
|
||||
auditedOfy().delete().entity(someObject);
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
@@ -156,8 +156,8 @@ public class OfyTest {
|
||||
() ->
|
||||
tm().transact(
|
||||
() -> {
|
||||
ofy().delete().entity(someObject);
|
||||
ofy().save().entity(someObject);
|
||||
auditedOfy().delete().entity(someObject);
|
||||
auditedOfy().save().entity(someObject);
|
||||
}));
|
||||
assertThat(thrown).hasMessageThat().contains("Multiple entries with same key");
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class OfyTest {
|
||||
void testSavingKeyTwiceInOneCall() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> tm().transact(() -> ofy().save().entities(someObject, someObject)));
|
||||
() -> tm().transact(() -> auditedOfy().save().entities(someObject, someObject)));
|
||||
}
|
||||
|
||||
/** Simple entity class with lifecycle callbacks. */
|
||||
@@ -194,21 +194,21 @@ public class OfyTest {
|
||||
|
||||
@Test
|
||||
void testLifecycleCallbacks_loadFromEntity() {
|
||||
ofy().factory().register(LifecycleObject.class);
|
||||
auditedOfy().factory().register(LifecycleObject.class);
|
||||
LifecycleObject object = new LifecycleObject();
|
||||
Entity entity = ofy().save().toEntity(object);
|
||||
Entity entity = auditedOfy().save().toEntity(object);
|
||||
assertThat(object.onSaveCalled).isTrue();
|
||||
assertThat(ofy().load().<LifecycleObject>fromEntity(entity).onLoadCalled).isTrue();
|
||||
assertThat(auditedOfy().load().<LifecycleObject>fromEntity(entity).onLoadCalled).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLifecycleCallbacks_loadFromDatastore() {
|
||||
ofy().factory().register(LifecycleObject.class);
|
||||
auditedOfy().factory().register(LifecycleObject.class);
|
||||
final LifecycleObject object = new LifecycleObject();
|
||||
tm().transact(() -> ofy().save().entity(object).now());
|
||||
tm().transact(() -> auditedOfy().save().entity(object).now());
|
||||
assertThat(object.onSaveCalled).isTrue();
|
||||
ofy().clearSessionCache();
|
||||
assertThat(ofy().load().entity(object).now().onLoadCalled).isTrue();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(auditedOfy().load().entity(object).now().onLoadCalled).isTrue();
|
||||
}
|
||||
|
||||
/** Avoid regressions of b/21309102 where transaction time did not change on each retry. */
|
||||
@@ -287,7 +287,7 @@ public class OfyTest {
|
||||
public Integer get() {
|
||||
// There will be something in the manifest now, but it won't be committed if
|
||||
// we throw.
|
||||
ofy().save().entity(someObject);
|
||||
auditedOfy().save().entity(someObject);
|
||||
count++;
|
||||
if (count == 3) {
|
||||
return count;
|
||||
@@ -309,7 +309,7 @@ public class OfyTest {
|
||||
public Void get() {
|
||||
if (firstCallToVrun) {
|
||||
firstCallToVrun = false;
|
||||
ofy().save().entity(someObject);
|
||||
auditedOfy().save().entity(someObject);
|
||||
return null;
|
||||
}
|
||||
fail("Shouldn't have retried.");
|
||||
@@ -332,7 +332,7 @@ public class OfyTest {
|
||||
};
|
||||
// Despite the DatastoreTimeoutException in the first call to getResult(), this should succeed
|
||||
// without retrying. If a retry is triggered, the test should fail due to the call to fail().
|
||||
ofy().transactCommitLoggedWork(commitLoggedWork);
|
||||
auditedOfy().transactCommitLoggedWork(commitLoggedWork);
|
||||
}
|
||||
|
||||
void doReadOnlyRetryTest(final RuntimeException e) {
|
||||
@@ -408,23 +408,24 @@ public class OfyTest {
|
||||
|
||||
@Test
|
||||
void test_doWithFreshSessionCache() {
|
||||
ofy().saveWithoutBackup().entity(someObject).now();
|
||||
auditedOfy().saveWithoutBackup().entity(someObject).now();
|
||||
final HistoryEntry modifiedObject =
|
||||
someObject.asBuilder().setModificationTime(END_OF_TIME).build();
|
||||
// Mutate the saved objected, bypassing the Objectify session cache.
|
||||
getDatastoreService().put(ofy().saveWithoutBackup().toEntity(modifiedObject));
|
||||
getDatastoreService().put(auditedOfy().saveWithoutBackup().toEntity(modifiedObject));
|
||||
// Normal loading should come from the session cache and shouldn't reflect the mutation.
|
||||
assertThat(ofy().load().entity(someObject).now()).isEqualTo(someObject);
|
||||
assertThat(auditedOfy().load().entity(someObject).now()).isEqualTo(someObject);
|
||||
// Loading inside doWithFreshSessionCache() should reflect the mutation.
|
||||
boolean ran =
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.doWithFreshSessionCache(
|
||||
() -> {
|
||||
assertThat(ofy().load().entity(someObject).now()).isEqualTo(modifiedObject);
|
||||
assertThat(auditedOfy().load().entity(someObject).now())
|
||||
.isEqualTo(modifiedObject);
|
||||
return true;
|
||||
});
|
||||
assertThat(ran).isTrue();
|
||||
// Test the normal loading again to verify that we've restored the original session unchanged.
|
||||
assertThat(ofy().load().entity(someObject).now()).isEqualTo(someObject);
|
||||
assertThat(auditedOfy().load().entity(someObject).now()).isEqualTo(someObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package google.registry.model.registrar;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.CertificateSamples.SAMPLE_CERT;
|
||||
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2;
|
||||
@@ -569,14 +569,14 @@ class RegistrarTest extends EntityTestCase {
|
||||
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
|
||||
// Load something as a control to make sure we are seeing loaded keys in the
|
||||
// session cache.
|
||||
ofy().load().entity(abuseAdminContact).now();
|
||||
assertThat(ofy().getSessionKeys()).contains(Key.create(abuseAdminContact));
|
||||
assertThat(ofy().getSessionKeys()).doesNotContain(Key.create(registrar));
|
||||
auditedOfy().load().entity(abuseAdminContact).now();
|
||||
assertThat(auditedOfy().getSessionKeys()).contains(Key.create(abuseAdminContact));
|
||||
assertThat(auditedOfy().getSessionKeys()).doesNotContain(Key.create(registrar));
|
||||
});
|
||||
tm().clearSessionCache();
|
||||
// Conversely, loads outside of a transaction should end up in the session cache.
|
||||
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
|
||||
assertThat(ofy().getSessionKeys()).contains(Key.create(registrar));
|
||||
assertThat(auditedOfy().getSessionKeys()).contains(Key.create(registrar));
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
|
||||
+6
-6
@@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static com.google.monitoring.metrics.contrib.DistributionMetricSubject.assertThat;
|
||||
import static com.google.monitoring.metrics.contrib.LongMetricSubject.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.registry.label.DomainLabelMetrics.PremiumListCheckOutcome.BLOOM_FILTER_NEGATIVE;
|
||||
import static google.registry.model.registry.label.DomainLabelMetrics.PremiumListCheckOutcome.CACHED_NEGATIVE;
|
||||
import static google.registry.model.registry.label.DomainLabelMetrics.PremiumListCheckOutcome.CACHED_POSITIVE;
|
||||
@@ -173,10 +173,10 @@ public class PremiumListDatastoreDaoTest {
|
||||
// Remove one of the premium list entries from behind the Bloom filter's back.
|
||||
tm().transactNew(
|
||||
() ->
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.delete()
|
||||
.keys(Key.create(pl.getRevisionKey(), PremiumListEntry.class, "rich")));
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
|
||||
assertThat(PremiumListDatastoreDao.getPremiumPrice("tld", "rich", "tld")).isEmpty();
|
||||
assertThat(PremiumListDatastoreDao.getPremiumPrice("tld", "rich", "tld")).isEmpty();
|
||||
@@ -203,7 +203,7 @@ public class PremiumListDatastoreDaoTest {
|
||||
assertThat(PremiumListDatastoreDao.getPremiumPrice("tld", "dolt", "tld"))
|
||||
.hasValue(Money.parse("JPY 1000"));
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.type(PremiumListEntry.class)
|
||||
.parent(pl.getRevisionKey())
|
||||
@@ -279,7 +279,7 @@ public class PremiumListDatastoreDaoTest {
|
||||
assertThat(entries.keySet()).containsExactly("test");
|
||||
// Save again with no changes, and clear the cache to force a re-load from Datastore.
|
||||
PremiumList resaved = PremiumListDatastoreDao.save("tld", ImmutableList.of("test,USD 1"));
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
Map<String, PremiumListEntry> entriesReloaded =
|
||||
Streams.stream(PremiumListDatastoreDao.loadPremiumListEntriesUncached(resaved))
|
||||
.collect(toImmutableMap(PremiumListEntry::getLabel, Function.identity()));
|
||||
@@ -296,7 +296,7 @@ public class PremiumListDatastoreDaoTest {
|
||||
Key<PremiumListRevision> parent = gtld1.get().getRevisionKey();
|
||||
PremiumListDatastoreDao.delete(gtld1.get());
|
||||
assertThat(PremiumListDatastoreDao.getLatestRevision("gtld1")).isEmpty();
|
||||
assertThat(ofy().load().type(PremiumListEntry.class).ancestor(parent).list()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(PremiumListEntry.class).ancestor(parent).list()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,7 @@ package google.registry.model.tmch;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -54,7 +54,7 @@ public class ClaimsListShardTest {
|
||||
tm().getTransactionTime(), ImmutableMap.of("a", "b"));
|
||||
claimsList.id = 1; // Without an id this won't save anyways.
|
||||
claimsList.parent = ClaimsListRevision.createKey();
|
||||
ofy().saveWithoutBackup().entity(claimsList).now();
|
||||
auditedOfy().saveWithoutBackup().entity(claimsList).now();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ClaimsListShardTest {
|
||||
unsharded.saveToDatastore(shardSize);
|
||||
assertThat(ClaimsListShard.getFromDatastore().get().labelsToKeys)
|
||||
.isEqualTo(unsharded.labelsToKeys);
|
||||
List<ClaimsListShard> shards1 = ofy().load().type(ClaimsListShard.class).list();
|
||||
List<ClaimsListShard> shards1 = auditedOfy().load().type(ClaimsListShard.class).list();
|
||||
assertThat(shards1).hasSize(4);
|
||||
assertThat(ClaimsListShard.getFromDatastore().get().getClaimKey("1")).hasValue("1");
|
||||
assertThat(ClaimsListShard.getFromDatastore().get().getClaimKey("a")).isEmpty();
|
||||
@@ -89,12 +89,12 @@ public class ClaimsListShardTest {
|
||||
}
|
||||
unsharded = ClaimsListShard.create(now.plusDays(1), ImmutableMap.copyOf(labelsToKeys));
|
||||
unsharded.saveToDatastore(shardSize);
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(ClaimsListShard.getFromDatastore().get().labelsToKeys)
|
||||
.hasSize(unsharded.labelsToKeys.size());
|
||||
assertThat(ClaimsListShard.getFromDatastore().get().labelsToKeys)
|
||||
.isEqualTo(unsharded.labelsToKeys);
|
||||
List<ClaimsListShard> shards2 = ofy().load().type(ClaimsListShard.class).list();
|
||||
List<ClaimsListShard> shards2 = auditedOfy().load().type(ClaimsListShard.class).list();
|
||||
assertThat(shards2).hasSize(2);
|
||||
|
||||
// Expect that the old revision is deleted.
|
||||
|
||||
+10
-9
@@ -15,7 +15,7 @@
|
||||
package google.registry.model.translators;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
import static org.joda.time.Duration.standardHours;
|
||||
@@ -65,12 +65,12 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||
}
|
||||
|
||||
private void save(final TestObject object) {
|
||||
tm().transact(() -> ofy().save().entity(object));
|
||||
tm().transact(() -> auditedOfy().save().entity(object));
|
||||
}
|
||||
|
||||
private TestObject reload() {
|
||||
ofy().clearSessionCache();
|
||||
return ofy().load().entity(new TestObject()).now();
|
||||
auditedOfy().clearSessionCache();
|
||||
return auditedOfy().load().entity(new TestObject()).now();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +87,8 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||
TestObject object = reload();
|
||||
assertThat(object.revisions).hasSize(1);
|
||||
assertThat(object.revisions).containsKey(START_TIME);
|
||||
CommitLogManifest commitLogManifest = ofy().load().key(object.revisions.get(START_TIME)).now();
|
||||
CommitLogManifest commitLogManifest =
|
||||
auditedOfy().load().key(object.revisions.get(START_TIME)).now();
|
||||
assertThat(commitLogManifest.getCommitTime()).isEqualTo(START_TIME);
|
||||
}
|
||||
|
||||
@@ -149,7 +150,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||
save(new TestObject());
|
||||
clock.advanceBy(standardDays(1));
|
||||
com.google.appengine.api.datastore.Entity entity =
|
||||
tm().transactNewReadOnly(() -> ofy().save().toEntity(reload()));
|
||||
tm().transactNewReadOnly(() -> auditedOfy().save().toEntity(reload()));
|
||||
assertThat(entity.getProperties().keySet()).containsExactly("revisions.key", "revisions.value");
|
||||
assertThat(entity.getProperties())
|
||||
.containsEntry(
|
||||
@@ -162,16 +163,16 @@ public class CommitLogRevisionsTranslatorFactoryTest {
|
||||
|
||||
@Test
|
||||
void testLoad_neverSaved_returnsNull() {
|
||||
assertThat(ofy().load().entity(new TestObject()).now()).isNull();
|
||||
assertThat(auditedOfy().load().entity(new TestObject()).now()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoad_missingRevisionRawProperties_createsEmptyObject() {
|
||||
com.google.appengine.api.datastore.Entity entity =
|
||||
tm().transactNewReadOnly(() -> ofy().save().toEntity(new TestObject()));
|
||||
tm().transactNewReadOnly(() -> auditedOfy().save().toEntity(new TestObject()));
|
||||
entity.removeProperty("revisions.key");
|
||||
entity.removeProperty("revisions.value");
|
||||
TestObject object = ofy().load().fromEntity(entity);
|
||||
TestObject object = auditedOfy().load().fromEntity(entity);
|
||||
assertThat(object.revisions).isNotNull();
|
||||
assertThat(object.revisions).isEmpty();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.common.Cursor.CursorType.BRDA;
|
||||
import static google.registry.model.common.Cursor.CursorType.RDE_STAGING;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.rde.RdeFixtures.makeContactResource;
|
||||
import static google.registry.rde.RdeFixtures.makeDomainBase;
|
||||
@@ -421,13 +421,18 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(RDE_STAGING, Registry.get("lol")))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("2000-01-02TZ"));
|
||||
assertThat(ofy().load().key(Cursor.createKey(BRDA, Registry.get("lol"))).now().getCursorTime())
|
||||
assertThat(
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(BRDA, Registry.get("lol")))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("2000-01-04TZ"));
|
||||
}
|
||||
|
||||
@@ -442,13 +447,18 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(RDE_STAGING, Registry.get("lol")))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("2000-01-05TZ"));
|
||||
assertThat(ofy().load().key(Cursor.createKey(BRDA, Registry.get("lol"))).now().getCursorTime())
|
||||
assertThat(
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(BRDA, Registry.get("lol")))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("2000-01-11TZ"));
|
||||
}
|
||||
|
||||
@@ -500,11 +510,19 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||
}
|
||||
|
||||
assertThat(
|
||||
ofy().load().key(Cursor.createKey(RDE_STAGING, Registry.get("fop"))).now()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(RDE_STAGING, Registry.get("fop")))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("1971-01-02TZ"));
|
||||
|
||||
assertThat(ofy().load().key(Cursor.createKey(BRDA, Registry.get("fop"))).now().getCursorTime())
|
||||
assertThat(
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(BRDA, Registry.get("fop")))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("1971-01-12TZ"));
|
||||
}
|
||||
|
||||
@@ -702,7 +720,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||
String firstDeposit = readXml("lol_1984-12-18_full_S1_R0.xml.ghostryde");
|
||||
assertThat(firstDeposit).doesNotContain("ns1.justine.lol");
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(RDE_STAGING, Registry.get("lol")))
|
||||
.now()
|
||||
@@ -719,7 +737,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||
assertThat(secondDeposit).doesNotContain("dead:beef::cafe");
|
||||
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(RDE_STAGING, Registry.get("lol")))
|
||||
.now()
|
||||
@@ -735,7 +753,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||
assertThat(thirdDeposit).doesNotContain("feed::a:bee");
|
||||
assertThat(thirdDeposit).contains("dead:beef::cafe");
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(RDE_STAGING, Registry.get("lol")))
|
||||
.now()
|
||||
@@ -782,13 +800,18 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||
"manual/test/" + tld + "_2000-01-02_thin_S1_R" + revision + ".xml.length");
|
||||
|
||||
assertThat(
|
||||
ofy()
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(RDE_STAGING, Registry.get(tld)))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("1999-01-01TZ"));
|
||||
assertThat(ofy().load().key(Cursor.createKey(BRDA, Registry.get(tld))).now().getCursorTime())
|
||||
assertThat(
|
||||
auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(BRDA, Registry.get(tld)))
|
||||
.now()
|
||||
.getCursorTime())
|
||||
.isEqualTo(DateTime.parse("2001-01-01TZ"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.rde;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.rde.RdeMode.FULL;
|
||||
import static google.registry.model.rde.RdeMode.THIN;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
@@ -215,11 +215,15 @@ class RdeStagingReducerTest {
|
||||
}
|
||||
|
||||
private static DateTime loadCursorTime(CursorType type) {
|
||||
return ofy().load().key(Cursor.createKey(type, Registry.get("soy"))).now().getCursorTime();
|
||||
return auditedOfy()
|
||||
.load()
|
||||
.key(Cursor.createKey(type, Registry.get("soy")))
|
||||
.now()
|
||||
.getCursorTime();
|
||||
}
|
||||
|
||||
private static int loadRevision(RdeMode mode) {
|
||||
return ofy()
|
||||
return auditedOfy()
|
||||
.load()
|
||||
.type(RdeRevision.class)
|
||||
.id("soy_2000-01-01_" + mode.getFilenameComponent())
|
||||
|
||||
@@ -17,7 +17,7 @@ package google.registry.testing;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.io.Files.asCharSink;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.persistSimpleResources;
|
||||
import static google.registry.testing.DualDatabaseTestInvocationContextProvider.injectTmForDualDatabaseTest;
|
||||
@@ -410,7 +410,7 @@ public final class AppEngineExtension implements BeforeEachCallback, AfterEachCa
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(START_OF_TIME, PrimaryDatabase.CLOUD_SQL),
|
||||
PrimaryDatabaseTransition.class));
|
||||
tm().transactNew(() -> ofy().saveWithoutBackup().entity(schedule).now());
|
||||
tm().transactNew(() -> auditedOfy().saveWithoutBackup().entity(schedule).now());
|
||||
if (withCloudSql && !withJpaUnitTest && !withoutCannedData) {
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import static google.registry.model.EppResourceUtils.createRepoId;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
|
||||
import static google.registry.model.ResourceTransferUtils.createTransferResponse;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.registry.Registry.TldState.GENERAL_AVAILABILITY;
|
||||
import static google.registry.model.registry.label.PremiumListDatastoreDao.parentPremiumListEntriesOnRevision;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
@@ -1226,7 +1226,9 @@ public class DatabaseHelper {
|
||||
public static <R> R cloneAndSetAutoTimestamps(final R resource) {
|
||||
R result;
|
||||
if (tm().isOfy()) {
|
||||
result = tm().transact(() -> ofy().load().fromEntity(ofy().save().toEntity(resource)));
|
||||
result =
|
||||
tm().transact(
|
||||
() -> auditedOfy().load().fromEntity(auditedOfy().save().toEntity(resource)));
|
||||
} else {
|
||||
// We have to separate the read and write operation into different transactions
|
||||
// otherwise JPA would just return the input entity instead of actually creating a
|
||||
@@ -1263,7 +1265,7 @@ public class DatabaseHelper {
|
||||
*/
|
||||
public static List<Object> loadAllEntities() {
|
||||
if (tm().isOfy()) {
|
||||
return ofy().load().list();
|
||||
return auditedOfy().load().list();
|
||||
} else {
|
||||
return jpaTm()
|
||||
.transact(
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.testing.mapreduce;
|
||||
|
||||
import static google.registry.config.RegistryConfig.getEppResourceIndexBucketCount;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -213,7 +213,7 @@ public abstract class MapreduceTestCase<T> {
|
||||
for (int numTasksDeleted = 0;
|
||||
!maxTasks.isPresent() || (numTasksDeleted < maxTasks.get());
|
||||
numTasksDeleted++) {
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
// We have to re-acquire task list every time, because local implementation returns a copy.
|
||||
List<QueueStateInfo.TaskStateInfo> taskInfo =
|
||||
taskQueue.getQueueStateInfo().get(queueName).getTaskInfo();
|
||||
|
||||
+5
-5
@@ -16,7 +16,7 @@ package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.loadByEntity;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
@@ -176,14 +176,14 @@ class DedupeRecurringBillingEventIdsCommandTest
|
||||
if (newRecurring.getTargetId().equals("foo.tld")) {
|
||||
assertSameRecurringEntityExceptId(newRecurring, recurring1);
|
||||
|
||||
BillingEvent.OneTime persistedOneTime = ofy().load().entity(oneTime).now();
|
||||
BillingEvent.OneTime persistedOneTime = auditedOfy().load().entity(oneTime).now();
|
||||
assertAboutImmutableObjects()
|
||||
.that(persistedOneTime)
|
||||
.isEqualExceptFields(oneTime, "cancellationMatchingBillingEvent");
|
||||
assertThat(persistedOneTime.getCancellationMatchingBillingEvent())
|
||||
.isEqualTo(newRecurring.createVKey());
|
||||
|
||||
DomainBase persistedDomain = ofy().load().entity(domain1).now();
|
||||
DomainBase persistedDomain = auditedOfy().load().entity(domain1).now();
|
||||
assertAboutImmutableObjects()
|
||||
.that(persistedDomain)
|
||||
.isEqualExceptFields(
|
||||
@@ -219,7 +219,7 @@ class DedupeRecurringBillingEventIdsCommandTest
|
||||
|
||||
private static void assertNotInDatastore(ImmutableObject... entities) {
|
||||
for (ImmutableObject entity : entities) {
|
||||
assertThat(ofy().load().entity(entity).now()).isNull();
|
||||
assertThat(auditedOfy().load().entity(entity).now()).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ class DedupeRecurringBillingEventIdsCommandTest
|
||||
}
|
||||
|
||||
private static ImmutableList<BillingEvent.Recurring> loadAllRecurrings() {
|
||||
return ImmutableList.copyOf(ofy().load().type(BillingEvent.Recurring.class));
|
||||
return ImmutableList.copyOf(auditedOfy().load().type(BillingEvent.Recurring.class));
|
||||
}
|
||||
|
||||
private static String getKeyPathLiteral(Object... entities) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
|
||||
import com.google.appengine.api.datastore.Entity;
|
||||
@@ -96,7 +96,7 @@ public class LevelDbFileBuilderTest {
|
||||
LevelDbFileBuilder builder = new LevelDbFileBuilder(logFile);
|
||||
|
||||
ContactResource contact = DatabaseHelper.newContactResource("contact");
|
||||
builder.addEntity(tm().transact(() -> ofy().save().toEntity(contact)));
|
||||
builder.addEntity(tm().transact(() -> auditedOfy().save().toEntity(contact)));
|
||||
builder.build();
|
||||
|
||||
ImmutableList<byte[]> records = ImmutableList.copyOf(LevelDbLogReader.from(logFile.getPath()));
|
||||
@@ -112,6 +112,6 @@ public class LevelDbFileBuilderTest {
|
||||
}
|
||||
|
||||
private static <T> T rawRecordToOfyEntity(byte[] record, Class<T> expectedType) {
|
||||
return expectedType.cast(ofy().load().fromEntity(rawRecordToEntity(record)));
|
||||
return expectedType.cast(auditedOfy().load().fromEntity(rawRecordToEntity(record)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.newDomainBase;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
@@ -62,7 +62,7 @@ public class RemoveRegistryOneKeyCommandTest extends CommandTestCase<RemoveRegis
|
||||
"--key_paths_file",
|
||||
writeToNamedTmpFile("keypath.txt", getKeyPathLiteral(domain)));
|
||||
|
||||
DomainBase persisted = ofy().load().key(domain.createVKey().getOfyKey()).now();
|
||||
DomainBase persisted = auditedOfy().load().key(domain.createVKey().getOfyKey()).now();
|
||||
assertThat(ImmutableList.of(persisted))
|
||||
.comparingElementsUsing(getDomainBaseCorrespondence())
|
||||
.containsExactly(origin);
|
||||
@@ -86,7 +86,7 @@ public class RemoveRegistryOneKeyCommandTest extends CommandTestCase<RemoveRegis
|
||||
"--key_paths_file",
|
||||
writeToNamedTmpFile("keypath.txt", getKeyPathLiteral(domain)));
|
||||
|
||||
DomainBase persisted = ofy().load().key(domain.createVKey().getOfyKey()).now();
|
||||
DomainBase persisted = auditedOfy().load().key(domain.createVKey().getOfyKey()).now();
|
||||
assertThat(ImmutableList.of(persisted))
|
||||
.comparingElementsUsing(getDomainBaseCorrespondence())
|
||||
.containsExactly(origin);
|
||||
|
||||
@@ -16,7 +16,7 @@ package google.registry.tools;
|
||||
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
|
||||
import com.google.appengine.api.datastore.KeyFactory;
|
||||
@@ -35,27 +35,27 @@ class ResaveEntitiesCommandTest extends CommandTestCase<ResaveEntitiesCommand> {
|
||||
ContactResource contact1 = persistActiveContact("contact1");
|
||||
ContactResource contact2 = persistActiveContact("contact2");
|
||||
deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class);
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(ofy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
runCommandForced(
|
||||
KeyFactory.keyToString(Key.create(contact1).getRaw()),
|
||||
KeyFactory.keyToString(Key.create(contact2).getRaw()));
|
||||
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).keys()).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).keys()).hasSize(1);
|
||||
Iterable<ImmutableObject> savedEntities =
|
||||
transform(
|
||||
ofy().load().type(CommitLogMutation.class).list(),
|
||||
mutation -> ofy().load().fromEntity(mutation.getEntity()));
|
||||
auditedOfy().load().type(CommitLogMutation.class).list(),
|
||||
mutation -> auditedOfy().load().fromEntity(mutation.getEntity()));
|
||||
// Reload the contacts before asserting, since their update times will have changed.
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(savedEntities)
|
||||
.containsExactlyElementsIn(ofy().load().entities(contact1, contact2).values());
|
||||
.containsExactlyElementsIn(auditedOfy().load().entities(contact1, contact2).values());
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static void deleteEntitiesOfTypes(Class<? extends ImmutableObject>... types) {
|
||||
for (Class<? extends ImmutableObject> type : types) {
|
||||
ofy().deleteWithoutBackup().keys(ofy().load().type(type).keys()).now();
|
||||
auditedOfy().deleteWithoutBackup().keys(auditedOfy().load().type(type).keys()).now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package google.registry.tools;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.loadRegistrar;
|
||||
|
||||
@@ -44,25 +44,25 @@ class ResaveEnvironmentEntitiesCommandTest
|
||||
CommitLogManifest.class,
|
||||
CommitLogMutation.class);
|
||||
runCommand();
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(ofy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_createsCommitLogs() throws Exception {
|
||||
createTld("tld");
|
||||
deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class);
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(ofy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
runCommand();
|
||||
|
||||
// There are 5 entities that have been re-saved at this point (in 3 transactions, one for each
|
||||
// type), so expect 3 manifests and 5 mutations.
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).keys()).hasSize(3);
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).keys()).hasSize(3);
|
||||
Iterable<ImmutableObject> savedEntities =
|
||||
transform(
|
||||
ofy().load().type(CommitLogMutation.class).list(),
|
||||
mutation -> ofy().load().fromEntity(mutation.getEntity()));
|
||||
auditedOfy().load().type(CommitLogMutation.class).list(),
|
||||
mutation -> auditedOfy().load().fromEntity(mutation.getEntity()));
|
||||
ImmutableSortedSet<RegistrarContact> theRegistrarContacts =
|
||||
loadRegistrar("TheRegistrar").getContacts();
|
||||
assertThat(savedEntities)
|
||||
@@ -79,7 +79,7 @@ class ResaveEnvironmentEntitiesCommandTest
|
||||
@SafeVarargs
|
||||
private static void deleteEntitiesOfTypes(Class<? extends ImmutableObject>... types) {
|
||||
for (Class<? extends ImmutableObject> type : types) {
|
||||
ofy().deleteWithoutBackup().keys(ofy().load().type(type).keys()).now();
|
||||
auditedOfy().deleteWithoutBackup().keys(auditedOfy().load().type(type).keys()).now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
|
||||
import google.registry.model.ImmutableObject;
|
||||
@@ -31,23 +31,23 @@ class ResaveEppResourcesCommandTest extends CommandTestCase<ResaveEppResourceCom
|
||||
void testSuccess_createsCommitLogs() throws Exception {
|
||||
ContactResource contact = persistActiveContact("contact");
|
||||
deleteEntitiesOfTypes(CommitLogManifest.class, CommitLogMutation.class);
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(ofy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).keys()).isEmpty();
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class).keys()).isEmpty();
|
||||
runCommandForced("--type=CONTACT", "--id=contact");
|
||||
|
||||
assertThat(ofy().load().type(CommitLogManifest.class).keys()).hasSize(1);
|
||||
assertThat(ofy().load().type(CommitLogMutation.class).keys()).hasSize(1);
|
||||
CommitLogMutation mutation = ofy().load().type(CommitLogMutation.class).first().now();
|
||||
assertThat(auditedOfy().load().type(CommitLogManifest.class).keys()).hasSize(1);
|
||||
assertThat(auditedOfy().load().type(CommitLogMutation.class).keys()).hasSize(1);
|
||||
CommitLogMutation mutation = auditedOfy().load().type(CommitLogMutation.class).first().now();
|
||||
// Reload the contact before asserting, since its update time will have changed.
|
||||
ofy().clearSessionCache();
|
||||
assertThat(ofy().load().<Object>fromEntity(mutation.getEntity()))
|
||||
.isEqualTo(ofy().load().entity(contact).now());
|
||||
auditedOfy().clearSessionCache();
|
||||
assertThat(auditedOfy().load().<Object>fromEntity(mutation.getEntity()))
|
||||
.isEqualTo(auditedOfy().load().entity(contact).now());
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static void deleteEntitiesOfTypes(Class<? extends ImmutableObject>... types) {
|
||||
for (Class<? extends ImmutableObject> type : types) {
|
||||
ofy().deleteWithoutBackup().keys(ofy().load().type(type).keys()).now();
|
||||
auditedOfy().deleteWithoutBackup().keys(auditedOfy().load().type(type).keys()).now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package google.registry.tools.server;
|
||||
import static com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.googlecode.objectify.Key.create;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.appengine.api.datastore.Entity;
|
||||
@@ -49,7 +49,7 @@ class DeleteEntityActionTest {
|
||||
@Test
|
||||
void test_deleteSingleRegisteredEntitySuccessfully() {
|
||||
ReservedList ofyEntity = new ReservedList.Builder().setName("foo").build();
|
||||
ofy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
auditedOfy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
new DeleteEntityAction(KeyFactory.keyToString(create(ofyEntity).getRaw()), response).run();
|
||||
assertThat(response.getPayload()).isEqualTo("Deleted 0 raw entities and 1 registered entities");
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class DeleteEntityActionTest {
|
||||
getDatastoreService().put(entity);
|
||||
String rawKey = KeyFactory.keyToString(entity.getKey());
|
||||
ReservedList ofyEntity = new ReservedList.Builder().setName("registered").build();
|
||||
ofy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
auditedOfy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
String ofyKey = KeyFactory.keyToString(create(ofyEntity).getRaw());
|
||||
new DeleteEntityAction(String.format("%s,%s", rawKey, ofyKey), response).run();
|
||||
assertThat(response.getPayload()).isEqualTo("Deleted 1 raw entities and 1 registered entities");
|
||||
@@ -88,7 +88,7 @@ class DeleteEntityActionTest {
|
||||
@Test
|
||||
void test_deleteOneEntityAndNonExistentEntityRepliesWithError() {
|
||||
ReservedList ofyEntity = new ReservedList.Builder().setName("first_registered").build();
|
||||
ofy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
auditedOfy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
String ofyKey = KeyFactory.keyToString(create(ofyEntity).getRaw());
|
||||
String rawKey = KeyFactory.keyToString(new Entity("non", "existent").getKey());
|
||||
BadRequestException thrown =
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.newContactResource;
|
||||
@@ -80,16 +81,18 @@ class KillAllCommitLogsActionTest extends MapreduceTestCase<KillAllCommitLogsAct
|
||||
assertWithMessage("entities of type " + clazz).that(ofy().load().type(clazz)).isNotEmpty();
|
||||
}
|
||||
ImmutableList<?> otherStuff =
|
||||
Streams.stream(ofy().load())
|
||||
Streams.stream(auditedOfy().load())
|
||||
.filter(obj -> !AFFECTED_TYPES.contains(obj.getClass()))
|
||||
.collect(toImmutableList());
|
||||
assertThat(otherStuff).isNotEmpty();
|
||||
runMapreduce();
|
||||
for (Class<?> clazz : AFFECTED_TYPES) {
|
||||
assertWithMessage("entities of type " + clazz).that(ofy().load().type(clazz)).isEmpty();
|
||||
assertWithMessage("entities of type " + clazz)
|
||||
.that(auditedOfy().load().type(clazz))
|
||||
.isEmpty();
|
||||
}
|
||||
// Filter out raw Entity objects created by the mapreduce.
|
||||
assertThat(filter(ofy().load(), not(instanceOf(Entity.class))))
|
||||
assertThat(filter(auditedOfy().load(), not(instanceOf(Entity.class))))
|
||||
.containsExactlyElementsIn(otherStuff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.collect.Multimaps.filterKeys;
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
@@ -130,7 +130,7 @@ class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResource
|
||||
assertThat(beforeContents.keySet()).containsAtLeastElementsIn(AFFECTED_KINDS);
|
||||
assertThat(difference(beforeContents.keySet(), AFFECTED_KINDS)).isNotEmpty();
|
||||
runMapreduce();
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
ImmutableMultimap<String, Object> afterContents = getDatastoreContents();
|
||||
assertThat(afterContents.keySet()).containsNoneIn(AFFECTED_KINDS);
|
||||
assertThat(afterContents)
|
||||
@@ -140,7 +140,7 @@ class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResource
|
||||
private ImmutableMultimap<String, Object> getDatastoreContents() {
|
||||
ImmutableMultimap.Builder<String, Object> contentsBuilder = new ImmutableMultimap.Builder<>();
|
||||
// Filter out raw Entity objects created by the mapreduce.
|
||||
for (Object obj : Iterables.filter(ofy().load(), not(instanceOf(Entity.class)))) {
|
||||
for (Object obj : Iterables.filter(auditedOfy().load(), not(instanceOf(Entity.class)))) {
|
||||
contentsBuilder.put(Key.getKind(obj.getClass()), obj);
|
||||
}
|
||||
return contentsBuilder.build();
|
||||
|
||||
+4
-4
@@ -15,7 +15,7 @@
|
||||
package google.registry.tools.server;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
@@ -55,9 +55,9 @@ class ResaveAllHistoryEntriesActionTest extends MapreduceTestCase<ResaveAllHisto
|
||||
DomainBase domain = persistActiveDomain("test.tld");
|
||||
ContactResource contact = persistActiveContact("humanBeing");
|
||||
Entity domainEntry =
|
||||
ofy().save().toEntity(new HistoryEntry.Builder().setParent(domain).build());
|
||||
auditedOfy().save().toEntity(new HistoryEntry.Builder().setParent(domain).build());
|
||||
Entity contactEntry =
|
||||
ofy().save().toEntity(new HistoryEntry.Builder().setParent(contact).build());
|
||||
auditedOfy().save().toEntity(new HistoryEntry.Builder().setParent(contact).build());
|
||||
|
||||
// Set raw properties outside the Objectify schema, which will be deleted upon re-save.
|
||||
domainEntry.setProperty("clientId", "validId");
|
||||
@@ -66,7 +66,7 @@ class ResaveAllHistoryEntriesActionTest extends MapreduceTestCase<ResaveAllHisto
|
||||
contactEntry.setProperty("alsoShouldBeDeleted", "456nah");
|
||||
datastoreService.put(domainEntry);
|
||||
datastoreService.put(contactEntry);
|
||||
ofy().clearSessionCache();
|
||||
auditedOfy().clearSessionCache();
|
||||
runMapreduce();
|
||||
|
||||
Entity updatedDomainEntry = datastoreService.get(domainEntry.getKey());
|
||||
|
||||
Reference in New Issue
Block a user