From a1b56b052131ed4384abbadffc275d17b2bf01c4 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Tue, 8 Jun 2021 13:52:13 -0400 Subject: [PATCH] Convert remaining ofy() calls to auditedOfy() (#1200) * Convert remaining ofy() calls to auditedOfy() --- .../registry/model/ofy/ObjectifyService.java | 2 +- .../CreateSyntheticHistoryEntriesAction.java | 4 ++-- .../google/registry/backup/CommitLogExports.java | 16 ++++++++-------- .../model/index/EppResourceIndexTest.java | 14 ++++++++------ .../server/KillAllCommitLogsActionTest.java | 5 +++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/google/registry/model/ofy/ObjectifyService.java b/core/src/main/java/google/registry/model/ofy/ObjectifyService.java index b86106ad4..5878ea54d 100644 --- a/core/src/main/java/google/registry/model/ofy/ObjectifyService.java +++ b/core/src/main/java/google/registry/model/ofy/ObjectifyService.java @@ -51,7 +51,7 @@ import google.registry.model.translators.VKeyTranslatorFactory; import java.util.concurrent.atomic.AtomicLong; /** - * An instance of Ofy, obtained via {@code #ofy()}, should be used to access all persistable + * An instance of Ofy, obtained via {@code #auditedOfy()}, should be used to access all persistable * objects. The class contains a static initializer to call factory().register(...) on all * persistable objects in this package. */ diff --git a/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticHistoryEntriesAction.java b/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticHistoryEntriesAction.java index 18a75225a..1ba24ab33 100644 --- a/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticHistoryEntriesAction.java +++ b/core/src/main/java/google/registry/tools/javascrap/CreateSyntheticHistoryEntriesAction.java @@ -14,7 +14,7 @@ package google.registry.tools.javascrap; -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.tools.mapreduce.Mapper; @@ -111,7 +111,7 @@ public class CreateSyntheticHistoryEntriesAction implements Runnable { public final void map(final Key resourceKey) { tm().transact( () -> { - EppResource eppResource = ofy().load().key(resourceKey).now(); + EppResource eppResource = auditedOfy().load().key(resourceKey).now(); tm().put( HistoryEntry.createBuilderForResource(eppResource) .setClientId(registryAdminRegistrarId) diff --git a/core/src/test/java/google/registry/backup/CommitLogExports.java b/core/src/test/java/google/registry/backup/CommitLogExports.java index b16a1aca7..a01496f30 100644 --- a/core/src/test/java/google/registry/backup/CommitLogExports.java +++ b/core/src/test/java/google/registry/backup/CommitLogExports.java @@ -22,7 +22,7 @@ import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Lists.partition; import static google.registry.backup.BackupUtils.serializeEntity; 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 google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.isAtOrAfter; @@ -80,7 +80,7 @@ public final class CommitLogExports { public static CommitLogCheckpoint computeCheckpoint(Clock clock) { CommitLogCheckpointStrategy strategy = new CommitLogCheckpointStrategy(); strategy.clock = clock; - strategy.ofy = ofy(); + strategy.ofy = auditedOfy(); CommitLogCheckpoint checkpoint = strategy.computeCheckpoint(); tm().transact( @@ -90,7 +90,7 @@ public final class CommitLogExports { checkpoint.getCheckpointTime().isAfter(lastWrittenTime), "Newer checkpoint already written at time: %s", lastWrittenTime); - ofy() + auditedOfy() .saveWithoutBackup() .entities( checkpoint, CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime())); @@ -135,17 +135,17 @@ public final class CommitLogExports { // asynchronously load the entities for the next one. List>> keyChunks = partition(sortedKeys, EXPORT_DIFF_BATCH_SIZE); // Objectify's map return type is asynchronous. Calling .values() will block until it loads. - Map nextChunkToExport = ofy().load().keys(keyChunks.get(0)); + Map nextChunkToExport = auditedOfy().load().keys(keyChunks.get(0)); for (int i = 0; i < keyChunks.size(); i++) { // Force the async load to finish. Collection chunkValues = nextChunkToExport.values(); // Since there is no hard bound on how much data this might be, take care not to let the // Objectify session cache fill up and potentially run out of memory. This is the only safe // point to do this since at this point there is no async load in progress. - ofy().clearSessionCache(); + auditedOfy().clearSessionCache(); // Kick off the next async load, which can happen in parallel to the current GCS export. if (i + 1 < keyChunks.size()) { - nextChunkToExport = ofy().load().keys(keyChunks.get(i + 1)); + nextChunkToExport = auditedOfy().load().keys(keyChunks.get(i + 1)); } exportChunk(commitLogStream, chunkValues); } @@ -205,7 +205,7 @@ public final class CommitLogExports { return ImmutableSet.of(); } Key bucketKey = getBucketKey(bucketNum); - return ofy() + return auditedOfy() .load() .type(CommitLogManifest.class) .ancestor(bucketKey) @@ -222,7 +222,7 @@ public final class CommitLogExports { new ImmutableList.Builder<>(); for (CommitLogManifest manifest : chunk) { entities.add(ImmutableList.of(manifest)); - entities.add(ofy().load().type(CommitLogMutation.class).ancestor(manifest)); + entities.add(auditedOfy().load().type(CommitLogMutation.class).ancestor(manifest)); } for (ImmutableObject entity : concat(entities.build())) { serializeEntity(entity, gcsStream); diff --git a/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java b/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java index f207b0069..48e446930 100644 --- a/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java +++ b/core/src/test/java/google/registry/model/index/EppResourceIndexTest.java @@ -16,7 +16,7 @@ package google.registry.model.index; import static com.google.common.truth.Truth.assertThat; 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 google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.persistActiveContact; import static google.registry.testing.DatabaseHelper.persistResource; @@ -44,7 +44,7 @@ class EppResourceIndexTest extends EntityTestCase { @Test void testPersistence() { EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects()); - assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact); + assertThat(auditedOfy().load().key(loadedIndex.reference).now()).isEqualTo(contact); } @Test @@ -56,7 +56,7 @@ class EppResourceIndexTest extends EntityTestCase { void testIdempotentOnUpdate() { contact = persistResource(contact.asBuilder().setEmailAddress("abc@def.fake").build()); EppResourceIndex loadedIndex = Iterables.getOnlyElement(getEppResourceIndexObjects()); - assertThat(ofy().load().key(loadedIndex.reference).now()).isEqualTo(contact); + assertThat(auditedOfy().load().key(loadedIndex.reference).now()).isEqualTo(contact); } /** @@ -65,9 +65,11 @@ class EppResourceIndexTest extends EntityTestCase { private static ImmutableList getEppResourceIndexObjects() { ImmutableList.Builder indexEntities = new ImmutableList.Builder<>(); for (int i = 0; i < getEppResourceIndexBucketCount(); i++) { - indexEntities.addAll(ofy().load() - .type(EppResourceIndex.class) - .ancestor(Key.create(EppResourceIndexBucket.class, i + 1))); + indexEntities.addAll( + auditedOfy() + .load() + .type(EppResourceIndex.class) + .ancestor(Key.create(EppResourceIndexBucket.class, i + 1))); } return indexEntities.build(); } diff --git a/core/src/test/java/google/registry/tools/server/KillAllCommitLogsActionTest.java b/core/src/test/java/google/registry/tools/server/KillAllCommitLogsActionTest.java index 661898794..082d968a2 100644 --- a/core/src/test/java/google/registry/tools/server/KillAllCommitLogsActionTest.java +++ b/core/src/test/java/google/registry/tools/server/KillAllCommitLogsActionTest.java @@ -21,7 +21,6 @@ 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; import static google.registry.testing.DatabaseHelper.persistResource; @@ -78,7 +77,9 @@ class KillAllCommitLogsActionTest extends MapreduceTestCase clazz : AFFECTED_TYPES) { - assertWithMessage("entities of type " + clazz).that(ofy().load().type(clazz)).isNotEmpty(); + assertWithMessage("entities of type " + clazz) + .that(auditedOfy().load().type(clazz)) + .isNotEmpty(); } ImmutableList otherStuff = Streams.stream(auditedOfy().load())