mirror of
https://github.com/google/nomulus.git
synced 2025-05-02 13:07:50 +02:00
Replace many Work and VoidWork usages with lambdas
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=176153460
This commit is contained in:
parent
603e0470cc
commit
cd314bdc75
36 changed files with 443 additions and 680 deletions
|
@ -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() {
|
||||
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()));
|
||||
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()));
|
||||
}});
|
||||
.param(
|
||||
UPPER_CHECKPOINT_TIME_PARAM, checkpoint.getCheckpointTime().toString()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,22 +314,21 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
|
|||
isDryRun ? "(dry run) " : "",
|
||||
cursorTime,
|
||||
executionTime);
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
Cursor cursor = ofy().load().key(Cursor.createGlobalKey(RECURRING_BILLING)).now();
|
||||
DateTime currentCursorTime = (cursor == null ? START_OF_TIME : cursor.getCursorTime());
|
||||
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);
|
||||
currentCursorTime, expectedPersistedCursorTime);
|
||||
return;
|
||||
}
|
||||
if (!isDryRun) {
|
||||
ofy().save().entity(Cursor.createGlobal(RECURRING_BILLING, executionTime));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<EppResource> resourceKey) {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
EppResource projectedResource =
|
||||
ofy().load().key(resourceKey).now().cloneProjectedAtTime(ofy().getTransactionTime());
|
||||
ofy()
|
||||
.load()
|
||||
.key(resourceKey)
|
||||
.now()
|
||||
.cloneProjectedAtTime(ofy().getTransactionTime());
|
||||
ofy().save().entity(projectedResource).now();
|
||||
}});
|
||||
});
|
||||
getContext().incrementCounter(String.format("%s entities re-saved", resourceKey.getKind()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,9 +87,9 @@ public class FlowRunner {
|
|||
return eppOutput;
|
||||
}
|
||||
try {
|
||||
return ofy().transact(new Work<EppOutput>() {
|
||||
@Override
|
||||
public EppOutput run() {
|
||||
return ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
eppMetricBuilder.incrementAttempts();
|
||||
try {
|
||||
EppOutput output = EppOutput.create(flowProvider.get().run());
|
||||
|
@ -101,7 +100,7 @@ public class FlowRunner {
|
|||
} catch (EppException e) {
|
||||
throw new EppRuntimeException(e);
|
||||
}
|
||||
}});
|
||||
});
|
||||
} catch (DryRunException e) {
|
||||
return e.output;
|
||||
} catch (EppRuntimeException e) {
|
||||
|
|
|
@ -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,9 +185,7 @@ public final class KmsUpdater {
|
|||
final ImmutableMap<String, EncryptResponse> encryptedValues) {
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
for (Map.Entry<String, EncryptResponse> entry : encryptedValues.entrySet()) {
|
||||
String secretName = entry.getKey();
|
||||
EncryptResponse revisionData = entry.getValue();
|
||||
|
@ -199,10 +196,7 @@ public final class KmsUpdater {
|
|||
.setKmsCryptoKeyVersionName(revisionData.cryptoKeyVersionName())
|
||||
.setParent(secretName)
|
||||
.build();
|
||||
ofy()
|
||||
.save()
|
||||
.entities(secretRevision, KmsSecret.create(secretName, secretRevision));
|
||||
}
|
||||
ofy().save().entities(secretRevision, KmsSecret.create(secretName, secretRevision));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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,9 +156,7 @@ public class SignedMarkRevocationList extends ImmutableObject {
|
|||
public SignedMarkRevocationList save() {
|
||||
ofy()
|
||||
.transact(
|
||||
new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
() -> {
|
||||
ofy()
|
||||
.deleteWithoutBackup()
|
||||
.keys(
|
||||
|
@ -174,14 +171,12 @@ public class SignedMarkRevocationList extends ImmutableObject {
|
|||
FluentIterable.from(CollectionUtils.partitionMap(revokes, SHARD_SIZE))
|
||||
.transform(
|
||||
(ImmutableMap<String, DateTime> shardRevokes) -> {
|
||||
SignedMarkRevocationList shard =
|
||||
create(creationTime, shardRevokes);
|
||||
SignedMarkRevocationList shard = create(creationTime, shardRevokes);
|
||||
shard.id = allocateId();
|
||||
shard.isShard =
|
||||
true; // Avoid the exception in disallowUnshardedSaves().
|
||||
return shard;
|
||||
}));
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -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<String, String> labelsToKeysShard) ->
|
||||
ofy()
|
||||
.transactNew(
|
||||
new Work<ClaimsListShard>() {
|
||||
@Override
|
||||
public ClaimsListShard run() {
|
||||
() -> {
|
||||
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() {
|
||||
ofy()
|
||||
.transactNew(
|
||||
() -> {
|
||||
verify(
|
||||
(getCurrentRevision() == null && oldRevision == null)
|
||||
|| getCurrentRevision().equals(oldRevision),
|
||||
"ClaimsList on Registries was updated by someone else while attempting to update.");
|
||||
"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()
|
||||
ofy()
|
||||
.deleteWithoutBackup()
|
||||
.keys(ofy().load().type(ClaimsListShard.class).ancestor(oldRevision).keys());
|
||||
}
|
||||
}});
|
||||
});
|
||||
}
|
||||
|
||||
public static ClaimsListShard create(
|
||||
|
|
|
@ -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() {
|
||||
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. */
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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,11 +225,12 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
|||
logger.info("Manual operation; not advancing cursor or enqueuing upload task");
|
||||
return;
|
||||
}
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
Registry registry = Registry.get(tld);
|
||||
DateTime position = getCursorTimeOrStartOfTime(
|
||||
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());
|
||||
|
@ -238,21 +238,26 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
|||
logger.warning("Cursor has already been rolled forward.");
|
||||
return;
|
||||
}
|
||||
verify(position.equals(key.watermark()),
|
||||
"Partial ordering of RDE deposits broken: %s %s", position, key);
|
||||
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);
|
||||
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));
|
||||
taskEnqueuer.enqueue(
|
||||
getQueue("rde-upload"),
|
||||
withUrl(RdeUploadAction.PATH).param(RequestParameters.PARAM_TLD, tld));
|
||||
} else {
|
||||
taskEnqueuer.enqueue(getQueue("brda"),
|
||||
taskEnqueuer.enqueue(
|
||||
getQueue("brda"),
|
||||
withUrl(BrdaCopyAction.PATH)
|
||||
.param(RequestParameters.PARAM_TLD, tld)
|
||||
.param(RdeModule.PARAM_WATERMARK, watermark.toString()));
|
||||
}
|
||||
}});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LrpTokenEntity> 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<LrpTokenEntity> tokens) {
|
||||
Collection<LrpTokenEntity> savedTokens =
|
||||
ofy().transact(new Work<Collection<LrpTokenEntity>>() {
|
||||
@Override
|
||||
public Collection<LrpTokenEntity> 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());
|
||||
}
|
||||
|
|
|
@ -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,12 +69,13 @@ final class GetAppliedLabelsCommand implements RemoteApiCommand {
|
|||
|
||||
/** Return a set of all fully-qualified domain names with open applications. */
|
||||
private static Set<String> getDomainApplicationMap(final String tld) {
|
||||
return ofy().transact(new Work<Set<String>>() {
|
||||
@Override
|
||||
public Set<String> run() {
|
||||
return ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
Set<String> labels = Sets.newHashSet();
|
||||
List<DomainApplication> domainApplications;
|
||||
domainApplications = ofy().load().type(DomainApplication.class).filter("tld", tld).list();
|
||||
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();
|
||||
|
@ -87,6 +87,6 @@ final class GetAppliedLabelsCommand implements RemoteApiCommand {
|
|||
labels.add(domainApplication.getFullyQualifiedDomainName());
|
||||
}
|
||||
return labels;
|
||||
}});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Key<T>> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
try {
|
||||
updateClaimsNotice(id, launchNotice);
|
||||
} catch (InvalidChecksumException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}});
|
||||
});
|
||||
}
|
||||
|
||||
private void updateClaimsNotice(String applicationId, LaunchNotice launchNotice)
|
||||
|
|
|
@ -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() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
try {
|
||||
updateSmd(id, encodedSignedMark, reason);
|
||||
} catch (EppException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}});
|
||||
});
|
||||
}
|
||||
|
||||
private void updateSmd(
|
||||
|
|
|
@ -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<?>, Key<?>, Void> {
|
|||
while (batches.hasNext()) {
|
||||
final List<Key<?>> 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()));
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -119,9 +119,10 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
|
||||
Map<String, Object> update(final Map<String, ?> args, final Registrar registrar) {
|
||||
final String clientId = sessionUtils.getRegistrarClientId(request);
|
||||
return ofy().transact(new Work<Map<String, Object>>() {
|
||||
@Override
|
||||
public Map<String, Object> run() {
|
||||
return ofy()
|
||||
.transact(
|
||||
(Work<Map<String, Object>>)
|
||||
() -> {
|
||||
ImmutableSet<RegistrarContact> oldContacts = registrar.getContacts();
|
||||
Map<String, Object> existingRegistrarMap =
|
||||
expandRegistrarWithContacts(oldContacts, registrar);
|
||||
|
@ -137,8 +138,8 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
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().
|
||||
// Update the registrar map with updated contacts to bypass Objectify caching
|
||||
// issues that come into play with calling getContacts().
|
||||
Map<String, Object> updatedRegistrarMap =
|
||||
expandRegistrarWithContacts(updatedContacts, updatedRegistrar);
|
||||
sendExternalUpdatesIfNecessary(
|
||||
|
@ -146,10 +147,8 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
|
|||
existingRegistrarMap,
|
||||
updatedRegistrarMap);
|
||||
return JsonResponseHelper.create(
|
||||
SUCCESS,
|
||||
"Saved " + clientId,
|
||||
updatedRegistrar.toJsonMap());
|
||||
}});
|
||||
SUCCESS, "Saved " + clientId, updatedRegistrar.toJsonMap());
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, Object> expandRegistrarWithContacts(Iterable<RegistrarContact> contacts,
|
||||
|
|
|
@ -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()
|
||||
ofy.transact(
|
||||
() ->
|
||||
ofy.saveWithoutBackup()
|
||||
.entity(
|
||||
CommitLogBucket.loadBucket(getBucketKey(bucketId))
|
||||
.asBuilder()
|
||||
.setLastWrittenTime(lastWrittenTime)
|
||||
.build());
|
||||
}});
|
||||
.build()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<DateTime>() {
|
||||
@Override
|
||||
public DateTime run() {
|
||||
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() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
TestObject object = new TestObject();
|
||||
object.createTime = CreateAutoTimestamp.create(oldCreateTime);
|
||||
ofy().save().entity(object);
|
||||
}});
|
||||
});
|
||||
ofy().clearSessionCache();
|
||||
assertThat(reload().createTime.timestamp).isEqualTo(oldCreateTime);
|
||||
}
|
||||
|
|
|
@ -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<DateTime>() {
|
||||
@Override
|
||||
public DateTime run() {
|
||||
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<DateTime>() {
|
||||
@Override
|
||||
public DateTime run() {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
ofy()
|
||||
.transact(
|
||||
() -> {
|
||||
assertThat(DomainApplicationIndex.load("example.com")).isNotNull();
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc()))
|
||||
.containsExactlyElementsIn(applicationsBuilder.build());
|
||||
}});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<CommitLogMutation>() {
|
||||
@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<Entity>() {
|
||||
@Override
|
||||
public Entity run() {
|
||||
return ofy().save().toEntity(object);
|
||||
}});
|
||||
return ofy().transact(() -> ofy().save().toEntity(object));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,31 +100,26 @@ 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()
|
||||
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);
|
||||
|
@ -152,44 +127,31 @@ public class OfyCommitLogTest {
|
|||
|
||||
@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()
|
||||
.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<Root> 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.<Key<?>>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.<Key<?>>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<TestVirtualObject> 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()
|
||||
.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()
|
||||
.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()
|
||||
.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());
|
||||
}});
|
||||
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()
|
||||
.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()
|
||||
.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()
|
||||
.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()
|
||||
.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()
|
||||
|
|
|
@ -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()
|
||||
.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
|
||||
|
|
|
@ -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() {
|
||||
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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<RdeStagingAction> {
|
|||
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> T unmarshal(Class<T> clazz, byte[] xml) throws XmlException {
|
||||
|
|
|
@ -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() {
|
||||
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");
|
||||
|
|
|
@ -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()
|
||||
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<ContactResource> key = Key.create(ContactResource.class, repoId);
|
||||
return ofy().transact(new Work<ContactResource>() {
|
||||
@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<HostResource> key = Key.create(HostResource.class, repoId);
|
||||
return ofy().transact(new Work<HostResource>() {
|
||||
@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<DomainResource> key = Key.create(DomainResource.class, repoId);
|
||||
return ofy().transact(new Work<DomainResource>() {
|
||||
@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. */
|
||||
|
|
|
@ -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()
|
||||
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();
|
||||
.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";
|
||||
|
|
Loading…
Add table
Reference in a new issue