From cadf9d4af22ea2d8880f0f63e18176ada42495cc Mon Sep 17 00:00:00 2001 From: mcilwain Date: Wed, 7 Sep 2016 08:58:15 -0700 Subject: [PATCH] Use smaller shard size in ClaimsListShardTest The default production value of 10,000 was unnecessarily large for testing purposes. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132441792 --- {docs => g3doc}/app-engine-architecture.md | 0 {docs => g3doc}/code-structure.md | 0 {docs => g3doc}/configuration.md | 0 {docs => g3doc}/developing.md | 0 {docs => g3doc}/extension-points.md | 0 {docs => g3doc}/install.md | 0 {docs => g3doc}/registry-tool.md | 0 .../registry/model/tmch/ClaimsListShard.java | 7 +++++-- .../registry/model/tmch/ClaimsListShardTest.java | 15 ++++++++++++--- 9 files changed, 17 insertions(+), 5 deletions(-) rename {docs => g3doc}/app-engine-architecture.md (100%) rename {docs => g3doc}/code-structure.md (100%) rename {docs => g3doc}/configuration.md (100%) rename {docs => g3doc}/developing.md (100%) rename {docs => g3doc}/extension-points.md (100%) rename {docs => g3doc}/install.md (100%) rename {docs => g3doc}/registry-tool.md (100%) diff --git a/docs/app-engine-architecture.md b/g3doc/app-engine-architecture.md similarity index 100% rename from docs/app-engine-architecture.md rename to g3doc/app-engine-architecture.md diff --git a/docs/code-structure.md b/g3doc/code-structure.md similarity index 100% rename from docs/code-structure.md rename to g3doc/code-structure.md diff --git a/docs/configuration.md b/g3doc/configuration.md similarity index 100% rename from docs/configuration.md rename to g3doc/configuration.md diff --git a/docs/developing.md b/g3doc/developing.md similarity index 100% rename from docs/developing.md rename to g3doc/developing.md diff --git a/docs/extension-points.md b/g3doc/extension-points.md similarity index 100% rename from docs/extension-points.md rename to g3doc/extension-points.md diff --git a/docs/install.md b/g3doc/install.md similarity index 100% rename from docs/install.md rename to g3doc/install.md diff --git a/docs/registry-tool.md b/g3doc/registry-tool.md similarity index 100% rename from docs/registry-tool.md rename to g3doc/registry-tool.md diff --git a/java/google/registry/model/tmch/ClaimsListShard.java b/java/google/registry/model/tmch/ClaimsListShard.java index 58d106b61..23ac8569b 100644 --- a/java/google/registry/model/tmch/ClaimsListShard.java +++ b/java/google/registry/model/tmch/ClaimsListShard.java @@ -44,6 +44,7 @@ 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 java.util.HashMap; import java.util.List; import java.util.Map; @@ -69,8 +70,10 @@ 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 - public static final int SHARD_SIZE = 10000; + @NonFinalForTesting + static int shardSize = 10000; @Id long id; @@ -159,7 +162,7 @@ public class ClaimsListShard extends ImmutableObject { final Key parentKey = ClaimsListRevision.createKey(); // Save the ClaimsList shards in separate transactions. - Concurrent.transform(CollectionUtils.partitionMap(labelsToKeys, SHARD_SIZE), + Concurrent.transform(CollectionUtils.partitionMap(labelsToKeys, shardSize), new Function, ClaimsListShard>() { @Override public ClaimsListShard apply(final ImmutableMap labelsToKeysShard) { diff --git a/javatests/google/registry/model/tmch/ClaimsListShardTest.java b/javatests/google/registry/model/tmch/ClaimsListShardTest.java index 351de6e76..a9dacd829 100644 --- a/javatests/google/registry/model/tmch/ClaimsListShardTest.java +++ b/javatests/google/registry/model/tmch/ClaimsListShardTest.java @@ -26,10 +26,12 @@ import google.registry.model.tmch.ClaimsListShard.ClaimsListRevision; import google.registry.model.tmch.ClaimsListShard.UnshardedSaveException; import google.registry.testing.AppEngineRule; import google.registry.testing.ExceptionRule; +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; @@ -47,7 +49,13 @@ public class ClaimsListShardTest { @Rule public final ExceptionRule thrown = new ExceptionRule(); - protected final DateTime now = DateTime.now(UTC); + @Rule + public final InjectRule inject = new InjectRule(); + + @Before + public void before() throws Exception { + inject.setStaticField(ClaimsListShard.class, "shardSize", 10); + } @Test public void test_unshardedSaveFails() throws Exception { @@ -73,9 +81,10 @@ public class ClaimsListShardTest { public void test_savesAndGets_withSharding() throws Exception { // Create a ClaimsList that will need 4 shards to save. Map labelsToKeys = new HashMap<>(); - for (int i = 0; i <= ClaimsListShard.SHARD_SIZE * 3; i++) { + for (int i = 0; i <= ClaimsListShard.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(); @@ -88,7 +97,7 @@ public class ClaimsListShardTest { // Create a smaller ClaimsList that will need only 2 shards to save. labelsToKeys = new HashMap<>(); - for (int i = 0; i <= ClaimsListShard.SHARD_SIZE; i++) { + for (int i = 0; i <= ClaimsListShard.shardSize; i++) { labelsToKeys.put(Integer.toString(i), Integer.toString(i)); } unsharded = ClaimsListShard.create(now.plusDays(1), ImmutableMap.copyOf(labelsToKeys));