mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 08:57:12 +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
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue