diff --git a/core/src/main/java/google/registry/schema/tmch/ClaimsListDao.java b/core/src/main/java/google/registry/model/tmch/ClaimsListDao.java similarity index 78% rename from core/src/main/java/google/registry/schema/tmch/ClaimsListDao.java rename to core/src/main/java/google/registry/model/tmch/ClaimsListDao.java index 5bbef7775..d0d377d80 100644 --- a/core/src/main/java/google/registry/schema/tmch/ClaimsListDao.java +++ b/core/src/main/java/google/registry/model/tmch/ClaimsListDao.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package google.registry.schema.tmch; +package google.registry.model.tmch; import static google.registry.config.RegistryConfig.getDomainLabelListCacheDuration; import static google.registry.model.CacheUtils.tryMemoizeWithExpiration; @@ -24,28 +24,28 @@ import google.registry.util.NonFinalForTesting; import java.util.Optional; import javax.persistence.EntityManager; -/** Data access object for {@link ClaimsList}. */ +/** Data access object for {@link ClaimsListShard}. */ public class ClaimsListDao { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); /** In-memory cache for claims list. */ @NonFinalForTesting - private static Supplier> cacheClaimsList = + private static Supplier> cacheClaimsList = tryMemoizeWithExpiration(getDomainLabelListCacheDuration(), ClaimsListDao::getLatestRevision); - private static void save(ClaimsList claimsList) { + private static void save(ClaimsListShard claimsList) { jpaTm().transact(() -> jpaTm().getEntityManager().persist(claimsList)); } /** - * Try to save the given {@link ClaimsList} into Cloud SQL. If the save fails, the error will be - * logged but no exception will be thrown. + * Try to save the given {@link ClaimsListShard} into Cloud SQL. If the save fails, the error will + * be logged but no exception will be thrown. * *

This method is used during the dual-write phase of database migration as Datastore is still * the authoritative database. */ - public static void trySave(ClaimsList claimsList) { + static void trySave(ClaimsListShard claimsList) { try { ClaimsListDao.save(claimsList); logger.atInfo().log( @@ -57,12 +57,12 @@ public class ClaimsListDao { } /** - * Returns the most recent revision of the {@link ClaimsList} in Cloud SQL, if it exists. + * Returns the most recent revision of the {@link ClaimsListShard} in Cloud SQL, if it exists. * TODO(shicong): Change this method to package level access after dual-read phase. * ClaimsListShard uses this method to retrieve claims list in Cloud SQL for the comparison, and * ClaimsListShard is not in this package. */ - public static Optional getLatestRevision() { + public static Optional getLatestRevision() { return jpaTm() .transact( () -> { @@ -73,15 +73,15 @@ public class ClaimsListDao { return em.createQuery( "FROM ClaimsList cl LEFT JOIN FETCH cl.labelsToKeys WHERE cl.revisionId =" + " :revisionId", - ClaimsList.class) + ClaimsListShard.class) .setParameter("revisionId", revisionId) .getResultStream() .findFirst(); }); } - /** Returns the most recent revision of the {@link ClaimsList}, from cache. */ - public static Optional getLatestRevisionCached() { + /** Returns the most recent revision of the {@link ClaimsListShard}, from cache. */ + public static Optional getLatestRevisionCached() { return cacheClaimsList.get(); } diff --git a/core/src/main/java/google/registry/model/tmch/ClaimsListShard.java b/core/src/main/java/google/registry/model/tmch/ClaimsListShard.java index 9b70e572b..98b4292a4 100644 --- a/core/src/main/java/google/registry/model/tmch/ClaimsListShard.java +++ b/core/src/main/java/google/registry/model/tmch/ClaimsListShard.java @@ -40,6 +40,7 @@ import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.OnSave; import com.googlecode.objectify.annotation.Parent; +import google.registry.model.CreateAutoTimestamp; import google.registry.model.ImmutableObject; import google.registry.model.annotations.NotBackedUp; import google.registry.model.annotations.NotBackedUp.Reason; @@ -47,8 +48,6 @@ import google.registry.model.annotations.VirtualEntity; import google.registry.model.common.CrossTldSingleton; import google.registry.schema.replay.DatastoreEntity; import google.registry.schema.replay.SqlEntity; -import google.registry.schema.tmch.ClaimsList; -import google.registry.schema.tmch.ClaimsListDao; import google.registry.util.CollectionUtils; import google.registry.util.Concurrent; import google.registry.util.Retrier; @@ -59,6 +58,15 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.Callable; import javax.annotation.Nullable; +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ElementCollection; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.JoinColumn; +import javax.persistence.MapKeyColumn; +import javax.persistence.Table; +import javax.persistence.Transient; import org.joda.time.DateTime; /** @@ -74,10 +82,21 @@ import org.joda.time.DateTime; * 10MB per transaction limit. * *

Therefore, it is never OK to save an instance of this class directly to Datastore. Instead you - * must use the {@link #save} method to do it for you. + * must use the {@link #saveToDatastore} method to do it for you. + * + *

Note that the primary key of this entity is {@link #revisionId}, which is auto-generated by + * the database. So, if a retry of insertion happens after the previous attempt unexpectedly + * succeeds, we will end up with having two exact same claims list with only different {@link + * #revisionId}. However, this is not an actual problem because we only use the claims list with + * highest {@link #revisionId}. + * + *

TODO(b/162007765): Rename the class to ClaimsList and remove Datastore related fields and + * methods. */ @Entity @NotBackedUp(reason = Reason.EXTERNALLY_SOURCED) +@javax.persistence.Entity(name = "ClaimsList") +@Table public class ClaimsListShard extends ImmutableObject implements DatastoreEntity { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); @@ -85,22 +104,44 @@ public class ClaimsListShard extends ImmutableObject implements DatastoreEntity /** The number of claims list entries to store per shard. */ private static final int SHARD_SIZE = 10000; - @Id - long id; + @Transient @Id long id; - @Parent - Key parent; + @Transient @Parent Key parent; - /** When the claims list was last updated. */ + @Ignore + @javax.persistence.Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + Long revisionId; + + @Ignore + @Column(nullable = false) + CreateAutoTimestamp creationTimestamp = CreateAutoTimestamp.create(null); + + /** + * When the claims list was last updated. + * + *

Note that the value of this field is parsed from the claims list file(See this RFC), it is + * the DNL List creation datetime from the rfc. Since this field has been used by Datastore, we + * cannot change its name until we finish the migration. + * + *

TODO(b/166784536): Rename this field to tmdbGenerationTime. + */ + @Column(name = "tmdb_generation_time", nullable = false) DateTime creationTime; /** A map from labels to claims keys. */ @EmbedMap + @ElementCollection + @CollectionTable( + name = "ClaimsEntry", + joinColumns = @JoinColumn(name = "revisionId", referencedColumnName = "revisionId")) + @MapKeyColumn(name = "domainLabel", nullable = false) + @Column(name = "claimKey", nullable = false) Map labelsToKeys; /** Indicates that this is a shard rather than a "full" list. */ - @Ignore - boolean isShard = false; + @Ignore @Transient boolean isShard = false; private static final Retrier LOADER_RETRIER = new Retrier(new SystemSleeper(), 2); @@ -164,10 +205,10 @@ public class ClaimsListShard extends ImmutableObject implements DatastoreEntity return datastoreList; }; - private static final void loadAndCompareCloudSqlList(ClaimsListShard datastoreList) { - Optional maybeCloudSqlList = ClaimsListDao.getLatestRevision(); + private static void loadAndCompareCloudSqlList(ClaimsListShard datastoreList) { + Optional maybeCloudSqlList = ClaimsListDao.getLatestRevision(); if (maybeCloudSqlList.isPresent()) { - ClaimsList cloudSqlList = maybeCloudSqlList.get(); + ClaimsListShard cloudSqlList = maybeCloudSqlList.get(); MapDifference diff = Maps.difference(datastoreList.labelsToKeys, cloudSqlList.getLabelsToKeys()); if (!diff.areEqual()) { @@ -206,15 +247,34 @@ public class ClaimsListShard extends ImmutableObject implements DatastoreEntity memoizeWithShortExpiration( () -> LOADER_RETRIER.callWithRetry(LOADER_CALLABLE, IllegalStateException.class)); - public DateTime getCreationTime() { + /** Returns the revision id of this claims list, or throws exception if it is null. */ + public Long getRevisionId() { + checkState( + revisionId != null, "revisionId is null because it is not persisted in the database"); + return revisionId; + } + + /** + * Returns the time when the external TMDB service generated this revision of the claims list. + * + * @see DNL List + * creation datetime + */ + public DateTime getTmdbGenerationTime() { return creationTime; } + /** Returns the creation time of this claims list. */ + public DateTime getCreationTimestamp() { + return creationTimestamp.getTimestamp(); + } + /** Returns the claim key for a given domain if there is one, empty otherwise. */ public Optional getClaimKey(String label) { return Optional.ofNullable(labelsToKeys.get(label)); } + /** Returns an {@link Map} mapping domain label to its lookup key. */ public ImmutableMap getLabelsToKeys() { return ImmutableMap.copyOf(labelsToKeys); } @@ -229,11 +289,12 @@ public class ClaimsListShard extends ImmutableObject implements DatastoreEntity * switching over to using them atomically, then deleting the old ones. */ public void save() { - save(SHARD_SIZE); + saveToDatastore(SHARD_SIZE); + ClaimsListDao.trySave(this); } @VisibleForTesting - void save(int shardSize) { + void saveToDatastore(int shardSize) { // Figure out what the next versionId should be based on which ones already exist. final Key oldRevision = getCurrentRevision(); final Key parentKey = ClaimsListRevision.createKey(); @@ -270,10 +331,11 @@ public class ClaimsListShard extends ImmutableObject implements DatastoreEntity }); } - public static ClaimsListShard create(DateTime creationTime, Map labelsToKeys) { + public static ClaimsListShard create( + DateTime tmdbGenerationTime, Map labelsToKeys) { ClaimsListShard instance = new ClaimsListShard(); instance.id = allocateId(); - instance.creationTime = checkNotNull(creationTime); + instance.creationTime = checkNotNull(tmdbGenerationTime); instance.labelsToKeys = checkNotNull(labelsToKeys); return instance; } diff --git a/core/src/main/java/google/registry/schema/tmch/ClaimsList.java b/core/src/main/java/google/registry/schema/tmch/ClaimsList.java deleted file mode 100644 index 2d023fa9b..000000000 --- a/core/src/main/java/google/registry/schema/tmch/ClaimsList.java +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2019 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.schema.tmch; - -import static com.google.common.base.Preconditions.checkState; -import static google.registry.util.DateTimeUtils.toJodaDateTime; -import static google.registry.util.DateTimeUtils.toZonedDateTime; - -import com.google.common.collect.ImmutableList; -import google.registry.model.CreateAutoTimestamp; -import google.registry.model.ImmutableObject; -import google.registry.schema.replay.DatastoreEntity; -import google.registry.schema.replay.SqlEntity; -import java.time.ZonedDateTime; -import java.util.Map; -import java.util.Optional; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.MapKeyColumn; -import javax.persistence.Table; -import org.joda.time.DateTime; - -/** - * A list of TMCH claims labels and their associated claims keys. - * - *

Note that the primary key of this entity is {@link #revisionId}, which is auto-generated by - * the database. So, if a retry of insertion happens after the previous attempt unexpectedly - * succeeds, we will end up with having two exact same claims list with only different {@link - * #revisionId}. However, this is not an actual problem because we only use the claims list with - * highest {@link #revisionId}. - */ -@Entity -@Table -public class ClaimsList extends ImmutableObject implements SqlEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column - private Long revisionId; - - @Column(nullable = false) - private CreateAutoTimestamp creationTimestamp = CreateAutoTimestamp.create(null); - - @Column(nullable = false) - private ZonedDateTime tmdbGenerationTime; - - @ElementCollection - @CollectionTable( - name = "ClaimsEntry", - joinColumns = @JoinColumn(name = "revisionId", referencedColumnName = "revisionId")) - @MapKeyColumn(name = "domainLabel", nullable = false) - @Column(name = "claimKey", nullable = false) - private Map labelsToKeys; - - private ClaimsList(ZonedDateTime tmdbGenerationTime, Map labelsToKeys) { - this.tmdbGenerationTime = tmdbGenerationTime; - this.labelsToKeys = labelsToKeys; - } - - // Hibernate requires this default constructor. - private ClaimsList() {} - - /** Constructs a {@link ClaimsList} object. */ - public static ClaimsList create(DateTime creationTimestamp, Map labelsToKeys) { - return new ClaimsList(toZonedDateTime(creationTimestamp), labelsToKeys); - } - - /** Returns the revision id of this claims list, or throws exception if it is null. */ - public Long getRevisionId() { - checkState( - revisionId != null, "revisionId is null because it is not persisted in the database"); - return revisionId; - } - - /** Returns the TMDB generation time of this claims list. */ - public DateTime getTmdbGenerationTime() { - return toJodaDateTime(tmdbGenerationTime); - } - - /** Returns the creation time of this claims list. */ - public DateTime getCreationTimestamp() { - return creationTimestamp.getTimestamp(); - } - - /** Returns an {@link Map} mapping domain label to its lookup key. */ - public Map getLabelsToKeys() { - return labelsToKeys; - } - - /** Returns the claim key for a given domain if there is one, empty otherwise. */ - public Optional getClaimKey(String label) { - return Optional.ofNullable(labelsToKeys.get(label)); - } - - @Override - public ImmutableList toDatastoreEntities() { - return ImmutableList.of(); // ClaimsList is dual-written - } -} diff --git a/core/src/main/java/google/registry/tmch/ClaimsListParser.java b/core/src/main/java/google/registry/tmch/ClaimsListParser.java index 25813e98c..b2b83dcc9 100644 --- a/core/src/main/java/google/registry/tmch/ClaimsListParser.java +++ b/core/src/main/java/google/registry/tmch/ClaimsListParser.java @@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMap; -import google.registry.schema.tmch.ClaimsList; +import google.registry.model.tmch.ClaimsListShard; import java.util.List; import org.joda.time.DateTime; @@ -34,11 +34,11 @@ import org.joda.time.DateTime; public class ClaimsListParser { /** - * Converts the lines from the DNL CSV file into a {@link ClaimsList} object. + * Converts the lines from the DNL CSV file into a {@link ClaimsListShard} object. * *

Please note that this does not insert the object into Datastore. */ - public static ClaimsList parse(List lines) { + public static ClaimsListShard parse(List lines) { ImmutableMap.Builder builder = new ImmutableMap.Builder<>(); // First line: , @@ -74,6 +74,6 @@ public class ClaimsListParser { builder.put(label, lookupKey); } - return ClaimsList.create(creationTime, builder.build()); + return ClaimsListShard.create(creationTime, builder.build()); } } diff --git a/core/src/main/java/google/registry/tmch/TmchDnlAction.java b/core/src/main/java/google/registry/tmch/TmchDnlAction.java index 15586e37d..dbf7a8256 100644 --- a/core/src/main/java/google/registry/tmch/TmchDnlAction.java +++ b/core/src/main/java/google/registry/tmch/TmchDnlAction.java @@ -21,8 +21,6 @@ import google.registry.keyring.api.KeyModule.Key; import google.registry.model.tmch.ClaimsListShard; import google.registry.request.Action; import google.registry.request.auth.Auth; -import google.registry.schema.tmch.ClaimsList; -import google.registry.schema.tmch.ClaimsListDao; import java.io.IOException; import java.security.SignatureException; import java.util.List; @@ -56,14 +54,10 @@ public final class TmchDnlAction implements Runnable { } catch (SignatureException | IOException | PGPException e) { throw new RuntimeException(e); } - ClaimsList claims = ClaimsListParser.parse(lines); - ClaimsListShard claimsListShard = - ClaimsListShard.create(claims.getTmdbGenerationTime(), claims.getLabelsToKeys()); - claimsListShard.save(); + ClaimsListShard claims = ClaimsListParser.parse(lines); + claims.save(); logger.atInfo().log( "Inserted %,d claims into Datastore, created at %s", - claimsListShard.size(), claimsListShard.getCreationTime()); - - ClaimsListDao.trySave(claims); + claims.size(), claims.getTmdbGenerationTime()); } } diff --git a/core/src/main/java/google/registry/tools/UploadClaimsListCommand.java b/core/src/main/java/google/registry/tools/UploadClaimsListCommand.java index 0fadada12..14a797748 100644 --- a/core/src/main/java/google/registry/tools/UploadClaimsListCommand.java +++ b/core/src/main/java/google/registry/tools/UploadClaimsListCommand.java @@ -22,8 +22,6 @@ import com.beust.jcommander.Parameters; import com.google.common.base.Joiner; import com.google.common.io.Files; import google.registry.model.tmch.ClaimsListShard; -import google.registry.schema.tmch.ClaimsList; -import google.registry.schema.tmch.ClaimsListDao; import google.registry.tmch.ClaimsListParser; import java.io.File; import java.io.IOException; @@ -39,7 +37,7 @@ final class UploadClaimsListCommand extends ConfirmingCommand implements Command private String claimsListFilename; - private ClaimsList claimsList; + private ClaimsListShard claimsList; @Override protected void init() throws IOException { @@ -58,8 +56,7 @@ final class UploadClaimsListCommand extends ConfirmingCommand implements Command @Override public String execute() { - ClaimsListShard.create(claimsList.getTmdbGenerationTime(), claimsList.getLabelsToKeys()).save(); - ClaimsListDao.trySave(claimsList); + claimsList.save(); return String.format("Successfully uploaded claims list %s", claimsListFilename); } } diff --git a/core/src/main/resources/META-INF/persistence.xml b/core/src/main/resources/META-INF/persistence.xml index ebaa1940c..d43c8e56c 100644 --- a/core/src/main/resources/META-INF/persistence.xml +++ b/core/src/main/resources/META-INF/persistence.xml @@ -53,8 +53,8 @@ google.registry.model.registry.label.PremiumList google.registry.model.reporting.Spec11ThreatMatch google.registry.persistence.transaction.TransactionEntity + google.registry.model.tmch.ClaimsListShard google.registry.schema.domain.RegistryLock - google.registry.schema.tmch.ClaimsList google.registry.schema.cursor.Cursor google.registry.schema.server.Lock google.registry.schema.tld.PremiumEntry diff --git a/core/src/test/java/google/registry/schema/tmch/ClaimsListDaoTest.java b/core/src/test/java/google/registry/model/tmch/ClaimsListDaoTest.java similarity index 73% rename from core/src/test/java/google/registry/schema/tmch/ClaimsListDaoTest.java rename to core/src/test/java/google/registry/model/tmch/ClaimsListDaoTest.java index 372762a35..589f40f1c 100644 --- a/core/src/test/java/google/registry/schema/tmch/ClaimsListDaoTest.java +++ b/core/src/test/java/google/registry/model/tmch/ClaimsListDaoTest.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package google.registry.schema.tmch; +package google.registry.model.tmch; import static com.google.common.truth.Truth.assertThat; @@ -40,20 +40,22 @@ public class ClaimsListDaoTest { @Test void trySave_insertsClaimsListSuccessfully() { - ClaimsList claimsList = - ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2")); + ClaimsListShard claimsList = + ClaimsListShard.create( + fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2")); ClaimsListDao.trySave(claimsList); - ClaimsList insertedClaimsList = ClaimsListDao.getLatestRevision().get(); + ClaimsListShard insertedClaimsList = ClaimsListDao.getLatestRevision().get(); assertClaimsListEquals(claimsList, insertedClaimsList); assertThat(insertedClaimsList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc()); } @Test void trySave_noExceptionThrownWhenSaveFail() { - ClaimsList claimsList = - ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2")); + ClaimsListShard claimsList = + ClaimsListShard.create( + fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2")); ClaimsListDao.trySave(claimsList); - ClaimsList insertedClaimsList = ClaimsListDao.getLatestRevision().get(); + ClaimsListShard insertedClaimsList = ClaimsListDao.getLatestRevision().get(); assertClaimsListEquals(claimsList, insertedClaimsList); // Save ClaimsList with existing revisionId should fail because revisionId is the primary key. ClaimsListDao.trySave(insertedClaimsList); @@ -61,9 +63,9 @@ public class ClaimsListDaoTest { @Test void trySave_claimsListWithNoEntries() { - ClaimsList claimsList = ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of()); + ClaimsListShard claimsList = ClaimsListShard.create(fakeClock.nowUtc(), ImmutableMap.of()); ClaimsListDao.trySave(claimsList); - ClaimsList insertedClaimsList = ClaimsListDao.getLatestRevision().get(); + ClaimsListShard insertedClaimsList = ClaimsListDao.getLatestRevision().get(); assertClaimsListEquals(claimsList, insertedClaimsList); assertThat(insertedClaimsList.getLabelsToKeys()).isEmpty(); } @@ -75,16 +77,18 @@ public class ClaimsListDaoTest { @Test void getCurrent_returnsLatestClaims() { - ClaimsList oldClaimsList = - ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2")); - ClaimsList newClaimsList = - ClaimsList.create(fakeClock.nowUtc(), ImmutableMap.of("label3", "key3", "label4", "key4")); + ClaimsListShard oldClaimsList = + ClaimsListShard.create( + fakeClock.nowUtc(), ImmutableMap.of("label1", "key1", "label2", "key2")); + ClaimsListShard newClaimsList = + ClaimsListShard.create( + fakeClock.nowUtc(), ImmutableMap.of("label3", "key3", "label4", "key4")); ClaimsListDao.trySave(oldClaimsList); ClaimsListDao.trySave(newClaimsList); assertClaimsListEquals(newClaimsList, ClaimsListDao.getLatestRevision().get()); } - private void assertClaimsListEquals(ClaimsList left, ClaimsList right) { + private void assertClaimsListEquals(ClaimsListShard left, ClaimsListShard right) { assertThat(left.getRevisionId()).isEqualTo(right.getRevisionId()); assertThat(left.getTmdbGenerationTime()).isEqualTo(right.getTmdbGenerationTime()); assertThat(left.getLabelsToKeys()).isEqualTo(right.getLabelsToKeys()); diff --git a/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java b/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java index cabdd0f88..b3fdf7795 100644 --- a/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java +++ b/core/src/test/java/google/registry/model/tmch/ClaimsListShardTest.java @@ -76,7 +76,7 @@ public class ClaimsListShardTest { DateTime now = DateTime.now(UTC); // Save it with sharding, and make sure that reloading it works. ClaimsListShard unsharded = ClaimsListShard.create(now, ImmutableMap.copyOf(labelsToKeys)); - unsharded.save(shardSize); + unsharded.saveToDatastore(shardSize); assertThat(ClaimsListShard.get().labelsToKeys).isEqualTo(unsharded.labelsToKeys); List shards1 = ofy().load().type(ClaimsListShard.class).list(); assertThat(shards1).hasSize(4); @@ -90,7 +90,7 @@ public class ClaimsListShardTest { labelsToKeys.put(Integer.toString(i), Integer.toString(i)); } unsharded = ClaimsListShard.create(now.plusDays(1), ImmutableMap.copyOf(labelsToKeys)); - unsharded.save(shardSize); + unsharded.saveToDatastore(shardSize); ofy().clearSessionCache(); assertThat(ClaimsListShard.get().labelsToKeys).hasSize(unsharded.labelsToKeys.size()); assertThat(ClaimsListShard.get().labelsToKeys).isEqualTo(unsharded.labelsToKeys); diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java index cac2e3fd5..d07902db5 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerRuleTest.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import google.registry.model.ImmutableObject; import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension; -import google.registry.schema.tmch.ClaimsList; import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; @@ -36,9 +35,7 @@ public class JpaTransactionManagerRuleTest { @RegisterExtension public final JpaUnitTestExtension jpaExtension = - new JpaTestRules.Builder() - .withEntityClass(ClaimsList.class, TestEntity.class) - .buildUnitTestRule(); + new JpaTestRules.Builder().withEntityClass(TestEntity.class).buildUnitTestRule(); @Test void verifiesRuleWorks() { @@ -58,7 +55,7 @@ public class JpaTransactionManagerRuleTest { List results = jpaTm() .getEntityManager() - .createNativeQuery("SELECT * FROM \"ClaimsList\"") + .createNativeQuery("SELECT * FROM \"TestEntity\"") .getResultList(); assertThat(results).isEmpty(); }); diff --git a/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java b/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java index 9c1a3d814..2aedfaa1f 100644 --- a/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java +++ b/core/src/test/java/google/registry/schema/integration/SqlIntegrationTestSuite.java @@ -27,6 +27,7 @@ import google.registry.model.poll.PollMessageTest; import google.registry.model.registry.RegistryLockDaoTest; import google.registry.model.registry.label.ReservedListSqlDaoTest; import google.registry.model.reporting.Spec11ThreatMatchTest; +import google.registry.model.tmch.ClaimsListDaoTest; import google.registry.persistence.transaction.JpaEntityCoverageExtension; import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension; import google.registry.schema.cursor.CursorDaoTest; @@ -35,7 +36,6 @@ import google.registry.schema.integration.SqlIntegrationTestSuite.BeforeSuiteTes import google.registry.schema.registrar.RegistrarDaoTest; import google.registry.schema.server.LockDaoTest; import google.registry.schema.tld.PremiumListDaoTest; -import google.registry.schema.tmch.ClaimsListDaoTest; import google.registry.testing.AppEngineExtension; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; diff --git a/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java b/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java index c3f888cc8..c1cd59e02 100644 --- a/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java +++ b/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java @@ -50,7 +50,8 @@ class TmchDnlActionTest extends TmchActionTestCase { // Make sure the contents of testdata/dnl-latest.csv got inserted into the database. ClaimsListShard claimsList = ClaimsListShard.get(); - assertThat(claimsList.getCreationTime()).isEqualTo(DateTime.parse("2013-11-24T23:15:37.4Z")); + assertThat(claimsList.getTmdbGenerationTime()) + .isEqualTo(DateTime.parse("2013-11-24T23:15:37.4Z")); assertThat(claimsList.getClaimKey("xn----7sbejwbn3axu3d")) .hasValue("2013112500/7/4/8/dIHW0DiuybvhdP8kIz"); assertThat(claimsList.getClaimKey("lolcat")).isEmpty(); diff --git a/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java b/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java index f5204d52f..5fa5529b0 100644 --- a/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java +++ b/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java @@ -37,7 +37,8 @@ class UploadClaimsListCommandTest extends CommandTestCase