diff --git a/java/google/registry/model/tmch/ClaimsListShard.java b/java/google/registry/model/tmch/ClaimsListShard.java index eeefc76c7..db507acdd 100644 --- a/java/google/registry/model/tmch/ClaimsListShard.java +++ b/java/google/registry/model/tmch/ClaimsListShard.java @@ -39,7 +39,6 @@ import google.registry.model.annotations.VirtualEntity; import google.registry.model.common.CrossTldSingleton; import google.registry.util.CollectionUtils; import google.registry.util.Concurrent; -import google.registry.util.NonFinalForTesting; import google.registry.util.Retrier; import google.registry.util.SystemSleeper; import java.util.HashMap; @@ -69,10 +68,8 @@ import org.joda.time.DateTime; @NotBackedUp(reason = Reason.EXTERNALLY_SOURCED) public class ClaimsListShard extends ImmutableObject { - /** The number of claims list entries to store per shard. Do not modify except for in tests. */ - @VisibleForTesting - @NonFinalForTesting - static int shardSize = 10000; + /** The number of claims list entries to store per shard. */ + private static final int SHARD_SIZE = 10000; @Id long id; @@ -165,6 +162,11 @@ public class ClaimsListShard extends ImmutableObject { * switching over to using them atomically, then deleting the old ones. */ public void save() { + save(SHARD_SIZE); + } + + @VisibleForTesting + void save(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(); diff --git a/javatests/google/registry/model/tmch/ClaimsListShardTest.java b/javatests/google/registry/model/tmch/ClaimsListShardTest.java index 6f7902b0a..8ea80936b 100644 --- a/javatests/google/registry/model/tmch/ClaimsListShardTest.java +++ b/javatests/google/registry/model/tmch/ClaimsListShardTest.java @@ -26,12 +26,10 @@ import com.googlecode.objectify.Key; import google.registry.model.tmch.ClaimsListShard.ClaimsListRevision; import google.registry.model.tmch.ClaimsListShard.UnshardedSaveException; import google.registry.testing.AppEngineRule; -import google.registry.testing.InjectRule; import java.util.HashMap; import java.util.List; import java.util.Map; import org.joda.time.DateTime; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,13 +44,7 @@ public class ClaimsListShardTest { .withDatastore() .build(); - @Rule - public final InjectRule inject = new InjectRule(); - - @Before - public void before() { - inject.setStaticField(ClaimsListShard.class, "shardSize", 10); - } + private final int shardSize = 10; @Test public void test_unshardedSaveFails() { @@ -81,13 +73,13 @@ public class ClaimsListShardTest { public void test_savesAndGets_withSharding() { // Create a ClaimsList that will need 4 shards to save. Map labelsToKeys = new HashMap<>(); - for (int i = 0; i <= ClaimsListShard.shardSize * 3; i++) { + for (int i = 0; i <= shardSize * 3; i++) { labelsToKeys.put(Integer.toString(i), Integer.toString(i)); } 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(); + unsharded.save(shardSize); assertThat(ClaimsListShard.get().labelsToKeys).isEqualTo(unsharded.labelsToKeys); List shards1 = ofy().load().type(ClaimsListShard.class).list(); assertThat(shards1).hasSize(4); @@ -97,11 +89,11 @@ public class ClaimsListShardTest { // Create a smaller ClaimsList that will need only 2 shards to save. labelsToKeys = new HashMap<>(); - for (int i = 0; i <= ClaimsListShard.shardSize; i++) { + for (int i = 0; i <= shardSize; i++) { labelsToKeys.put(Integer.toString(i), Integer.toString(i)); } unsharded = ClaimsListShard.create(now.plusDays(1), ImmutableMap.copyOf(labelsToKeys)); - unsharded.save(); + unsharded.save(shardSize); ofy().clearSessionCache(); assertThat(ClaimsListShard.get().labelsToKeys).hasSize(unsharded.labelsToKeys.size()); assertThat(ClaimsListShard.get().labelsToKeys).isEqualTo(unsharded.labelsToKeys);