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
This commit is contained in:
mcilwain 2016-09-07 08:58:15 -07:00 committed by Ben McIlwain
parent 4652688585
commit cadf9d4af2
9 changed files with 17 additions and 5 deletions

View file

@ -44,6 +44,7 @@ import google.registry.model.annotations.VirtualEntity;
import google.registry.model.common.CrossTldSingleton; import google.registry.model.common.CrossTldSingleton;
import google.registry.util.CollectionUtils; import google.registry.util.CollectionUtils;
import google.registry.util.Concurrent; import google.registry.util.Concurrent;
import google.registry.util.NonFinalForTesting;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -69,8 +70,10 @@ import org.joda.time.DateTime;
@NotBackedUp(reason = Reason.EXTERNALLY_SOURCED) @NotBackedUp(reason = Reason.EXTERNALLY_SOURCED)
public class ClaimsListShard extends ImmutableObject { public class ClaimsListShard extends ImmutableObject {
/** The number of claims list entries to store per shard. Do not modify except for in tests. */
@VisibleForTesting @VisibleForTesting
public static final int SHARD_SIZE = 10000; @NonFinalForTesting
static int shardSize = 10000;
@Id @Id
long id; long id;
@ -159,7 +162,7 @@ public class ClaimsListShard extends ImmutableObject {
final Key<ClaimsListRevision> parentKey = ClaimsListRevision.createKey(); final Key<ClaimsListRevision> parentKey = ClaimsListRevision.createKey();
// Save the ClaimsList shards in separate transactions. // Save the ClaimsList shards in separate transactions.
Concurrent.transform(CollectionUtils.partitionMap(labelsToKeys, SHARD_SIZE), Concurrent.transform(CollectionUtils.partitionMap(labelsToKeys, shardSize),
new Function<ImmutableMap<String, String>, ClaimsListShard>() { new Function<ImmutableMap<String, String>, ClaimsListShard>() {
@Override @Override
public ClaimsListShard apply(final ImmutableMap<String, String> labelsToKeysShard) { public ClaimsListShard apply(final ImmutableMap<String, String> labelsToKeysShard) {

View file

@ -26,10 +26,12 @@ import google.registry.model.tmch.ClaimsListShard.ClaimsListRevision;
import google.registry.model.tmch.ClaimsListShard.UnshardedSaveException; import google.registry.model.tmch.ClaimsListShard.UnshardedSaveException;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule; import google.registry.testing.ExceptionRule;
import google.registry.testing.InjectRule;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -47,7 +49,13 @@ public class ClaimsListShardTest {
@Rule @Rule
public final ExceptionRule thrown = new ExceptionRule(); 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 @Test
public void test_unshardedSaveFails() throws Exception { public void test_unshardedSaveFails() throws Exception {
@ -73,9 +81,10 @@ public class ClaimsListShardTest {
public void test_savesAndGets_withSharding() throws Exception { public void test_savesAndGets_withSharding() throws Exception {
// Create a ClaimsList that will need 4 shards to save. // Create a ClaimsList that will need 4 shards to save.
Map<String, String> labelsToKeys = new HashMap<>(); Map<String, String> 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)); labelsToKeys.put(Integer.toString(i), Integer.toString(i));
} }
DateTime now = DateTime.now(UTC);
// Save it with sharding, and make sure that reloading it works. // Save it with sharding, and make sure that reloading it works.
ClaimsListShard unsharded = ClaimsListShard.create(now, ImmutableMap.copyOf(labelsToKeys)); ClaimsListShard unsharded = ClaimsListShard.create(now, ImmutableMap.copyOf(labelsToKeys));
unsharded.save(); unsharded.save();
@ -88,7 +97,7 @@ public class ClaimsListShardTest {
// Create a smaller ClaimsList that will need only 2 shards to save. // Create a smaller ClaimsList that will need only 2 shards to save.
labelsToKeys = new HashMap<>(); 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)); labelsToKeys.put(Integer.toString(i), Integer.toString(i));
} }
unsharded = ClaimsListShard.create(now.plusDays(1), ImmutableMap.copyOf(labelsToKeys)); unsharded = ClaimsListShard.create(now.plusDays(1), ImmutableMap.copyOf(labelsToKeys));