mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 20:23:24 +02:00
Use DomainHistoryVKey to restore symmetric VKey (#874)
* Use DomainHistoryVKey to restore symmetric VKey * Rebase on HEAD
This commit is contained in:
parent
ab7ee51fb2
commit
1d91a8e647
27 changed files with 871 additions and 621 deletions
|
@ -71,7 +71,7 @@ import google.registry.model.registry.Registry;
|
|||
import google.registry.model.registry.Registry.TldState;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.persistence.DomainHistoryVKey;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -169,7 +169,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
|
|||
new AllocationToken.Builder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(SINGLE_USE)
|
||||
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1L, historyEntryKey))
|
||||
.setRedemptionHistoryEntry(DomainHistoryVKey.create(historyEntryKey))
|
||||
.build());
|
||||
doCheckTest(
|
||||
create(false, "example1.tld", "In use"),
|
||||
|
|
|
@ -162,7 +162,7 @@ import google.registry.model.reporting.DomainTransactionRecord;
|
|||
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.monitoring.whitebox.EppMetric;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.persistence.DomainHistoryVKey;
|
||||
import google.registry.testing.ReplayExtension;
|
||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||
import java.math.BigDecimal;
|
||||
|
@ -505,7 +505,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
new AllocationToken.Builder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(SINGLE_USE)
|
||||
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 505L, historyEntryKey))
|
||||
.setRedemptionHistoryEntry(DomainHistoryVKey.create(historyEntryKey))
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
EppException thrown =
|
||||
|
@ -528,7 +528,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
HistoryEntry historyEntry =
|
||||
ofy().load().type(HistoryEntry.class).ancestor(reloadResourceByForeignKey()).first().now();
|
||||
assertThat(ofy().load().entity(token).now().getRedemptionHistoryEntry())
|
||||
.hasValue(HistoryEntry.createVKey(Key.create(historyEntry)));
|
||||
.hasValue(DomainHistoryVKey.create(Key.create(historyEntry)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1275,7 +1275,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
assertThat(reloadedToken.isRedeemed()).isTrue();
|
||||
assertThat(reloadedToken.getRedemptionHistoryEntry())
|
||||
.hasValue(
|
||||
HistoryEntry.createVKey(
|
||||
DomainHistoryVKey.create(
|
||||
Key.create(getHistoryEntries(reloadResourceByForeignKey()).get(0))));
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ import google.registry.model.domain.token.AllocationToken;
|
|||
import google.registry.model.domain.token.AllocationToken.TokenStatus;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.persistence.DomainHistoryVKey;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -198,7 +198,7 @@ class AllocationTokenFlowUtilsTest {
|
|||
new AllocationToken.Builder()
|
||||
.setToken("tokeN")
|
||||
.setTokenType(SINGLE_USE)
|
||||
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 101L, historyEntryKey))
|
||||
.setRedemptionHistoryEntry(DomainHistoryVKey.create(historyEntryKey))
|
||||
.build());
|
||||
assertThat(
|
||||
flowUtils
|
||||
|
|
|
@ -40,6 +40,7 @@ import google.registry.model.domain.DomainBase;
|
|||
import google.registry.model.domain.token.AllocationToken.TokenStatus;
|
||||
import google.registry.model.domain.token.AllocationToken.TokenType;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.persistence.DomainHistoryVKey;
|
||||
import google.registry.persistence.VKey;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -85,7 +86,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
persistResource(
|
||||
new AllocationToken.Builder()
|
||||
.setToken("abc123Single")
|
||||
.setRedemptionHistoryEntry(HistoryEntry.createVKey(historyEntryKey))
|
||||
.setRedemptionHistoryEntry(DomainHistoryVKey.create(historyEntryKey))
|
||||
.setDomainName("example.foo")
|
||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||
.setTokenType(SINGLE_USE)
|
||||
|
@ -124,7 +125,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
new AllocationToken.Builder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(SINGLE_USE)
|
||||
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1L, historyEntryKey))
|
||||
.setRedemptionHistoryEntry(DomainHistoryVKey.create(historyEntryKey))
|
||||
.setDomainName("blahdomain.foo")
|
||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||
.build()),
|
||||
|
@ -230,7 +231,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
new AllocationToken.Builder()
|
||||
.setToken("foobar")
|
||||
.setTokenType(TokenType.UNLIMITED_USE)
|
||||
.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1L, historyEntryKey));
|
||||
.setRedemptionHistoryEntry(DomainHistoryVKey.create(historyEntryKey));
|
||||
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
|
|
|
@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
|||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
import google.registry.model.ofy.CommitLogCheckpoint;
|
||||
import google.registry.model.ofy.CommitLogCheckpointRoot;
|
||||
|
@ -64,12 +65,16 @@ public class VKeyTranslatorFactoryTest {
|
|||
|
||||
@Test
|
||||
void testEntityWithAncestor() {
|
||||
Key<HistoryEntry> key =
|
||||
Key.create(Key.create(DomainBase.class, "ROID-1"), HistoryEntry.class, 101);
|
||||
VKey<HistoryEntry> vkey = VKeyTranslatorFactory.createVKey(key);
|
||||
assertThat(vkey.getKind()).isEqualTo(HistoryEntry.class);
|
||||
assertThat(vkey.getOfyKey()).isEqualTo(key);
|
||||
assertThat(vkey.getSqlKey()).isEqualTo("DomainBase/ROID-1/101");
|
||||
Key<DomainBase> domainKey = Key.create(DomainBase.class, "ROID-1");
|
||||
Key<HistoryEntry> historyEntryKey = Key.create(domainKey, HistoryEntry.class, 10L);
|
||||
Key<BillingEvent.OneTime> oneTimeKey =
|
||||
Key.create(historyEntryKey, BillingEvent.OneTime.class, 200L);
|
||||
|
||||
VKey<BillingEvent.OneTime> vkey = VKeyTranslatorFactory.createVKey(oneTimeKey);
|
||||
|
||||
assertThat(vkey.getKind()).isEqualTo(BillingEvent.OneTime.class);
|
||||
assertThat(vkey.getOfyKey()).isEqualTo(oneTimeKey);
|
||||
assertThat(vkey.getSqlKey()).isEqualTo(200L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.persistence;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import com.googlecode.objectify.annotation.Parent;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.common.EntityGroupRoot;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
import google.registry.model.domain.DomainHistory.DomainHistoryId;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.schema.replay.EntityTest.EntityForTesting;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import javax.persistence.Transient;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit test for {@link DomainHistoryVKey}. */
|
||||
@DualDatabaseTest
|
||||
class DomainHistoryVKeyTest {
|
||||
|
||||
@RegisterExtension
|
||||
final AppEngineExtension appEngine =
|
||||
AppEngineExtension.builder()
|
||||
.withDatastoreAndCloudSql()
|
||||
.withOfyTestEntities(TestEntity.class)
|
||||
.withJpaUnitTestEntities(TestEntity.class)
|
||||
.build();
|
||||
|
||||
@TestOfyAndSql
|
||||
void testRestoreSymmetricVKey() {
|
||||
Key<HistoryEntry> ofyKey =
|
||||
Key.create(Key.create(DomainBase.class, "domainRepoId"), HistoryEntry.class, 10L);
|
||||
DomainHistoryVKey domainHistoryVKey = DomainHistoryVKey.create(ofyKey);
|
||||
TestEntity original = new TestEntity(domainHistoryVKey);
|
||||
tm().transact(() -> tm().insert(original));
|
||||
TestEntity persisted = tm().transact(() -> tm().load(original.createVKey()));
|
||||
assertThat(persisted).isEqualTo(original);
|
||||
// Double check that the persisted.domainHistoryVKey is a symmetric VKey
|
||||
assertThat(persisted.domainHistoryVKey.getKind()).isEqualTo(HistoryEntry.class);
|
||||
assertThat(persisted.domainHistoryVKey.getOfyKey())
|
||||
.isEqualTo(
|
||||
Key.create(Key.create(DomainBase.class, "domainRepoId"), HistoryEntry.class, 10L));
|
||||
assertThat(persisted.domainHistoryVKey.getSqlKey())
|
||||
.isEqualTo(new DomainHistoryId("domainRepoId", 10L));
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testCreateSymmetricVKeyFromOfyKey() {
|
||||
Key<HistoryEntry> ofyKey =
|
||||
Key.create(Key.create(DomainBase.class, "domainRepoId"), HistoryEntry.class, 10L);
|
||||
DomainHistoryVKey domainHistoryVKey = DomainHistoryVKey.create(ofyKey);
|
||||
assertThat(domainHistoryVKey.getKind()).isEqualTo(HistoryEntry.class);
|
||||
assertThat(domainHistoryVKey.getOfyKey()).isEqualTo(ofyKey);
|
||||
assertThat(domainHistoryVKey.getSqlKey()).isEqualTo(new DomainHistoryId("domainRepoId", 10L));
|
||||
}
|
||||
|
||||
@EntityForTesting
|
||||
@Entity
|
||||
@javax.persistence.Entity(name = "TestEntity")
|
||||
private static class TestEntity extends ImmutableObject {
|
||||
@Transient @Parent Key<EntityGroupRoot> parent = getCrossTldKey();
|
||||
|
||||
@Id @javax.persistence.Id String id = "id";
|
||||
|
||||
DomainHistoryVKey domainHistoryVKey;
|
||||
|
||||
TestEntity() {}
|
||||
|
||||
TestEntity(DomainHistoryVKey domainHistoryVKey) {
|
||||
this.domainHistoryVKey = domainHistoryVKey;
|
||||
}
|
||||
|
||||
VKey<TestEntity> createVKey() {
|
||||
return VKey.create(TestEntity.class, id, Key.create(parent, TestEntity.class, id));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ import google.registry.model.domain.DomainBase;
|
|||
import google.registry.model.domain.token.AllocationToken;
|
||||
import google.registry.model.domain.token.AllocationToken.TokenType;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.persistence.DomainHistoryVKey;
|
||||
import java.util.Collection;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -173,7 +173,7 @@ class DeleteAllocationTokensCommandTest extends CommandTestCase<DeleteAllocation
|
|||
String domainToPersist = domainName != null ? domainName : "example.foo";
|
||||
DomainBase domain = persistActiveDomain(domainToPersist);
|
||||
Key<HistoryEntry> historyEntryKey = Key.create(Key.create(domain), HistoryEntry.class, 1051L);
|
||||
builder.setRedemptionHistoryEntry(VKey.create(HistoryEntry.class, 1051L, historyEntryKey));
|
||||
builder.setRedemptionHistoryEntry(DomainHistoryVKey.create(historyEntryKey));
|
||||
}
|
||||
return persistResource(builder.build());
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ import com.google.common.collect.Iterables;
|
|||
import com.google.common.io.Files;
|
||||
import google.registry.model.domain.token.AllocationToken;
|
||||
import google.registry.model.domain.token.AllocationToken.TokenStatus;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.persistence.DomainHistoryVKey;
|
||||
import google.registry.testing.DeterministicStringGenerator;
|
||||
import google.registry.testing.DeterministicStringGenerator.Rule;
|
||||
import google.registry.testing.FakeClock;
|
||||
|
@ -314,7 +313,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
|
|||
|
||||
private AllocationToken createToken(
|
||||
String token,
|
||||
@Nullable VKey<HistoryEntry> redemptionHistoryEntry,
|
||||
@Nullable DomainHistoryVKey redemptionHistoryEntry,
|
||||
@Nullable String domainName) {
|
||||
AllocationToken.Builder builder =
|
||||
new AllocationToken.Builder().setToken(token).setTokenType(SINGLE_USE);
|
||||
|
|
|
@ -28,7 +28,7 @@ import com.google.common.collect.ImmutableList;
|
|||
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.persistence.DomainHistoryVKey;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -85,7 +85,7 @@ class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocationTokenCo
|
|||
.setTokenType(SINGLE_USE)
|
||||
.setDomainName("fqqdn.tld")
|
||||
.setRedemptionHistoryEntry(
|
||||
HistoryEntry.createVKey(Key.create(createHistoryEntryForEppResource(domain))))
|
||||
DomainHistoryVKey.create(Key.create(createHistoryEntryForEppResource(domain))))
|
||||
.build());
|
||||
runCommand("foo");
|
||||
assertInStdout(
|
||||
|
|
|
@ -344,7 +344,7 @@ class google.registry.model.domain.token.AllocationToken {
|
|||
google.registry.model.UpdateAutoTimestamp updateTimestamp;
|
||||
google.registry.model.common.TimedTransitionProperty<google.registry.model.domain.token.AllocationToken$TokenStatus, google.registry.model.domain.token.AllocationToken$TokenStatusTransition> tokenStatusTransitions;
|
||||
google.registry.model.domain.token.AllocationToken$TokenType tokenType;
|
||||
google.registry.persistence.VKey<google.registry.model.reporting.HistoryEntry> redemptionHistoryEntry;
|
||||
google.registry.persistence.DomainHistoryVKey redemptionHistoryEntry;
|
||||
int discountYears;
|
||||
java.lang.String domainName;
|
||||
java.util.Set<java.lang.String> allowedClientIds;
|
||||
|
@ -908,3 +908,10 @@ enum google.registry.model.transfer.TransferStatus {
|
|||
SERVER_APPROVED;
|
||||
SERVER_CANCELLED;
|
||||
}
|
||||
class google.registry.persistence.DomainHistoryVKey {
|
||||
com.googlecode.objectify.Key<T> ofyKey;
|
||||
java.lang.Class<? extends T> kind;
|
||||
java.lang.Long domainHistoryId;
|
||||
java.lang.Object sqlKey;
|
||||
java.lang.String domainRepoId;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue