mirror of
https://github.com/google/nomulus.git
synced 2025-06-04 03:27:27 +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
|
@ -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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue