mirror of
https://github.com/google/nomulus.git
synced 2025-06-21 11:50:48 +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
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
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<DateTime>() {
|
||||
@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);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
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());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,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<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().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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
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");
|
||||
|
|
|
@ -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<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()
|
||||
.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";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue