From cd314bdc75718a64df1bcb64bfb331dd5f91d25a Mon Sep 17 00:00:00 2001 From: mcilwain Date: Fri, 17 Nov 2017 13:38:53 -0800 Subject: [PATCH] Replace many Work and VoidWork usages with lambdas ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=176153460 --- .../backup/CommitLogCheckpointAction.java | 39 +-- .../ExpandRecurringBillingEventsAction.java | 34 ++- .../batch/ResaveAllEppResourcesAction.java | 19 +- .../export/sheet/SyncRegistrarsSheet.java | 9 +- java/google/registry/flows/FlowRunner.java | 29 +- .../registry/keyring/kms/KmsUpdater.java | 28 +- .../model/smd/SignedMarkRevocationList.java | 47 ++-- .../registry/model/tmch/ClaimsListShard.java | 45 ++- java/google/registry/model/tmch/TmchCrl.java | 19 +- .../google/registry/rde/EscrowTaskRunner.java | 9 +- .../registry/rde/RdeStagingReducer.java | 63 +++-- .../tools/CreateLrpTokensCommand.java | 14 +- .../tools/GetAppliedLabelsCommand.java | 38 +-- .../ResaveEnvironmentEntitiesCommand.java | 7 +- .../tools/UpdateApplicationStatusCommand.java | 8 +- .../tools/UpdateClaimsNoticeCommand.java | 19 +- .../registry/tools/UpdateSmdCommand.java | 19 +- .../tools/server/KillAllEntitiesReducer.java | 7 +- .../server/ResaveAllHistoryEntriesAction.java | 7 +- .../registrar/RegistrarSettingsAction.java | 61 ++-- .../CommitLogCheckpointStrategyTest.java | 30 +- ...xpandRecurringBillingEventsActionTest.java | 7 +- .../model/CreateAutoTimestampTest.java | 33 ++- .../model/UpdateAutoTimestampTest.java | 35 +-- .../registry/model/common/CursorTest.java | 37 +-- .../index/DomainApplicationIndexTest.java | 15 +- .../model/ofy/CommitLogMutationTest.java | 14 +- .../registry/model/ofy/OfyCommitLogTest.java | 264 ++++++------------ .../smd/SignedMarkRevocationListTest.java | 18 +- .../model/tmch/ClaimsListShardTest.java | 19 +- ...mmitLogRevisionsTranslatorFactoryTest.java | 7 +- .../rde/PendingDepositCheckerTest.java | 7 +- .../registry/rde/RdeStagingActionTest.java | 7 +- .../registry/rde/RdeUploadActionTest.java | 19 +- .../rde/imports/RdeImportUtilsTest.java | 66 +---- .../google/registry/tmch/LordnTaskTest.java | 24 +- 36 files changed, 443 insertions(+), 680 deletions(-) diff --git a/java/google/registry/backup/CommitLogCheckpointAction.java b/java/google/registry/backup/CommitLogCheckpointAction.java index 5bf6d5def..c2b368692 100644 --- a/java/google/registry/backup/CommitLogCheckpointAction.java +++ b/java/google/registry/backup/CommitLogCheckpointAction.java @@ -22,7 +22,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.DateTimeUtils.isBeforeOrAt; import static google.registry.util.FormattingLogger.getLoggerForCallerClass; -import com.googlecode.objectify.VoidWork; import google.registry.model.ofy.CommitLogCheckpoint; import google.registry.model.ofy.CommitLogCheckpointRoot; import google.registry.request.Action; @@ -64,23 +63,25 @@ public final class CommitLogCheckpointAction implements Runnable { public void run() { final CommitLogCheckpoint checkpoint = strategy.computeCheckpoint(); logger.info("Generated candidate checkpoint for time " + checkpoint.getCheckpointTime()); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - DateTime lastWrittenTime = CommitLogCheckpointRoot.loadRoot().getLastWrittenTime(); - if (isBeforeOrAt(checkpoint.getCheckpointTime(), lastWrittenTime)) { - logger.info("Newer checkpoint already written at time: " + lastWrittenTime); - return; - } - ofy().saveWithoutBackup().entities( - checkpoint, - CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime())); - // Enqueue a diff task between previous and current checkpoints. - taskEnqueuer.enqueue( - getQueue(QUEUE_NAME), - withUrl(ExportCommitLogDiffAction.PATH) - .param(LOWER_CHECKPOINT_TIME_PARAM, lastWrittenTime.toString()) - .param(UPPER_CHECKPOINT_TIME_PARAM, checkpoint.getCheckpointTime().toString())); - }}); + ofy() + .transact( + () -> { + DateTime lastWrittenTime = CommitLogCheckpointRoot.loadRoot().getLastWrittenTime(); + if (isBeforeOrAt(checkpoint.getCheckpointTime(), lastWrittenTime)) { + logger.info("Newer checkpoint already written at time: " + lastWrittenTime); + return; + } + ofy() + .saveWithoutBackup() + .entities( + checkpoint, CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime())); + // Enqueue a diff task between previous and current checkpoints. + taskEnqueuer.enqueue( + getQueue(QUEUE_NAME), + withUrl(ExportCommitLogDiffAction.PATH) + .param(LOWER_CHECKPOINT_TIME_PARAM, lastWrittenTime.toString()) + .param( + UPPER_CHECKPOINT_TIME_PARAM, checkpoint.getCheckpointTime().toString())); + }); } } diff --git a/java/google/registry/batch/ExpandRecurringBillingEventsAction.java b/java/google/registry/batch/ExpandRecurringBillingEventsAction.java index 05be3a677..b5aa3794d 100644 --- a/java/google/registry/batch/ExpandRecurringBillingEventsAction.java +++ b/java/google/registry/batch/ExpandRecurringBillingEventsAction.java @@ -38,7 +38,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Range; import com.google.common.collect.Streams; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.NullInput; @@ -315,23 +314,22 @@ public class ExpandRecurringBillingEventsAction implements Runnable { isDryRun ? "(dry run) " : "", cursorTime, executionTime); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now(); - DateTime currentCursorTime = (cursor == null ? START_OF_TIME : cursor.getCursorTime()); - if (!currentCursorTime.equals(expectedPersistedCursorTime)) { - logger.severefmt( - "Current cursor position %s does not match expected cursor position %s.", - currentCursorTime, - expectedPersistedCursorTime); - return; - } - if (!isDryRun) { - ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, executionTime)); - } - } - }); + ofy() + .transact( + () -> { + Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now(); + DateTime currentCursorTime = + (cursor == null ? START_OF_TIME : cursor.getCursorTime()); + if (!currentCursorTime.equals(expectedPersistedCursorTime)) { + logger.severefmt( + "Current cursor position %s does not match expected cursor position %s.", + currentCursorTime, expectedPersistedCursorTime); + return; + } + if (!isDryRun) { + ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, executionTime)); + } + }); } } } diff --git a/java/google/registry/batch/ResaveAllEppResourcesAction.java b/java/google/registry/batch/ResaveAllEppResourcesAction.java index b2630216a..57f2e5481 100644 --- a/java/google/registry/batch/ResaveAllEppResourcesAction.java +++ b/java/google/registry/batch/ResaveAllEppResourcesAction.java @@ -20,7 +20,6 @@ import static google.registry.util.PipelineUtils.createJobPath; import com.google.appengine.tools.mapreduce.Mapper; import com.google.common.collect.ImmutableList; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.EppResourceInputs; import google.registry.model.EppResource; @@ -70,13 +69,17 @@ public class ResaveAllEppResourcesAction implements Runnable { @Override public final void map(final Key resourceKey) { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - EppResource projectedResource = - ofy().load().key(resourceKey).now().cloneProjectedAtTime(ofy().getTransactionTime()); - ofy().save().entity(projectedResource).now(); - }}); + ofy() + .transact( + () -> { + EppResource projectedResource = + ofy() + .load() + .key(resourceKey) + .now() + .cloneProjectedAtTime(ofy().getTransactionTime()); + ofy().save().entity(projectedResource).now(); + }); getContext().incrementCounter(String.format("%s entities re-saved", resourceKey.getKind())); } } diff --git a/java/google/registry/export/sheet/SyncRegistrarsSheet.java b/java/google/registry/export/sheet/SyncRegistrarsSheet.java index 0dce56976..f7d4a3580 100644 --- a/java/google/registry/export/sheet/SyncRegistrarsSheet.java +++ b/java/google/registry/export/sheet/SyncRegistrarsSheet.java @@ -33,7 +33,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Ordering; -import com.googlecode.objectify.VoidWork; import google.registry.model.common.Cursor; import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarAddress; @@ -153,11 +152,9 @@ class SyncRegistrarsSheet { return builder.build(); }) .collect(toImmutableList())); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.createGlobal(SYNC_REGISTRAR_SHEET, executionTime)); - }}); + ofy() + .transact( + () -> ofy().save().entity(Cursor.createGlobal(SYNC_REGISTRAR_SHEET, executionTime))); } private static String convertContacts( diff --git a/java/google/registry/flows/FlowRunner.java b/java/google/registry/flows/FlowRunner.java index 3e3edbd32..b6530732c 100644 --- a/java/google/registry/flows/FlowRunner.java +++ b/java/google/registry/flows/FlowRunner.java @@ -18,7 +18,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.xml.XmlTransformer.prettyPrint; import com.google.common.base.Strings; -import com.googlecode.objectify.Work; import google.registry.flows.FlowModule.ClientId; import google.registry.flows.FlowModule.DryRun; import google.registry.flows.FlowModule.InputXml; @@ -88,20 +87,20 @@ public class FlowRunner { return eppOutput; } try { - return ofy().transact(new Work() { - @Override - public EppOutput run() { - eppMetricBuilder.incrementAttempts(); - try { - EppOutput output = EppOutput.create(flowProvider.get().run()); - if (isDryRun) { - throw new DryRunException(output); - } - return output; - } catch (EppException e) { - throw new EppRuntimeException(e); - } - }}); + return ofy() + .transact( + () -> { + eppMetricBuilder.incrementAttempts(); + try { + EppOutput output = EppOutput.create(flowProvider.get().run()); + if (isDryRun) { + throw new DryRunException(output); + } + return output; + } catch (EppException e) { + throw new EppRuntimeException(e); + } + }); } catch (DryRunException e) { return e.output; } catch (EppRuntimeException e) { diff --git a/java/google/registry/keyring/kms/KmsUpdater.java b/java/google/registry/keyring/kms/KmsUpdater.java index 2d040a31b..1532b6d76 100644 --- a/java/google/registry/keyring/kms/KmsUpdater.java +++ b/java/google/registry/keyring/kms/KmsUpdater.java @@ -36,7 +36,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import com.google.common.collect.ImmutableMap; -import com.googlecode.objectify.VoidWork; import google.registry.keyring.api.KeySerializer; import google.registry.keyring.kms.KmsKeyring.PrivateKeyLabel; import google.registry.keyring.kms.KmsKeyring.PublicKeyLabel; @@ -186,23 +185,18 @@ public final class KmsUpdater { final ImmutableMap encryptedValues) { ofy() .transact( - new VoidWork() { - @Override - public void vrun() { - for (Map.Entry entry : encryptedValues.entrySet()) { - String secretName = entry.getKey(); - EncryptResponse revisionData = entry.getValue(); + () -> { + for (Map.Entry entry : encryptedValues.entrySet()) { + String secretName = entry.getKey(); + EncryptResponse revisionData = entry.getValue(); - KmsSecretRevision secretRevision = - new KmsSecretRevision.Builder() - .setEncryptedValue(revisionData.ciphertext()) - .setKmsCryptoKeyVersionName(revisionData.cryptoKeyVersionName()) - .setParent(secretName) - .build(); - ofy() - .save() - .entities(secretRevision, KmsSecret.create(secretName, secretRevision)); - } + KmsSecretRevision secretRevision = + new KmsSecretRevision.Builder() + .setEncryptedValue(revisionData.ciphertext()) + .setKmsCryptoKeyVersionName(revisionData.cryptoKeyVersionName()) + .setParent(secretName) + .build(); + ofy().save().entities(secretRevision, KmsSecret.create(secretName, secretRevision)); } }); } diff --git a/java/google/registry/model/smd/SignedMarkRevocationList.java b/java/google/registry/model/smd/SignedMarkRevocationList.java index c4000c3ee..dd36d4ad1 100644 --- a/java/google/registry/model/smd/SignedMarkRevocationList.java +++ b/java/google/registry/model/smd/SignedMarkRevocationList.java @@ -30,7 +30,6 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import com.googlecode.objectify.annotation.EmbedMap; import com.googlecode.objectify.annotation.Entity; @@ -157,31 +156,27 @@ public class SignedMarkRevocationList extends ImmutableObject { public SignedMarkRevocationList save() { ofy() .transact( - new VoidWork() { - @Override - public void vrun() { - ofy() - .deleteWithoutBackup() - .keys( - ofy() - .load() - .type(SignedMarkRevocationList.class) - .ancestor(getCrossTldKey()) - .keys()); - ofy() - .saveWithoutBackup() - .entities( - FluentIterable.from(CollectionUtils.partitionMap(revokes, SHARD_SIZE)) - .transform( - (ImmutableMap shardRevokes) -> { - SignedMarkRevocationList shard = - create(creationTime, shardRevokes); - shard.id = allocateId(); - shard.isShard = - true; // Avoid the exception in disallowUnshardedSaves(). - return shard; - })); - } + () -> { + ofy() + .deleteWithoutBackup() + .keys( + ofy() + .load() + .type(SignedMarkRevocationList.class) + .ancestor(getCrossTldKey()) + .keys()); + ofy() + .saveWithoutBackup() + .entities( + FluentIterable.from(CollectionUtils.partitionMap(revokes, SHARD_SIZE)) + .transform( + (ImmutableMap shardRevokes) -> { + SignedMarkRevocationList shard = create(creationTime, shardRevokes); + shard.id = allocateId(); + shard.isShard = + true; // Avoid the exception in disallowUnshardedSaves(). + return shard; + })); }); return this; } diff --git a/java/google/registry/model/tmch/ClaimsListShard.java b/java/google/registry/model/tmch/ClaimsListShard.java index fad132865..e53e3767a 100644 --- a/java/google/registry/model/tmch/ClaimsListShard.java +++ b/java/google/registry/model/tmch/ClaimsListShard.java @@ -26,7 +26,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import com.googlecode.objectify.annotation.EmbedMap; import com.googlecode.objectify.annotation.Entity; @@ -178,32 +177,30 @@ public class ClaimsListShard extends ImmutableObject { (final ImmutableMap labelsToKeysShard) -> ofy() .transactNew( - new Work() { - @Override - public ClaimsListShard run() { - ClaimsListShard shard = create(creationTime, labelsToKeysShard); - shard.isShard = true; - shard.parent = parentKey; - ofy().saveWithoutBackup().entity(shard); - return shard; - } + () -> { + ClaimsListShard shard = create(creationTime, labelsToKeysShard); + shard.isShard = true; + shard.parent = parentKey; + ofy().saveWithoutBackup().entity(shard); + return shard; })); // Persist the new revision, thus causing the newly created shards to go live. - ofy().transactNew(new VoidWork() { - @Override - public void vrun() { - verify( - (getCurrentRevision() == null && oldRevision == null) - || getCurrentRevision().equals(oldRevision), - "ClaimsList on Registries was updated by someone else while attempting to update."); - ofy().saveWithoutBackup().entity(ClaimsListSingleton.create(parentKey)); - // Delete the old ClaimsListShard entities. - if (oldRevision != null) { - ofy().deleteWithoutBackup() - .keys(ofy().load().type(ClaimsListShard.class).ancestor(oldRevision).keys()); - } - }}); + ofy() + .transactNew( + () -> { + verify( + (getCurrentRevision() == null && oldRevision == null) + || getCurrentRevision().equals(oldRevision), + "Registries' ClaimsList was updated by someone else while attempting to update."); + ofy().saveWithoutBackup().entity(ClaimsListSingleton.create(parentKey)); + // Delete the old ClaimsListShard entities. + if (oldRevision != null) { + ofy() + .deleteWithoutBackup() + .keys(ofy().load().type(ClaimsListShard.class).ancestor(oldRevision).keys()); + } + }); } public static ClaimsListShard create( diff --git a/java/google/registry/model/tmch/TmchCrl.java b/java/google/registry/model/tmch/TmchCrl.java index 65af297de..939474750 100644 --- a/java/google/registry/model/tmch/TmchCrl.java +++ b/java/google/registry/model/tmch/TmchCrl.java @@ -17,7 +17,6 @@ package google.registry.model.tmch; import static com.google.common.base.Preconditions.checkNotNull; import static google.registry.model.ofy.ObjectifyService.ofy; -import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.annotation.Entity; import google.registry.model.annotations.NotBackedUp; import google.registry.model.annotations.NotBackedUp.Reason; @@ -49,15 +48,15 @@ public final class TmchCrl extends CrossTldSingleton { * and actually newer than the one currently in Datastore. */ public static void set(final String crl, final String url) { - ofy().transactNew(new VoidWork() { - @Override - public void vrun() { - TmchCrl tmchCrl = new TmchCrl(); - tmchCrl.updated = ofy().getTransactionTime(); - tmchCrl.crl = checkNotNull(crl, "crl"); - tmchCrl.url = checkNotNull(url, "url"); - ofy().saveWithoutBackup().entity(tmchCrl); - }}); + ofy() + .transactNew( + () -> { + TmchCrl tmchCrl = new TmchCrl(); + tmchCrl.updated = ofy().getTransactionTime(); + tmchCrl.crl = checkNotNull(crl, "crl"); + tmchCrl.url = checkNotNull(url, "url"); + ofy().saveWithoutBackup().entity(tmchCrl); + }); } /** ASCII-armored X.509 certificate revocation list. */ diff --git a/java/google/registry/rde/EscrowTaskRunner.java b/java/google/registry/rde/EscrowTaskRunner.java index 5712549f6..5b56b6b95 100644 --- a/java/google/registry/rde/EscrowTaskRunner.java +++ b/java/google/registry/rde/EscrowTaskRunner.java @@ -16,7 +16,6 @@ package google.registry.rde; import static google.registry.model.ofy.ObjectifyService.ofy; -import com.googlecode.objectify.VoidWork; import google.registry.model.common.Cursor; import google.registry.model.common.Cursor.CursorType; import google.registry.model.registry.Registry; @@ -99,15 +98,11 @@ class EscrowTaskRunner { task.runWithLock(nextRequiredRun); ofy() .transact( - new VoidWork() { - @Override - public void vrun() { + () -> ofy() .save() .entity( - Cursor.create(cursorType, nextRequiredRun.plus(interval), registry)); - } - }); + Cursor.create(cursorType, nextRequiredRun.plus(interval), registry))); return null; }; String lockName = String.format("EscrowTaskRunner %s", task.getClass().getSimpleName()); diff --git a/java/google/registry/rde/RdeStagingReducer.java b/java/google/registry/rde/RdeStagingReducer.java index c0ac4ca9f..89bc1abe3 100644 --- a/java/google/registry/rde/RdeStagingReducer.java +++ b/java/google/registry/rde/RdeStagingReducer.java @@ -30,7 +30,6 @@ import com.google.appengine.tools.cloudstorage.GcsFilename; import com.google.appengine.tools.cloudstorage.RetryParams; import com.google.appengine.tools.mapreduce.Reducer; import com.google.appengine.tools.mapreduce.ReducerInput; -import com.googlecode.objectify.VoidWork; import google.registry.config.RegistryConfig.Config; import google.registry.gcs.GcsUtils; import google.registry.keyring.api.KeyModule; @@ -226,33 +225,39 @@ public final class RdeStagingReducer extends Reducer { + Registry registry = Registry.get(tld); + DateTime position = + getCursorTimeOrStartOfTime( + ofy().load().key(Cursor.createKey(key.cursor(), registry)).now()); + checkState(key.interval() != null, "Interval must be present"); + DateTime newPosition = key.watermark().plus(key.interval()); + if (!position.isBefore(newPosition)) { + logger.warning("Cursor has already been rolled forward."); + return; + } + verify( + position.equals(key.watermark()), + "Partial ordering of RDE deposits broken: %s %s", + position, + key); + ofy().save().entity(Cursor.create(key.cursor(), newPosition, registry)).now(); + logger.infofmt( + "Rolled forward %s on %s cursor to %s", key.cursor(), tld, newPosition); + RdeRevision.saveRevision(tld, watermark, mode, revision); + if (mode == RdeMode.FULL) { + taskEnqueuer.enqueue( + getQueue("rde-upload"), + withUrl(RdeUploadAction.PATH).param(RequestParameters.PARAM_TLD, tld)); + } else { + taskEnqueuer.enqueue( + getQueue("brda"), + withUrl(BrdaCopyAction.PATH) + .param(RequestParameters.PARAM_TLD, tld) + .param(RdeModule.PARAM_WATERMARK, watermark.toString())); + } + }); } } diff --git a/java/google/registry/tools/CreateLrpTokensCommand.java b/java/google/registry/tools/CreateLrpTokensCommand.java index 88c3d9240..d82e033e3 100644 --- a/java/google/registry/tools/CreateLrpTokensCommand.java +++ b/java/google/registry/tools/CreateLrpTokensCommand.java @@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.io.Files; import com.google.common.io.LineReader; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Work; import google.registry.model.domain.LrpTokenEntity; import google.registry.tools.Command.RemoteApiCommand; import google.registry.tools.params.KeyValueMapParameter.StringToIntegerMap; @@ -162,23 +161,14 @@ public class CreateLrpTokensCommand implements RemoteApiCommand { } final ImmutableSet tokensToSave = tokensToSaveBuilder.build(); // Wrap in a retrier to deal with transient 404 errors (thrown as RemoteApiExceptions). - retrier.callWithRetry( - () -> { - saveTokens(tokensToSave); - return null; - }, - RemoteApiException.class); + retrier.callWithRetry(() -> saveTokens(tokensToSave), RemoteApiException.class); } while (line != null); } @VisibleForTesting void saveTokens(final ImmutableSet tokens) { Collection savedTokens = - ofy().transact(new Work>() { - @Override - public Collection run() { - return ofy().save().entities(tokens).now().values(); - }}); + ofy().transact(() -> ofy().save().entities(tokens).now().values()); for (LrpTokenEntity token : savedTokens) { System.out.printf("%s,%s%n", token.getAssignee(), token.getToken()); } diff --git a/java/google/registry/tools/GetAppliedLabelsCommand.java b/java/google/registry/tools/GetAppliedLabelsCommand.java index 1b9b63593..c32eb8e53 100644 --- a/java/google/registry/tools/GetAppliedLabelsCommand.java +++ b/java/google/registry/tools/GetAppliedLabelsCommand.java @@ -23,7 +23,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.beust.jcommander.internal.Sets; -import com.googlecode.objectify.Work; import google.registry.model.domain.DomainApplication; import google.registry.model.domain.launch.ApplicationStatus; import google.registry.tools.Command.RemoteApiCommand; @@ -70,23 +69,24 @@ final class GetAppliedLabelsCommand implements RemoteApiCommand { /** Return a set of all fully-qualified domain names with open applications. */ private static Set getDomainApplicationMap(final String tld) { - return ofy().transact(new Work>() { - @Override - public Set run() { - Set labels = Sets.newHashSet(); - List domainApplications; - domainApplications = ofy().load().type(DomainApplication.class).filter("tld", tld).list(); - for (DomainApplication domainApplication : domainApplications) { - // Ignore deleted and rejected applications. They aren't under consideration. - ApplicationStatus applicationStatus = domainApplication.getApplicationStatus(); - DateTime deletionTime = domainApplication.getDeletionTime(); - if (applicationStatus == REJECTED - || isAtOrAfter(ofy().getTransactionTime(), deletionTime)) { - continue; - } - labels.add(domainApplication.getFullyQualifiedDomainName()); - } - return labels; - }}); + return ofy() + .transact( + () -> { + Set labels = Sets.newHashSet(); + List domainApplications; + domainApplications = + ofy().load().type(DomainApplication.class).filter("tld", tld).list(); + for (DomainApplication domainApplication : domainApplications) { + // Ignore deleted and rejected applications. They aren't under consideration. + ApplicationStatus applicationStatus = domainApplication.getApplicationStatus(); + DateTime deletionTime = domainApplication.getDeletionTime(); + if (applicationStatus == REJECTED + || isAtOrAfter(ofy().getTransactionTime(), deletionTime)) { + continue; + } + labels.add(domainApplication.getFullyQualifiedDomainName()); + } + return labels; + }); } } diff --git a/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java b/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java index b2bc440d1..32ce968a0 100644 --- a/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java +++ b/java/google/registry/tools/ResaveEnvironmentEntitiesCommand.java @@ -20,7 +20,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import com.beust.jcommander.Parameters; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarContact; import google.registry.model.registry.Registry; @@ -48,11 +47,7 @@ final class ResaveEnvironmentEntitiesCommand implements RemoteApiCommand { System.out.printf("Re-saving %s entities.\n", clazz.getSimpleName()); for (final Iterable> batch : partition(ofy().load().type(clazz).ancestor(getCrossTldKey()).keys().list(), BATCH_SIZE)) { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entities(ofy().load().keys(batch).values()); - }}); + ofy().transact(() -> ofy().save().entities(ofy().load().keys(batch).values())); System.out.printf("Re-saved entities batch: %s.\n", batch); } } diff --git a/java/google/registry/tools/UpdateApplicationStatusCommand.java b/java/google/registry/tools/UpdateApplicationStatusCommand.java index 5e11bf586..8f0aeccc3 100644 --- a/java/google/registry/tools/UpdateApplicationStatusCommand.java +++ b/java/google/registry/tools/UpdateApplicationStatusCommand.java @@ -25,7 +25,6 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.common.collect.ImmutableList; -import com.googlecode.objectify.VoidWork; import google.registry.model.domain.DomainApplication; import google.registry.model.domain.launch.ApplicationStatus; import google.registry.model.domain.launch.LaunchInfoResponseExtension; @@ -70,12 +69,7 @@ final class UpdateApplicationStatusCommand extends MutatingCommand { checkArgumentPresent( Registrar.loadByClientId(clientId), "Registrar with client ID %s not found", clientId); for (final String applicationId : ids) { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - updateApplicationStatus(applicationId); - } - }); + ofy().transact(() -> updateApplicationStatus(applicationId)); } } diff --git a/java/google/registry/tools/UpdateClaimsNoticeCommand.java b/java/google/registry/tools/UpdateClaimsNoticeCommand.java index f03e3a9e5..7bcb5e2f4 100644 --- a/java/google/registry/tools/UpdateClaimsNoticeCommand.java +++ b/java/google/registry/tools/UpdateClaimsNoticeCommand.java @@ -21,7 +21,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.common.net.InternetDomainName; -import com.googlecode.objectify.VoidWork; import google.registry.model.domain.DomainApplication; import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.launch.LaunchNotice.InvalidChecksumException; @@ -67,15 +66,15 @@ final class UpdateClaimsNoticeCommand implements RemoteApiCommand { final LaunchNotice launchNotice = LaunchNotice.create( tcnId, validatorId, DateTime.parse(expirationTime), DateTime.parse(acceptedTime)); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - try { - updateClaimsNotice(id, launchNotice); - } catch (InvalidChecksumException e) { - throw new RuntimeException(e); - } - }}); + ofy() + .transact( + () -> { + try { + updateClaimsNotice(id, launchNotice); + } catch (InvalidChecksumException e) { + throw new RuntimeException(e); + } + }); } private void updateClaimsNotice(String applicationId, LaunchNotice launchNotice) diff --git a/java/google/registry/tools/UpdateSmdCommand.java b/java/google/registry/tools/UpdateSmdCommand.java index 5ce6d058d..7bf80bb7d 100644 --- a/java/google/registry/tools/UpdateSmdCommand.java +++ b/java/google/registry/tools/UpdateSmdCommand.java @@ -24,7 +24,6 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.common.collect.ImmutableList; import com.google.common.net.InternetDomainName; -import com.googlecode.objectify.VoidWork; import google.registry.flows.EppException; import google.registry.flows.domain.DomainFlowTmchUtils; import google.registry.model.domain.DomainApplication; @@ -67,15 +66,15 @@ final class UpdateSmdCommand implements RemoteApiCommand { final EncodedSignedMark encodedSignedMark = readEncodedSignedMark(new String(Files.readAllBytes(smdFile), US_ASCII)); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - try { - updateSmd(id, encodedSignedMark, reason); - } catch (EppException e) { - throw new RuntimeException(e); - } - }}); + ofy() + .transact( + () -> { + try { + updateSmd(id, encodedSignedMark, reason); + } catch (EppException e) { + throw new RuntimeException(e); + } + }); } private void updateSmd( diff --git a/java/google/registry/tools/server/KillAllEntitiesReducer.java b/java/google/registry/tools/server/KillAllEntitiesReducer.java index 65c6f1a70..eb6a6ac9c 100644 --- a/java/google/registry/tools/server/KillAllEntitiesReducer.java +++ b/java/google/registry/tools/server/KillAllEntitiesReducer.java @@ -20,7 +20,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import com.google.appengine.tools.mapreduce.Reducer; import com.google.appengine.tools.mapreduce.ReducerInput; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import java.util.Iterator; import java.util.List; @@ -37,11 +36,7 @@ public class KillAllEntitiesReducer extends Reducer, Key, Void> { while (batches.hasNext()) { final List> batch = batches.next(); // Use a transaction to get retrying for free. - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().deleteWithoutBackup().keys(batch); - }}); + ofy().transact(() -> ofy().deleteWithoutBackup().keys(batch)); getContext().incrementCounter("entities deleted", batch.size()); for (Key key : batch) { getContext().incrementCounter(String.format("%s deleted", key.getKind())); diff --git a/java/google/registry/tools/server/ResaveAllHistoryEntriesAction.java b/java/google/registry/tools/server/ResaveAllHistoryEntriesAction.java index 93fe5aa03..b0d22b560 100644 --- a/java/google/registry/tools/server/ResaveAllHistoryEntriesAction.java +++ b/java/google/registry/tools/server/ResaveAllHistoryEntriesAction.java @@ -20,7 +20,6 @@ import static google.registry.util.PipelineUtils.createJobPath; import com.google.appengine.tools.mapreduce.Mapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.VoidWork; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.EppResourceInputs; import google.registry.model.EppResource; @@ -70,11 +69,7 @@ public class ResaveAllHistoryEntriesAction implements Runnable { @Override public final void map(final HistoryEntry historyEntry) { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(ofy().load().entity(historyEntry).now()).now(); - }}); + ofy().transact(() -> ofy().save().entity(ofy().load().entity(historyEntry).now()).now()); getContext().incrementCounter( String.format( "HistoryEntries parented under %s re-saved", historyEntry.getParent().getKind())); diff --git a/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java b/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java index 19f15041e..79ee662e6 100644 --- a/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java +++ b/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java @@ -119,37 +119,36 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA Map update(final Map args, final Registrar registrar) { final String clientId = sessionUtils.getRegistrarClientId(request); - return ofy().transact(new Work>() { - @Override - public Map run() { - ImmutableSet oldContacts = registrar.getContacts(); - Map existingRegistrarMap = - expandRegistrarWithContacts(oldContacts, registrar); - Registrar.Builder builder = registrar.asBuilder(); - ImmutableSet updatedContacts = - changeRegistrarFields(registrar, builder, args); - if (!updatedContacts.isEmpty()) { - builder.setContactsRequireSyncing(true); - } - Registrar updatedRegistrar = builder.build(); - ofy().save().entity(updatedRegistrar); - if (!updatedContacts.isEmpty()) { - checkContactRequirements(oldContacts, updatedContacts); - RegistrarContact.updateContacts(updatedRegistrar, updatedContacts); - } - // Update the registrar map with updated contacts to bypass Objectify caching issues that - // come into play with calling getContacts(). - Map updatedRegistrarMap = - expandRegistrarWithContacts(updatedContacts, updatedRegistrar); - sendExternalUpdatesIfNecessary( - updatedRegistrar.getRegistrarName(), - existingRegistrarMap, - updatedRegistrarMap); - return JsonResponseHelper.create( - SUCCESS, - "Saved " + clientId, - updatedRegistrar.toJsonMap()); - }}); + return ofy() + .transact( + (Work>) + () -> { + ImmutableSet oldContacts = registrar.getContacts(); + Map existingRegistrarMap = + expandRegistrarWithContacts(oldContacts, registrar); + Registrar.Builder builder = registrar.asBuilder(); + ImmutableSet updatedContacts = + changeRegistrarFields(registrar, builder, args); + if (!updatedContacts.isEmpty()) { + builder.setContactsRequireSyncing(true); + } + Registrar updatedRegistrar = builder.build(); + ofy().save().entity(updatedRegistrar); + if (!updatedContacts.isEmpty()) { + checkContactRequirements(oldContacts, updatedContacts); + RegistrarContact.updateContacts(updatedRegistrar, updatedContacts); + } + // Update the registrar map with updated contacts to bypass Objectify caching + // issues that come into play with calling getContacts(). + Map updatedRegistrarMap = + expandRegistrarWithContacts(updatedContacts, updatedRegistrar); + sendExternalUpdatesIfNecessary( + updatedRegistrar.getRegistrarName(), + existingRegistrarMap, + updatedRegistrarMap); + return JsonResponseHelper.create( + SUCCESS, "Saved " + clientId, updatedRegistrar.toJsonMap()); + }); } private Map expandRegistrarWithContacts(Iterable contacts, diff --git a/javatests/google/registry/backup/CommitLogCheckpointStrategyTest.java b/javatests/google/registry/backup/CommitLogCheckpointStrategyTest.java index 9bf00c0d8..9ca27ce67 100644 --- a/javatests/google/registry/backup/CommitLogCheckpointStrategyTest.java +++ b/javatests/google/registry/backup/CommitLogCheckpointStrategyTest.java @@ -15,6 +15,7 @@ package google.registry.backup; import static com.google.common.truth.Truth.assertThat; +import static google.registry.model.common.Cursor.CursorType.RDE_REPORT; import static google.registry.model.ofy.CommitLogBucket.getBucketKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; @@ -23,9 +24,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; -import com.googlecode.objectify.VoidWork; import google.registry.model.common.Cursor; -import google.registry.model.common.Cursor.CursorType; import google.registry.model.ofy.CommitLogBucket; import google.registry.model.ofy.CommitLogCheckpoint; import google.registry.model.ofy.Ofy; @@ -291,25 +290,22 @@ public class CommitLogCheckpointStrategyTest { private void writeCommitLogToBucket(final int bucketId) { fakeBucketIdSupplier.value = bucketId; ofy.transact( - new VoidWork() { - @Override - public void vrun() { - String tld = "tld" + bucketId; - ofy().save().entity( - Cursor.create(CursorType.RDE_REPORT, ofy.getTransactionTime(), Registry.get(tld))); - } + () -> { + Cursor cursor = + Cursor.create(RDE_REPORT, ofy.getTransactionTime(), Registry.get("tld" + bucketId)); + ofy().save().entity(cursor); }); fakeBucketIdSupplier.value = null; } private void saveBucketWithLastWrittenTime(final int bucketId, final DateTime lastWrittenTime) { - ofy.transact(new VoidWork() { - @Override - public void vrun() { - ofy.saveWithoutBackup().entity( - CommitLogBucket.loadBucket(getBucketKey(bucketId)).asBuilder() - .setLastWrittenTime(lastWrittenTime) - .build()); - }}); + ofy.transact( + () -> + ofy.saveWithoutBackup() + .entity( + CommitLogBucket.loadBucket(getBucketKey(bucketId)) + .asBuilder() + .setLastWrittenTime(lastWrittenTime) + .build())); } } diff --git a/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java b/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java index 117211bac..05a60d23a 100644 --- a/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java +++ b/javatests/google/registry/batch/ExpandRecurringBillingEventsActionTest.java @@ -36,7 +36,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.OneTime; @@ -106,11 +105,7 @@ public class ExpandRecurringBillingEventsActionTest } void saveCursor(final DateTime cursorTime) throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, cursorTime)); - }}); + ofy().transact(() -> ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, cursorTime))); } void runMapreduce() throws Exception { diff --git a/javatests/google/registry/model/CreateAutoTimestampTest.java b/javatests/google/registry/model/CreateAutoTimestampTest.java index 8d17f34c3..61f1bacb1 100644 --- a/javatests/google/registry/model/CreateAutoTimestampTest.java +++ b/javatests/google/registry/model/CreateAutoTimestampTest.java @@ -19,8 +19,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static org.joda.time.DateTimeZone.UTC; import com.googlecode.objectify.ObjectifyService; -import com.googlecode.objectify.VoidWork; -import com.googlecode.objectify.Work; import com.googlecode.objectify.annotation.Entity; import google.registry.model.common.CrossTldSingleton; import google.registry.testing.AppEngineRule; @@ -57,14 +55,15 @@ public class CreateAutoTimestampTest { @Test public void testSaveSetsTime() throws Exception { - DateTime transactionTime = ofy().transact(new Work() { - @Override - public DateTime run() { - TestObject object = new TestObject(); - assertThat(object.createTime.getTimestamp()).isNull(); - ofy().save().entity(object); - return ofy().getTransactionTime(); - }}); + DateTime transactionTime = + ofy() + .transact( + () -> { + TestObject object = new TestObject(); + assertThat(object.createTime.getTimestamp()).isNull(); + ofy().save().entity(object); + return ofy().getTransactionTime(); + }); ofy().clearSessionCache(); assertThat(reload().createTime.timestamp).isEqualTo(transactionTime); } @@ -72,13 +71,13 @@ public class CreateAutoTimestampTest { @Test public void testResavingRespectsOriginalTime() throws Exception { final DateTime oldCreateTime = DateTime.now(UTC).minusDays(1); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - TestObject object = new TestObject(); - object.createTime = CreateAutoTimestamp.create(oldCreateTime); - ofy().save().entity(object); - }}); + ofy() + .transact( + () -> { + TestObject object = new TestObject(); + object.createTime = CreateAutoTimestamp.create(oldCreateTime); + ofy().save().entity(object); + }); ofy().clearSessionCache(); assertThat(reload().createTime.timestamp).isEqualTo(oldCreateTime); } diff --git a/javatests/google/registry/model/UpdateAutoTimestampTest.java b/javatests/google/registry/model/UpdateAutoTimestampTest.java index 61b8cd515..4c585eee2 100644 --- a/javatests/google/registry/model/UpdateAutoTimestampTest.java +++ b/javatests/google/registry/model/UpdateAutoTimestampTest.java @@ -19,7 +19,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static org.joda.time.DateTimeZone.UTC; import com.googlecode.objectify.ObjectifyService; -import com.googlecode.objectify.Work; import com.googlecode.objectify.annotation.Entity; import google.registry.model.common.CrossTldSingleton; import google.registry.testing.AppEngineRule; @@ -56,28 +55,30 @@ public class UpdateAutoTimestampTest { @Test public void testSaveSetsTime() throws Exception { - DateTime transactionTime = ofy().transact(new Work() { - @Override - public DateTime run() { - TestObject object = new TestObject(); - assertThat(object.updateTime.timestamp).isNull(); - ofy().save().entity(object); - return ofy().getTransactionTime(); - }}); + DateTime transactionTime = + ofy() + .transact( + () -> { + TestObject object = new TestObject(); + assertThat(object.updateTime.timestamp).isNull(); + ofy().save().entity(object); + return ofy().getTransactionTime(); + }); ofy().clearSessionCache(); assertThat(reload().updateTime.timestamp).isEqualTo(transactionTime); } @Test public void testResavingOverwritesOriginalTime() throws Exception { - DateTime transactionTime = ofy().transact(new Work() { - @Override - public DateTime run() { - TestObject object = new TestObject(); - object.updateTime = UpdateAutoTimestamp.create(DateTime.now(UTC).minusDays(1)); - ofy().save().entity(object); - return ofy().getTransactionTime(); - }}); + DateTime transactionTime = + ofy() + .transact( + () -> { + TestObject object = new TestObject(); + object.updateTime = UpdateAutoTimestamp.create(DateTime.now(UTC).minusDays(1)); + ofy().save().entity(object); + return ofy().getTransactionTime(); + }); ofy().clearSessionCache(); assertThat(reload().updateTime.timestamp).isEqualTo(transactionTime); } diff --git a/javatests/google/registry/model/common/CursorTest.java b/javatests/google/registry/model/common/CursorTest.java index c14e250bf..360ea847f 100644 --- a/javatests/google/registry/model/common/CursorTest.java +++ b/javatests/google/registry/model/common/CursorTest.java @@ -23,7 +23,6 @@ import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.util.DateTimeUtils.START_OF_TIME; -import com.googlecode.objectify.VoidWork; import google.registry.model.EntityTestCase; import google.registry.model.domain.DomainResource; import google.registry.model.registry.Registry; @@ -42,14 +41,7 @@ public class CursorTest extends EntityTestCase { createTld("tld"); clock.advanceOneMilli(); final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z"); - ofy() - .transact( - new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.create(RDE_UPLOAD, time, Registry.get("tld"))); - } - }); + ofy().transact(() -> ofy().save().entity(Cursor.create(RDE_UPLOAD, time, Registry.get("tld")))); assertThat(ofy().load().key(Cursor.createKey(BRDA, Registry.get("tld"))).now()).isNull(); assertThat( ofy() @@ -63,14 +55,7 @@ public class CursorTest extends EntityTestCase { @Test public void testSuccess_persistGlobalCursor() { final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z"); - ofy() - .transact( - new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, time)); - } - }); + ofy().transact(() -> ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, time))); assertThat(ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now().getCursorTime()) .isEqualTo(time); } @@ -78,14 +63,7 @@ public class CursorTest extends EntityTestCase { @Test public void testIndexing() throws Exception { final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z"); - ofy() - .transact( - new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, time)); - } - }); + ofy().transact(() -> ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, time))); Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now(); verifyIndexing(cursor); } @@ -98,14 +76,7 @@ public class CursorTest extends EntityTestCase { final DomainResource domain = persistActiveDomain("notaregistry.tld"); thrown.expect( IllegalArgumentException.class, "Class required for cursor does not match scope class"); - ofy() - .transact( - new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.create(RDE_UPLOAD, time, domain)); - } - }); + ofy().transact(() -> ofy().save().entity(Cursor.create(RDE_UPLOAD, time, domain))); } @Test diff --git a/javatests/google/registry/model/index/DomainApplicationIndexTest.java b/javatests/google/registry/model/index/DomainApplicationIndexTest.java index 239dec05e..9d5308b68 100644 --- a/javatests/google/registry/model/index/DomainApplicationIndexTest.java +++ b/javatests/google/registry/model/index/DomainApplicationIndexTest.java @@ -28,7 +28,6 @@ import static org.joda.time.DateTimeZone.UTC; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import google.registry.model.EntityTestCase; import google.registry.model.domain.DomainApplication; import google.registry.testing.ExceptionRule; @@ -132,12 +131,12 @@ public class DomainApplicationIndexTest extends EntityTestCase { persistResource(createUpdatedInstance(application)); applicationsBuilder.add(application); } - ofy().transact(new VoidWork() { - @Override - public void vrun() { - assertThat(DomainApplicationIndex.load("example.com")).isNotNull(); - assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc())) - .containsExactlyElementsIn(applicationsBuilder.build()); - }}); + ofy() + .transact( + () -> { + assertThat(DomainApplicationIndex.load("example.com")).isNotNull(); + assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc())) + .containsExactlyElementsIn(applicationsBuilder.build()); + }); } } diff --git a/javatests/google/registry/model/ofy/CommitLogMutationTest.java b/javatests/google/registry/model/ofy/CommitLogMutationTest.java index ef7f29afb..1bf68f403 100644 --- a/javatests/google/registry/model/ofy/CommitLogMutationTest.java +++ b/javatests/google/registry/model/ofy/CommitLogMutationTest.java @@ -22,7 +22,6 @@ import com.google.appengine.api.datastore.Entity; import com.google.appengine.api.datastore.EntityTranslator; import com.google.appengine.api.datastore.KeyFactory; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Work; import google.registry.model.ImmutableObject; import google.registry.model.registry.Registry; import google.registry.testing.AppEngineRule; @@ -69,11 +68,8 @@ public class CommitLogMutationTest { public void test_create_createsExpectedMutation() { Entity rawEntity = convertToEntityInTxn(someObject); // Needs to be in a transaction so that registry-saving-to-entity will work. - CommitLogMutation mutation = ofy().transact(new Work() { - @Override - public CommitLogMutation run() { - return CommitLogMutation.create(manifestKey, someObject); - }}); + CommitLogMutation mutation = + ofy().transact(() -> CommitLogMutation.create(manifestKey, someObject)); assertThat(Key.create(mutation)) .isEqualTo(CommitLogMutation.createKey(manifestKey, Key.create(someObject))); assertThat(mutation.getEntity()).isEqualTo(rawEntity); @@ -93,10 +89,6 @@ public class CommitLogMutationTest { } private static Entity convertToEntityInTxn(final ImmutableObject object) { - return ofy().transact(new Work() { - @Override - public Entity run() { - return ofy().save().toEntity(object); - }}); + return ofy().transact(() -> ofy().save().toEntity(object)); } } diff --git a/javatests/google/registry/model/ofy/OfyCommitLogTest.java b/javatests/google/registry/model/ofy/OfyCommitLogTest.java index 7518aa3d2..b0fb4ffe4 100644 --- a/javatests/google/registry/model/ofy/OfyCommitLogTest.java +++ b/javatests/google/registry/model/ofy/OfyCommitLogTest.java @@ -20,11 +20,9 @@ import static com.googlecode.objectify.ObjectifyService.register; 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.testing.TestObject.TestVirtualObject; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Parent; @@ -35,6 +33,7 @@ import google.registry.testing.AppEngineRule; import google.registry.testing.ExceptionRule; import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; +import google.registry.testing.TestObject.TestVirtualObject; import org.joda.time.DateTime; import org.junit.Before; import org.junit.Rule; @@ -68,20 +67,13 @@ public class OfyCommitLogTest { @Test public void testTransact_doesNothing_noCommitLogIsSaved() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() {} - }); + ofy().transact(() -> {}); assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty(); } @Test public void testTransact_savesDataAndCommitLog() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())).now(); - }}); + ofy().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now()); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value) .isEqualTo("value"); assertThat(ofy().load().type(CommitLogManifest.class)).hasSize(1); @@ -90,11 +82,7 @@ public class OfyCommitLogTest { @Test public void testTransact_saveWithoutBackup_noCommitLogIsSaved() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now(); - }}); + ofy().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now()); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now().value) .isEqualTo("value"); assertThat(ofy().load().type(CommitLogManifest.class)).isEmpty(); @@ -103,16 +91,8 @@ public class OfyCommitLogTest { @Test public void testTransact_deleteWithoutBackup_noCommitLogIsSaved() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now(); - }}); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().deleteWithoutBackup().key(Key.create(Root.class, 1)); - }}); + ofy().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now()); + ofy().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(); @@ -120,76 +100,58 @@ public class OfyCommitLogTest { @Test public void testTransact_savesEntity_itsProtobufFormIsStoredInCommitLog() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())).now(); - }}); + ofy().transact(() -> ofy().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() // when it attempts to set the update timestamp. - ofy().transact(new VoidWork() { - @Override - public void vrun() { - assertThat(entityProtoBytes).isEqualTo( - convertToPb(ofy().save().toEntity(Root.create(1, getCrossTldKey()))).toByteArray()); - }}); + ofy() + .transact( + () -> + assertThat(entityProtoBytes) + .isEqualTo( + convertToPb(ofy().save().toEntity(Root.create(1, getCrossTldKey()))) + .toByteArray())); } @Test public void testTransact_savesEntity_mutationIsChildOfManifest() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())).now(); - }}); - assertThat(ofy().load() - .type(CommitLogMutation.class) - .ancestor(ofy().load().type(CommitLogManifest.class).first().now())) - .hasSize(1); + ofy().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now()); + assertThat( + ofy() + .load() + .type(CommitLogMutation.class) + .ancestor(ofy().load().type(CommitLogManifest.class).first().now())) + .hasSize(1); } @Test public void testTransactNew_savesDataAndCommitLog() throws Exception { - ofy().transactNew(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())).now(); - }}); - assertThat(ofy().load() - .key(Key.create(getCrossTldKey(), Root.class, 1)) - .now().value).isEqualTo("value"); + ofy().transactNew(() -> ofy().save().entity(Root.create(1, getCrossTldKey())).now()); + assertThat(ofy().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); } @Test public void testTransact_multipleSaves_logsMultipleMutations() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())).now(); - ofy().save().entity(Root.create(2, getCrossTldKey())).now(); - }}); + ofy() + .transact( + () -> { + ofy().save().entity(Root.create(1, getCrossTldKey())).now(); + ofy().save().entity(Root.create(2, getCrossTldKey())).now(); + }); assertThat(ofy().load().type(CommitLogManifest.class)).hasSize(1); assertThat(ofy().load().type(CommitLogMutation.class)).hasSize(2); } @Test public void testTransact_deletion_deletesAndLogsWithoutMutation() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now(); - }}); + ofy().transact(() -> ofy().saveWithoutBackup().entity(Root.create(1, getCrossTldKey())).now()); clock.advanceOneMilli(); final Key otherTldKey = Key.create(getCrossTldKey(), Root.class, 1); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().delete().key(otherTldKey); - }}); + ofy().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(); @@ -202,11 +164,7 @@ public class OfyCommitLogTest { final CommitLogManifest backupsArentAllowedOnMe = CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.>of()); thrown.expect(IllegalArgumentException.class, "Can't save/delete a @NotBackedUp"); - ofy().transactNew(new VoidWork() { - @Override - public void vrun() { - ofy().delete().entity(backupsArentAllowedOnMe); - }}); + ofy().transactNew(() -> ofy().delete().entity(backupsArentAllowedOnMe)); } @Test @@ -214,33 +172,21 @@ public class OfyCommitLogTest { final CommitLogManifest backupsArentAllowedOnMe = CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.>of()); thrown.expect(IllegalArgumentException.class, "Can't save/delete a @NotBackedUp"); - ofy().transactNew(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(backupsArentAllowedOnMe); - }}); + ofy().transactNew(() -> ofy().save().entity(backupsArentAllowedOnMe)); } @Test public void testTransactNew_deleteVirtualEntityKey_throws() throws Exception { final Key virtualEntityKey = TestVirtualObject.createKey("virtual"); thrown.expect(IllegalArgumentException.class, "Can't save/delete a @VirtualEntity"); - ofy().transactNew(new VoidWork() { - @Override - public void vrun() { - ofy().delete().key(virtualEntityKey); - }}); + ofy().transactNew(() -> ofy().delete().key(virtualEntityKey)); } @Test public void testTransactNew_saveVirtualEntity_throws() throws Exception { final TestVirtualObject virtualEntity = TestVirtualObject.create("virtual"); thrown.expect(IllegalArgumentException.class, "Can't save/delete a @VirtualEntity"); - ofy().transactNew(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(virtualEntity); - }}); + ofy().transactNew(() -> ofy().save().entity(virtualEntity)); } @Test @@ -260,42 +206,38 @@ public class OfyCommitLogTest { @Test public void testTransact_twoSavesOnSameKey_throws() throws Exception { thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - ofy().save().entity(Root.create(1, getCrossTldKey())); - }}); + ofy() + .transact( + () -> { + ofy().save().entity(Root.create(1, getCrossTldKey())); + ofy().save().entity(Root.create(1, getCrossTldKey())); + }); } @Test public void testTransact_saveAndDeleteSameKey_throws() throws Exception { thrown.expect(IllegalArgumentException.class, "Multiple entries with same key"); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - ofy().delete().entity(Root.create(1, getCrossTldKey())); - }}); + ofy() + .transact( + () -> { + ofy().save().entity(Root.create(1, getCrossTldKey())); + ofy().delete().entity(Root.create(1, getCrossTldKey())); + }); } @Test public void testSavingRootAndChild_updatesTimestampOnBackupGroupRoot() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - }}); + ofy().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); clock.advanceOneMilli(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - ofy().save().entity(new Child()); - }}); + ofy() + .transact( + () -> { + ofy().save().entity(Root.create(1, getCrossTldKey())); + ofy().save().entity(new Child()); + }); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); @@ -303,20 +245,12 @@ public class OfyCommitLogTest { @Test public void testSavingOnlyChild_updatesTimestampOnBackupGroupRoot() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - }}); + ofy().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); clock.advanceOneMilli(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(new Child()); - }}); + ofy().transact(() -> ofy().save().entity(new Child())); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); @@ -324,21 +258,13 @@ public class OfyCommitLogTest { @Test public void testDeletingChild_updatesTimestampOnBackupGroupRoot() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - }}); + ofy().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); clock.advanceOneMilli(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - // The fact that the child was never persisted is irrelevant. - ofy().delete().entity(new Child()); - }}); + // The fact that the child was never persisted is irrelevant. + ofy().transact(() -> ofy().delete().entity(new Child())); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); @@ -346,23 +272,19 @@ public class OfyCommitLogTest { @Test public void testReadingRoot_doesntUpdateTimestamp() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - }}); + ofy().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); clock.advanceOneMilli(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - // Don't remove this line, as without saving *something* the commit log co/de will never - // be invoked and the test will trivially pass - ofy().save().entity(Root.create(2, getCrossTldKey())); - ofy().load().entity(Root.create(1, getCrossTldKey())); - }}); + ofy() + .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())); + }); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc().minusMillis(1)); @@ -370,23 +292,19 @@ public class OfyCommitLogTest { @Test public void testReadingChild_doesntUpdateTimestampOnBackupGroupRoot() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - }}); + ofy().transact(() -> ofy().save().entity(Root.create(1, getCrossTldKey()))); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc()); clock.advanceOneMilli(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - // Don't remove this line, as without saving *something* the commit log co/de 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). - }}); + ofy() + .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). + }); ofy().clearSessionCache(); assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() .getUpdateAutoTimestamp().getTimestamp()).isEqualTo(clock.nowUtc().minusMillis(1)); @@ -395,13 +313,13 @@ public class OfyCommitLogTest { @Test public void testSavingAcrossBackupGroupRoots_updatesCorrectTimestamps() throws Exception { // Create three roots. - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Root.create(1, getCrossTldKey())); - ofy().save().entity(Root.create(2, getCrossTldKey())); - ofy().save().entity(Root.create(3, getCrossTldKey())); - }}); + ofy() + .transact( + () -> { + ofy().save().entity(Root.create(1, getCrossTldKey())); + ofy().save().entity(Root.create(2, getCrossTldKey())); + ofy().save().entity(Root.create(3, getCrossTldKey())); + }); ofy().clearSessionCache(); for (int i = 1; i <= 3; i++) { assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, i)).now() @@ -409,12 +327,12 @@ public class OfyCommitLogTest { } clock.advanceOneMilli(); // Mutate one root, and a child of a second, ignoring the third. - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(new Child()); // All Child objects are under Root(1). - ofy().save().entity(Root.create(2, getCrossTldKey())); - }}); + ofy() + .transact( + () -> { + ofy().save().entity(new Child()); // All Child objects are under Root(1). + ofy().save().entity(Root.create(2, getCrossTldKey())); + }); ofy().clearSessionCache(); // Child was touched. assertThat(ofy().load().key(Key.create(getCrossTldKey(), Root.class, 1)).now() diff --git a/javatests/google/registry/model/smd/SignedMarkRevocationListTest.java b/javatests/google/registry/model/smd/SignedMarkRevocationListTest.java index fb889d56c..e5020a897 100644 --- a/javatests/google/registry/model/smd/SignedMarkRevocationListTest.java +++ b/javatests/google/registry/model/smd/SignedMarkRevocationListTest.java @@ -21,7 +21,6 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.time.Duration.standardDays; import com.google.common.collect.ImmutableMap; -import com.googlecode.objectify.VoidWork; import google.registry.testing.AppEngineRule; import google.registry.testing.ExceptionRule; import google.registry.testing.FakeClock; @@ -49,14 +48,15 @@ public class SignedMarkRevocationListTest { public void testUnshardedSaveFails() throws Exception { thrown.expect(SignedMarkRevocationList.UnshardedSaveException.class); // Our @Entity's @OnSave method will notice that this shouldn't be saved. - ofy().transact(new VoidWork() { - @Override - public void vrun() { - SignedMarkRevocationList smdrl = SignedMarkRevocationList.create( - ofy().getTransactionTime(), ImmutableMap.of("a", ofy().getTransactionTime())); - smdrl.id = 1; // Without an id this won't save anyways. - ofy().saveWithoutBackup().entity(smdrl).now(); - }}); + ofy() + .transact( + () -> { + SignedMarkRevocationList smdrl = + SignedMarkRevocationList.create( + ofy().getTransactionTime(), ImmutableMap.of("a", ofy().getTransactionTime())); + smdrl.id = 1; // Without an id this won't save anyways. + ofy().saveWithoutBackup().entity(smdrl).now(); + }); } @Test diff --git a/javatests/google/registry/model/tmch/ClaimsListShardTest.java b/javatests/google/registry/model/tmch/ClaimsListShardTest.java index e773d6a80..0b0cb3eb3 100644 --- a/javatests/google/registry/model/tmch/ClaimsListShardTest.java +++ b/javatests/google/registry/model/tmch/ClaimsListShardTest.java @@ -21,7 +21,6 @@ import static org.joda.time.DateTimeZone.UTC; import com.google.common.collect.ImmutableMap; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; import google.registry.model.tmch.ClaimsListShard.ClaimsListRevision; import google.registry.model.tmch.ClaimsListShard.UnshardedSaveException; import google.registry.testing.AppEngineRule; @@ -60,15 +59,15 @@ public class ClaimsListShardTest { @Test public void test_unshardedSaveFails() throws Exception { thrown.expect(UnshardedSaveException.class); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ClaimsListShard claimsList = - ClaimsListShard.create(ofy().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(); - }}); + ofy() + .transact( + () -> { + ClaimsListShard claimsList = + ClaimsListShard.create(ofy().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(); + }); } @Test diff --git a/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java b/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java index 615ab6aab..1fe07b442 100644 --- a/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java +++ b/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedMap; import com.googlecode.objectify.Key; import com.googlecode.objectify.ObjectifyService; -import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import com.googlecode.objectify.annotation.Entity; import google.registry.model.common.CrossTldSingleton; @@ -72,11 +71,7 @@ public class CommitLogRevisionsTranslatorFactoryTest { } private void save(final TestObject object) { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(object); - }}); + ofy().transact(() -> ofy().save().entity(object)); } private TestObject reload() { diff --git a/javatests/google/registry/rde/PendingDepositCheckerTest.java b/javatests/google/registry/rde/PendingDepositCheckerTest.java index 9d1a23f3c..66fc69e69 100644 --- a/javatests/google/registry/rde/PendingDepositCheckerTest.java +++ b/javatests/google/registry/rde/PendingDepositCheckerTest.java @@ -26,7 +26,6 @@ import static org.joda.time.DateTimeConstants.TUESDAY; import static org.joda.time.Duration.standardDays; import com.google.common.collect.ImmutableSetMultimap; -import com.googlecode.objectify.VoidWork; import google.registry.model.common.Cursor; import google.registry.model.common.Cursor.CursorType; import google.registry.model.ofy.Ofy; @@ -165,11 +164,7 @@ public class PendingDepositCheckerTest { private static void setCursor( final Registry registry, final CursorType cursorType, final DateTime value) { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.create(cursorType, value, registry)); - }}); + ofy().transact(() -> ofy().save().entity(Cursor.create(cursorType, value, registry))); } private static void createTldWithEscrowEnabled(final String tld) { diff --git a/javatests/google/registry/rde/RdeStagingActionTest.java b/javatests/google/registry/rde/RdeStagingActionTest.java index 881301280..0be2067bb 100644 --- a/javatests/google/registry/rde/RdeStagingActionTest.java +++ b/javatests/google/registry/rde/RdeStagingActionTest.java @@ -44,7 +44,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; -import com.googlecode.objectify.VoidWork; import google.registry.keyring.api.Keyring; import google.registry.keyring.api.PgpHelper; import google.registry.model.common.Cursor; @@ -864,11 +863,7 @@ public class RdeStagingActionTest extends MapreduceTestCase { private void setCursor( final Registry registry, final CursorType cursorType, final DateTime value) { clock.advanceOneMilli(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(Cursor.create(cursorType, value, registry)).now(); - }}); + ofy().transact(() -> ofy().save().entity(Cursor.create(cursorType, value, registry)).now()); } public static T unmarshal(Class clazz, byte[] xml) throws XmlException { diff --git a/javatests/google/registry/rde/RdeUploadActionTest.java b/javatests/google/registry/rde/RdeUploadActionTest.java index 4e321a7aa..98b5a2c44 100644 --- a/javatests/google/registry/rde/RdeUploadActionTest.java +++ b/javatests/google/registry/rde/RdeUploadActionTest.java @@ -47,7 +47,6 @@ import com.google.appengine.tools.cloudstorage.GcsServiceFactory; import com.google.common.io.ByteSource; import com.google.common.io.CharStreams; import com.google.common.io.Files; -import com.googlecode.objectify.VoidWork; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; @@ -252,12 +251,12 @@ public class RdeUploadActionTest { Ghostryde.encode(REPORT_XML.read(), encryptKey, "dieform.xml", clock.nowUtc())); writeGcsFile(gcsService, REPORT_R1_FILE, Ghostryde.encode(REPORT_XML.read(), encryptKey, "dieform.xml", clock.nowUtc())); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - RdeRevision.saveRevision("lol", DateTime.parse("2010-10-17TZ"), FULL, 0); - RdeRevision.saveRevision("tld", DateTime.parse("2010-10-17TZ"), FULL, 0); - }}); + ofy() + .transact( + () -> { + RdeRevision.saveRevision("lol", DateTime.parse("2010-10-17TZ"), FULL, 0); + RdeRevision.saveRevision("tld", DateTime.parse("2010-10-17TZ"), FULL, 0); + }); } @Test @@ -342,11 +341,7 @@ public class RdeUploadActionTest { @Test public void testRunWithLock_resend() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - RdeRevision.saveRevision("tld", DateTime.parse("2010-10-17TZ"), FULL, 1); - }}); + ofy().transact(() -> RdeRevision.saveRevision("tld", DateTime.parse("2010-10-17TZ"), FULL, 1)); int port = sftpd.serve("user", "password", folder.getRoot()); URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port)); DateTime stagingCursor = DateTime.parse("2010-10-18TZ"); diff --git a/javatests/google/registry/rde/imports/RdeImportUtilsTest.java b/javatests/google/registry/rde/imports/RdeImportUtilsTest.java index bc5a8a41b..f5014d366 100644 --- a/javatests/google/registry/rde/imports/RdeImportUtilsTest.java +++ b/javatests/google/registry/rde/imports/RdeImportUtilsTest.java @@ -34,8 +34,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import com.google.common.io.ByteSource; import com.googlecode.objectify.Key; -import com.googlecode.objectify.VoidWork; -import com.googlecode.objectify.Work; import google.registry.gcs.GcsUtils; import google.registry.model.EppResource; import google.registry.model.contact.ContactResource; @@ -111,11 +109,7 @@ public class RdeImportUtilsTest extends ShardableTestCase { @Test public void testImportNewContact() { final ContactResource newContact = buildNewContact(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - rdeImportUtils.importEppResource(newContact); - }}); + ofy().transact(() -> rdeImportUtils.importEppResource(newContact)); assertEppResourceIndexEntityFor(newContact); assertForeignKeyIndexFor(newContact); @@ -138,11 +132,7 @@ public class RdeImportUtilsTest extends ShardableTestCase { .setLastEppUpdateTime(newContact.getLastEppUpdateTime().plusSeconds(1)) .build(); try { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - rdeImportUtils.importEppResource(updatedContact); - }}); + ofy().transact(() -> rdeImportUtils.importEppResource(updatedContact)); fail("Expected ResourceExistsException"); } catch (ResourceExistsException expected) { // verify the updated contact was not saved @@ -158,11 +148,7 @@ public class RdeImportUtilsTest extends ShardableTestCase { @Test public void testImportNewHost() throws UnknownHostException { final HostResource newHost = buildNewHost(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - rdeImportUtils.importEppResource(newHost); - }}); + ofy().transact(() -> rdeImportUtils.importEppResource(newHost)); assertEppResourceIndexEntityFor(newHost); assertForeignKeyIndexFor(newHost); @@ -186,11 +172,7 @@ public class RdeImportUtilsTest extends ShardableTestCase { .setLastEppUpdateTime(newHost.getLastEppUpdateTime().plusSeconds(1)) .build(); try { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - rdeImportUtils.importEppResource(updatedHost); - }}); + ofy().transact(() -> rdeImportUtils.importEppResource(updatedHost)); fail("Expected ResourceExistsException"); } catch (ResourceExistsException expected) { // verify the contact was not updated @@ -205,12 +187,7 @@ public class RdeImportUtilsTest extends ShardableTestCase { @Test public void testImportNewDomain() throws Exception { final DomainResource newDomain = buildNewDomain(); - ofy().transact(new VoidWork() { - @Override - public void vrun() { - rdeImportUtils.importEppResource(newDomain); - } - }); + ofy().transact(() -> rdeImportUtils.importEppResource(newDomain)); DomainResource saved = getDomain("Dexample1-TEST"); assertThat(saved.getFullyQualifiedDomainName()) @@ -229,15 +206,13 @@ public class RdeImportUtilsTest extends ShardableTestCase { public void testImportExistingDomain() throws Exception { DomainResource newDomain = buildNewDomain(); persistResource(newDomain); - final DomainResource updatedDomain = newDomain.asBuilder() - .setFullyQualifiedDomainName("1" + newDomain.getFullyQualifiedDomainName()) - .build(); + final DomainResource updatedDomain = + newDomain + .asBuilder() + .setFullyQualifiedDomainName("1" + newDomain.getFullyQualifiedDomainName()) + .build(); try { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - rdeImportUtils.importEppResource(updatedDomain); - }}); + ofy().transact(() -> rdeImportUtils.importEppResource(updatedDomain)); fail("Expected ResourceExistsException"); } catch (ResourceExistsException expected) { DomainResource saved = getDomain("Dexample1-TEST"); @@ -339,32 +314,19 @@ public class RdeImportUtilsTest extends ShardableTestCase { /** Gets the contact with the specified ROID */ private static ContactResource getContact(String repoId) { final Key key = Key.create(ContactResource.class, repoId); - return ofy().transact(new Work() { - @Override - public ContactResource run() { - return ofy().load().key(key).now(); - }}); + return ofy().transact(() -> ofy().load().key(key).now()); } /** Gets the host with the specified ROID */ private static HostResource getHost(String repoId) { final Key key = Key.create(HostResource.class, repoId); - return ofy().transact(new Work() { - @Override - public HostResource run() { - return ofy().load().key(key).now(); - } - }); + return ofy().transact(() -> ofy().load().key(key).now()); } /** Gets the domain with the specified ROID */ private static DomainResource getDomain(String repoId) { final Key key = Key.create(DomainResource.class, repoId); - return ofy().transact(new Work() { - @Override - public DomainResource run() { - return ofy().load().key(key).now(); - }}); + return ofy().transact(() -> ofy().load().key(key).now()); } /** Confirms that a ForeignKeyIndex exists in Datastore for a given resource. */ diff --git a/javatests/google/registry/tmch/LordnTaskTest.java b/javatests/google/registry/tmch/LordnTaskTest.java index f184915f5..b22a1a03e 100644 --- a/javatests/google/registry/tmch/LordnTaskTest.java +++ b/javatests/google/registry/tmch/LordnTaskTest.java @@ -138,17 +138,19 @@ public class LordnTaskTest { @Test public void test_oteRegistrarWithNullIanaId() throws Exception { - ofy().transact(new VoidWork() { - @Override - public void vrun() { - ofy().save().entity(loadRegistrar("TheRegistrar").asBuilder() - .setType(Type.OTE) - .setIanaIdentifier(null) - .build()); - }}); - DomainResource domain = newDomainBuilder(DateTime.parse("2010-05-01T10:11:12Z")) - .setRepoId("3-EXAMPLE") - .build(); + ofy() + .transact( + () -> + ofy() + .save() + .entity( + loadRegistrar("TheRegistrar") + .asBuilder() + .setType(Type.OTE) + .setIanaIdentifier(null) + .build())); + DomainResource domain = + newDomainBuilder(DateTime.parse("2010-05-01T10:11:12Z")).setRepoId("3-EXAMPLE").build(); persistDomainAndEnqueueLordn(domain); String expectedPayload = "3-EXAMPLE,fleece.example,smdzzzz,null,2010-05-01T10:11:12.000Z,2010-05-01T10:11:12.000Z";