mirror of
https://github.com/google/nomulus.git
synced 2025-08-12 20:49:37 +02:00
Fix some small transactional issues in SQL mode (#1662)
* Fix some small transactional issues in SQL mode These weren't caught until I switched the default database type in tests to be SQL (separate PR). Fortunately these don't seem to be catastrophic
This commit is contained in:
parent
623356b1e8
commit
e30b3f9e0b
4 changed files with 38 additions and 30 deletions
|
@ -49,11 +49,14 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi {
|
||||||
tokens.stream()
|
tokens.stream()
|
||||||
.map(t -> VKey.create(AllocationToken.class, t))
|
.map(t -> VKey.create(AllocationToken.class, t))
|
||||||
.collect(toImmutableList());
|
.collect(toImmutableList());
|
||||||
tm().loadByKeysIfPresent(tokenKeys)
|
tm().transact(
|
||||||
.forEach((k, v) -> builder.put(k.getSqlKey().toString(), v));
|
() ->
|
||||||
|
tm().loadByKeysIfPresent(tokenKeys)
|
||||||
|
.forEach((k, v) -> builder.put(k.getSqlKey().toString(), v)));
|
||||||
}
|
}
|
||||||
ImmutableMap<String, AllocationToken> loadedTokens = builder.build();
|
ImmutableMap<String, AllocationToken> loadedTokens = builder.build();
|
||||||
ImmutableMap<VKey<DomainBase>, DomainBase> domains = loadRedeemedDomains(loadedTokens.values());
|
ImmutableMap<VKey<DomainBase>, DomainBase> domains =
|
||||||
|
tm().transact(() -> loadRedeemedDomains(loadedTokens.values()));
|
||||||
|
|
||||||
for (String token : mainParameters) {
|
for (String token : mainParameters) {
|
||||||
if (loadedTokens.containsKey(token)) {
|
if (loadedTokens.containsKey(token)) {
|
||||||
|
|
|
@ -204,7 +204,8 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand {
|
||||||
|
|
||||||
private ImmutableSortedSet<String> getExistingNameservers(DomainBase domain) {
|
private ImmutableSortedSet<String> getExistingNameservers(DomainBase domain) {
|
||||||
ImmutableSortedSet.Builder<String> nameservers = ImmutableSortedSet.naturalOrder();
|
ImmutableSortedSet.Builder<String> 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());
|
nameservers.add(host.getForeignKey());
|
||||||
}
|
}
|
||||||
return nameservers.build();
|
return nameservers.build();
|
||||||
|
|
|
@ -29,13 +29,15 @@ import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.domain.DomainBase;
|
import google.registry.model.domain.DomainBase;
|
||||||
import google.registry.model.domain.token.AllocationToken;
|
import google.registry.model.domain.token.AllocationToken;
|
||||||
import google.registry.model.reporting.HistoryEntry;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
|
import google.registry.testing.DualDatabaseTest;
|
||||||
|
import google.registry.testing.TestSqlOnly;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
/** Unit tests for {@link GetAllocationTokenCommand}. */
|
/** Unit tests for {@link GetAllocationTokenCommand}. */
|
||||||
|
@DualDatabaseTest
|
||||||
class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCommand> {
|
class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCommand> {
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testSuccess_oneToken() throws Exception {
|
void testSuccess_oneToken() throws Exception {
|
||||||
createTlds("bar");
|
createTlds("bar");
|
||||||
AllocationToken token =
|
AllocationToken token =
|
||||||
|
@ -49,7 +51,7 @@ class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCo
|
||||||
assertInStdout(token.toString(), "Token foo was not redeemed.");
|
assertInStdout(token.toString(), "Token foo was not redeemed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testSuccess_multipleTokens() throws Exception {
|
void testSuccess_multipleTokens() throws Exception {
|
||||||
createTlds("baz");
|
createTlds("baz");
|
||||||
ImmutableList<AllocationToken> tokens =
|
ImmutableList<AllocationToken> tokens =
|
||||||
|
@ -73,7 +75,7 @@ class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCo
|
||||||
"Token fii was not redeemed.");
|
"Token fii was not redeemed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testSuccess_redeemedToken() throws Exception {
|
void testSuccess_redeemedToken() throws Exception {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
|
@ -93,7 +95,7 @@ class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCo
|
||||||
"Token foo was redeemed to create domain fqqdn.tld at 2016-04-07T22:19:17.044Z.");
|
"Token foo was redeemed to create domain fqqdn.tld at 2016-04-07T22:19:17.044Z.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testSuccess_oneTokenDoesNotExist() throws Exception {
|
void testSuccess_oneTokenDoesNotExist() throws Exception {
|
||||||
createTlds("bar");
|
createTlds("bar");
|
||||||
AllocationToken token =
|
AllocationToken token =
|
||||||
|
@ -108,7 +110,7 @@ class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCo
|
||||||
token.toString(), "Token foo was not redeemed.", "ERROR: Token bar does not exist.");
|
token.toString(), "Token foo was not redeemed.", "ERROR: Token bar does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testFailure_noAllocationTokensSpecified() {
|
void testFailure_noAllocationTokensSpecified() {
|
||||||
assertThrows(ParameterException.class, this::runCommand);
|
assertThrows(ParameterException.class, this::runCommand);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,14 @@ import google.registry.model.domain.secdns.DelegationSignerData;
|
||||||
import google.registry.model.eppcommon.StatusValue;
|
import google.registry.model.eppcommon.StatusValue;
|
||||||
import google.registry.model.host.HostResource;
|
import google.registry.model.host.HostResource;
|
||||||
import google.registry.persistence.VKey;
|
import google.registry.persistence.VKey;
|
||||||
|
import google.registry.testing.DualDatabaseTest;
|
||||||
|
import google.registry.testing.TestSqlOnly;
|
||||||
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
|
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
/** Unit tests for {@link UniformRapidSuspensionCommand}. */
|
/** Unit tests for {@link UniformRapidSuspensionCommand}. */
|
||||||
|
@DualDatabaseTest
|
||||||
class UniformRapidSuspensionCommandTest
|
class UniformRapidSuspensionCommandTest
|
||||||
extends EppToolCommandTestCase<UniformRapidSuspensionCommand> {
|
extends EppToolCommandTestCase<UniformRapidSuspensionCommand> {
|
||||||
|
|
||||||
|
@ -72,7 +74,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
domainBase.asBuilder().setNameservers(hostRefs.build()).setDsData(dsData).build());
|
domainBase.asBuilder().setNameservers(hostRefs.build()).setDsData(dsData).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testCommand_addsLocksReplacesHostsAndDsDataPrintsUndo() throws Exception {
|
void testCommand_addsLocksReplacesHostsAndDsDataPrintsUndo() throws Exception {
|
||||||
persistDomainWithHosts(defaultDomainBase, defaultDsData, ns1, ns2);
|
persistDomainWithHosts(defaultDomainBase, defaultDsData, ns1, ns2);
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
@ -93,7 +95,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertNotInStdout("--restore_client_hold");
|
assertNotInStdout("--restore_client_hold");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testCommand_respectsExistingHost() throws Exception {
|
void testCommand_respectsExistingHost() throws Exception {
|
||||||
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs2, ns1);
|
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs2, ns1);
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
@ -111,7 +113,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertNotInStdout("--locks_to_preserve");
|
assertNotInStdout("--locks_to_preserve");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testCommand_generatesUndoForUndelegatedDomain() throws Exception {
|
void testCommand_generatesUndoForUndelegatedDomain() throws Exception {
|
||||||
persistActiveDomain("evil.tld");
|
persistActiveDomain("evil.tld");
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
@ -124,7 +126,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertNotInStdout("--locks_to_preserve");
|
assertNotInStdout("--locks_to_preserve");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testCommand_generatesUndoWithLocksToPreserve() throws Exception {
|
void testCommand_generatesUndoWithLocksToPreserve() throws Exception {
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("evil.tld").asBuilder()
|
newDomainBase("evil.tld").asBuilder()
|
||||||
|
@ -137,7 +139,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertInStdout("--locks_to_preserve serverDeleteProhibited");
|
assertInStdout("--locks_to_preserve serverDeleteProhibited");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testCommand_removeClientHold() throws Exception {
|
void testCommand_removeClientHold() throws Exception {
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("evil.tld")
|
newDomainBase("evil.tld")
|
||||||
|
@ -162,7 +164,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertInStdout("--restore_client_hold");
|
assertInStdout("--restore_client_hold");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testUndo_removesLocksReplacesHostsAndDsData() throws Exception {
|
void testUndo_removesLocksReplacesHostsAndDsData() throws Exception {
|
||||||
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2);
|
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2);
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
@ -178,7 +180,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertNotInStdout("--undo"); // Undo shouldn't print a new undo command.
|
assertNotInStdout("--undo"); // Undo shouldn't print a new undo command.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testUndo_respectsLocksToPreserveFlag() throws Exception {
|
void testUndo_respectsLocksToPreserveFlag() throws Exception {
|
||||||
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2);
|
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2);
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
@ -195,7 +197,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertNotInStdout("--undo"); // Undo shouldn't print a new undo command.
|
assertNotInStdout("--undo"); // Undo shouldn't print a new undo command.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testUndo_restoresClientHolds() throws Exception {
|
void testUndo_restoresClientHolds() throws Exception {
|
||||||
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2);
|
persistDomainWithHosts(defaultDomainBase, defaultDsData, urs1, urs2);
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
@ -212,7 +214,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertNotInStdout("--undo"); // Undo shouldn't print a new undo command.
|
assertNotInStdout("--undo"); // Undo shouldn't print a new undo command.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testAutorenews_setToFalseByDefault() throws Exception {
|
void testAutorenews_setToFalseByDefault() throws Exception {
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("evil.tld")
|
newDomainBase("evil.tld")
|
||||||
|
@ -224,7 +226,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertInStdout("<superuser:autorenews>false</superuser:autorenews>");
|
assertInStdout("<superuser:autorenews>false</superuser:autorenews>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testAutorenews_setToTrueWhenUndo() throws Exception {
|
void testAutorenews_setToTrueWhenUndo() throws Exception {
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("evil.tld")
|
newDomainBase("evil.tld")
|
||||||
|
@ -241,7 +243,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertInStdout("<superuser:autorenews>true</superuser:autorenews>");
|
assertInStdout("<superuser:autorenews>true</superuser:autorenews>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testRenewOneYearWithoutUndo_verifyReasonWithoutUndo() throws Exception {
|
void testRenewOneYearWithoutUndo_verifyReasonWithoutUndo() throws Exception {
|
||||||
persistDomainWithHosts(
|
persistDomainWithHosts(
|
||||||
newDomainBase("evil.tld")
|
newDomainBase("evil.tld")
|
||||||
|
@ -278,7 +280,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
.verifySentAny();
|
.verifySentAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testRenewOneYearWithUndo_verifyReasonWithUndo() throws Exception {
|
void testRenewOneYearWithUndo_verifyReasonWithUndo() throws Exception {
|
||||||
persistDomainWithHosts(
|
persistDomainWithHosts(
|
||||||
newDomainBase("evil.tld")
|
newDomainBase("evil.tld")
|
||||||
|
@ -316,7 +318,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
.verifySentAny();
|
.verifySentAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testRenewOneYear_verifyBothRenewAndUpdateFlowsAreTriggered() throws Exception {
|
void testRenewOneYear_verifyBothRenewAndUpdateFlowsAreTriggered() throws Exception {
|
||||||
persistDomainWithHosts(
|
persistDomainWithHosts(
|
||||||
newDomainBase("evil.tld")
|
newDomainBase("evil.tld")
|
||||||
|
@ -361,7 +363,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
eppVerifier.verifyNoMoreSent();
|
eppVerifier.verifyNoMoreSent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testFailure_locksToPreserveWithoutUndo() {
|
void testFailure_locksToPreserveWithoutUndo() {
|
||||||
persistActiveDomain("evil.tld");
|
persistActiveDomain("evil.tld");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -375,7 +377,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertThat(thrown).hasMessageThat().contains("--undo");
|
assertThat(thrown).hasMessageThat().contains("--undo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testFailure_domainNameRequired() {
|
void testFailure_domainNameRequired() {
|
||||||
persistActiveDomain("evil.tld");
|
persistActiveDomain("evil.tld");
|
||||||
ParameterException thrown =
|
ParameterException thrown =
|
||||||
|
@ -387,7 +389,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertThat(thrown).hasMessageThat().contains("--domain_name");
|
assertThat(thrown).hasMessageThat().contains("--domain_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testFailure_renewOneYearRequired() {
|
void testFailure_renewOneYearRequired() {
|
||||||
persistActiveDomain("evil.tld");
|
persistActiveDomain("evil.tld");
|
||||||
ParameterException thrown =
|
ParameterException thrown =
|
||||||
|
@ -395,7 +397,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertThat(thrown).hasMessageThat().contains("--renew_one_year");
|
assertThat(thrown).hasMessageThat().contains("--renew_one_year");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testFailure_extraFieldInDsData() {
|
void testFailure_extraFieldInDsData() {
|
||||||
persistActiveDomain("evil.tld");
|
persistActiveDomain("evil.tld");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -409,7 +411,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
.contains("dsRecord 1 1 1 abc 1 should have 4 parts, but has 5");
|
.contains("dsRecord 1 1 1 abc 1 should have 4 parts, but has 5");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testFailure_missingFieldInDsData() {
|
void testFailure_missingFieldInDsData() {
|
||||||
persistActiveDomain("evil.tld");
|
persistActiveDomain("evil.tld");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -421,7 +423,7 @@ class UniformRapidSuspensionCommandTest
|
||||||
assertThat(thrown).hasMessageThat().contains("dsRecord 1 1 1 should have 4 parts, but has 3");
|
assertThat(thrown).hasMessageThat().contains("dsRecord 1 1 1 should have 4 parts, but has 3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestSqlOnly
|
||||||
void testFailure_malformedDsData() {
|
void testFailure_malformedDsData() {
|
||||||
persistActiveDomain("evil.tld");
|
persistActiveDomain("evil.tld");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue