mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 03:57:51 +02:00
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:
parent
4652688585
commit
cadf9d4af2
9 changed files with 17 additions and 5 deletions
|
@ -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<ClaimsListRevision> 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<ImmutableMap<String, String>, ClaimsListShard>() {
|
||||
@Override
|
||||
public ClaimsListShard apply(final ImmutableMap<String, String> labelsToKeysShard) {
|
||||
|
|
|
@ -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<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));
|
||||
}
|
||||
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));
|
||||
|
|
Loading…
Add table
Reference in a new issue