diff --git a/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java b/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java index 5697ffb5f..2404543a5 100644 --- a/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java +++ b/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java @@ -49,11 +49,14 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi { tokens.stream() .map(t -> VKey.create(AllocationToken.class, t)) .collect(toImmutableList()); - tm().loadByKeysIfPresent(tokenKeys) - .forEach((k, v) -> builder.put(k.getSqlKey().toString(), v)); + tm().transact( + () -> + tm().loadByKeysIfPresent(tokenKeys) + .forEach((k, v) -> builder.put(k.getSqlKey().toString(), v))); } ImmutableMap loadedTokens = builder.build(); - ImmutableMap, DomainBase> domains = loadRedeemedDomains(loadedTokens.values()); + ImmutableMap, DomainBase> domains = + tm().transact(() -> loadRedeemedDomains(loadedTokens.values())); for (String token : mainParameters) { if (loadedTokens.containsKey(token)) { diff --git a/core/src/main/java/google/registry/tools/UniformRapidSuspensionCommand.java b/core/src/main/java/google/registry/tools/UniformRapidSuspensionCommand.java index cc9f7f82c..a059b3ecb 100644 --- a/core/src/main/java/google/registry/tools/UniformRapidSuspensionCommand.java +++ b/core/src/main/java/google/registry/tools/UniformRapidSuspensionCommand.java @@ -204,7 +204,8 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand { private ImmutableSortedSet getExistingNameservers(DomainBase domain) { ImmutableSortedSet.Builder nameservers = ImmutableSortedSet.naturalOrder(); - for (HostResource host : tm().loadByKeys(domain.getNameservers()).values()) { + for (HostResource host : + tm().transact(() -> tm().loadByKeys(domain.getNameservers()).values())) { nameservers.add(host.getForeignKey()); } return nameservers.build(); diff --git a/core/src/test/java/google/registry/tools/GetAllocationTokenCommandTest.java b/core/src/test/java/google/registry/tools/GetAllocationTokenCommandTest.java index 515339c4a..7eda87df8 100644 --- a/core/src/test/java/google/registry/tools/GetAllocationTokenCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetAllocationTokenCommandTest.java @@ -29,13 +29,15 @@ import com.googlecode.objectify.Key; import google.registry.model.domain.DomainBase; import google.registry.model.domain.token.AllocationToken; import google.registry.model.reporting.HistoryEntry; +import google.registry.testing.DualDatabaseTest; +import google.registry.testing.TestSqlOnly; import org.joda.time.DateTime; -import org.junit.jupiter.api.Test; /** Unit tests for {@link GetAllocationTokenCommand}. */ +@DualDatabaseTest class GetAllocationTokenCommandTest extends CommandTestCase { - @Test + @TestSqlOnly void testSuccess_oneToken() throws Exception { createTlds("bar"); AllocationToken token = @@ -49,7 +51,7 @@ class GetAllocationTokenCommandTest extends CommandTestCase tokens = @@ -73,7 +75,7 @@ class GetAllocationTokenCommandTest extends CommandTestCase { @@ -72,7 +74,7 @@ class UniformRapidSuspensionCommandTest domainBase.asBuilder().setNameservers(hostRefs.build()).setDsData(dsData).build()); } - @Test + @TestSqlOnly void testCommand_addsLocksReplacesHostsAndDsDataPrintsUndo() throws Exception { persistDomainWithHosts(defaultDomainBase, defaultDsData, ns1, ns2); runCommandForced( @@ -93,7 +95,7 @@ class UniformRapidSuspensionCommandTest assertNotInStdout("--restore_client_hold"); } - @Test + @TestSqlOnly void testCommand_respectsExistingHost() throws Exception { persistDomainWithHosts(defaultDomainBase, defaultDsData, urs2, ns1); runCommandForced( @@ -111,7 +113,7 @@ class UniformRapidSuspensionCommandTest assertNotInStdout("--locks_to_preserve"); } - @Test + @TestSqlOnly void testCommand_generatesUndoForUndelegatedDomain() throws Exception { persistActiveDomain("evil.tld"); runCommandForced( @@ -124,7 +126,7 @@ class UniformRapidSuspensionCommandTest assertNotInStdout("--locks_to_preserve"); } - @Test + @TestSqlOnly void testCommand_generatesUndoWithLocksToPreserve() throws Exception { persistResource( newDomainBase("evil.tld").asBuilder() @@ -137,7 +139,7 @@ class UniformRapidSuspensionCommandTest assertInStdout("--locks_to_preserve serverDeleteProhibited"); } - @Test + @TestSqlOnly void testCommand_removeClientHold() throws Exception { persistResource( newDomainBase("evil.tld") @@ -162,7 +164,7 @@ class UniformRapidSuspensionCommandTest assertInStdout("--restore_client_hold"); } - @Test + @TestSqlOnly void testUndo_removesLocksReplacesHostsAndDsData() throws Exception { persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2); runCommandForced( @@ -178,7 +180,7 @@ class UniformRapidSuspensionCommandTest assertNotInStdout("--undo"); // Undo shouldn't print a new undo command. } - @Test + @TestSqlOnly void testUndo_respectsLocksToPreserveFlag() throws Exception { persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2); runCommandForced( @@ -195,7 +197,7 @@ class UniformRapidSuspensionCommandTest assertNotInStdout("--undo"); // Undo shouldn't print a new undo command. } - @Test + @TestSqlOnly void testUndo_restoresClientHolds() throws Exception { persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2); runCommandForced( @@ -212,7 +214,7 @@ class UniformRapidSuspensionCommandTest assertNotInStdout("--undo"); // Undo shouldn't print a new undo command. } - @Test + @TestSqlOnly void testAutorenews_setToFalseByDefault() throws Exception { persistResource( newDomainBase("evil.tld") @@ -224,7 +226,7 @@ class UniformRapidSuspensionCommandTest assertInStdout("false"); } - @Test + @TestSqlOnly void testAutorenews_setToTrueWhenUndo() throws Exception { persistResource( newDomainBase("evil.tld") @@ -241,7 +243,7 @@ class UniformRapidSuspensionCommandTest assertInStdout("true"); } - @Test + @TestSqlOnly void testRenewOneYearWithoutUndo_verifyReasonWithoutUndo() throws Exception { persistDomainWithHosts( newDomainBase("evil.tld") @@ -278,7 +280,7 @@ class UniformRapidSuspensionCommandTest .verifySentAny(); } - @Test + @TestSqlOnly void testRenewOneYearWithUndo_verifyReasonWithUndo() throws Exception { persistDomainWithHosts( newDomainBase("evil.tld") @@ -316,7 +318,7 @@ class UniformRapidSuspensionCommandTest .verifySentAny(); } - @Test + @TestSqlOnly void testRenewOneYear_verifyBothRenewAndUpdateFlowsAreTriggered() throws Exception { persistDomainWithHosts( newDomainBase("evil.tld") @@ -361,7 +363,7 @@ class UniformRapidSuspensionCommandTest eppVerifier.verifyNoMoreSent(); } - @Test + @TestSqlOnly void testFailure_locksToPreserveWithoutUndo() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown = @@ -375,7 +377,7 @@ class UniformRapidSuspensionCommandTest assertThat(thrown).hasMessageThat().contains("--undo"); } - @Test + @TestSqlOnly void testFailure_domainNameRequired() { persistActiveDomain("evil.tld"); ParameterException thrown = @@ -387,7 +389,7 @@ class UniformRapidSuspensionCommandTest assertThat(thrown).hasMessageThat().contains("--domain_name"); } - @Test + @TestSqlOnly void testFailure_renewOneYearRequired() { persistActiveDomain("evil.tld"); ParameterException thrown = @@ -395,7 +397,7 @@ class UniformRapidSuspensionCommandTest assertThat(thrown).hasMessageThat().contains("--renew_one_year"); } - @Test + @TestSqlOnly void testFailure_extraFieldInDsData() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown = @@ -409,7 +411,7 @@ class UniformRapidSuspensionCommandTest .contains("dsRecord 1 1 1 abc 1 should have 4 parts, but has 5"); } - @Test + @TestSqlOnly void testFailure_missingFieldInDsData() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown = @@ -421,7 +423,7 @@ class UniformRapidSuspensionCommandTest assertThat(thrown).hasMessageThat().contains("dsRecord 1 1 1 should have 4 parts, but has 3"); } - @Test + @TestSqlOnly void testFailure_malformedDsData() { persistActiveDomain("evil.tld"); IllegalArgumentException thrown =