mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +02:00
Make Registry.get(tld) hit memcache explicitly.
TESTED=The test fails if you change line 134 in Ofy to not use memcache and use the unchanged original Registry.get() code. This is the expected behavior. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=154226534
This commit is contained in:
parent
9e61f1d6ef
commit
4eba2ea07a
2 changed files with 17 additions and 1 deletions
|
@ -250,7 +250,7 @@ public class Registry extends ImmutableObject implements Buildable {
|
||||||
@Override
|
@Override
|
||||||
public Registry run() {
|
public Registry run() {
|
||||||
return ofy()
|
return ofy()
|
||||||
.load()
|
.loadWithMemcache()
|
||||||
.key(Key.create(getCrossTldKey(), Registry.class, tld))
|
.key(Key.create(getCrossTldKey(), Registry.class, tld))
|
||||||
.now();
|
.now();
|
||||||
}}));
|
}}));
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.DatastoreHelper.newRegistry;
|
import static google.registry.testing.DatastoreHelper.newRegistry;
|
||||||
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
||||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||||
|
import static google.registry.testing.MemcacheHelper.setMemcacheContents;
|
||||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
import static org.joda.money.CurrencyUnit.EUR;
|
import static org.joda.money.CurrencyUnit.EUR;
|
||||||
|
@ -33,6 +34,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSortedMap;
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.EntityTestCase;
|
import google.registry.model.EntityTestCase;
|
||||||
|
import google.registry.model.ofy.RequestCapturingAsyncDatastoreService;
|
||||||
import google.registry.model.registry.Registry.RegistryNotFoundException;
|
import google.registry.model.registry.Registry.RegistryNotFoundException;
|
||||||
import google.registry.model.registry.Registry.TldState;
|
import google.registry.model.registry.Registry.TldState;
|
||||||
import google.registry.model.registry.label.PremiumList;
|
import google.registry.model.registry.label.PremiumList;
|
||||||
|
@ -478,4 +480,18 @@ public class RegistryTest extends EntityTestCase {
|
||||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadHitsMemcache() {
|
||||||
|
Registry registry = Registry.get("tld");
|
||||||
|
// In unit tests the in-memory cache has a duration of 0, so even without this line we should
|
||||||
|
// expect this to hit memcache. Nevertheless, remove it from the cache explicitly so that if the
|
||||||
|
// unit test caching is ever set to nonzero this won't spuriously pass.
|
||||||
|
registry.invalidateInCache();
|
||||||
|
setMemcacheContents(Key.create(getCrossTldKey(), Registry.class, "tld"));
|
||||||
|
int numPreviousReads = RequestCapturingAsyncDatastoreService.getReads().size();
|
||||||
|
Registry.get("tld");
|
||||||
|
int numReadsForGet = RequestCapturingAsyncDatastoreService.getReads().size() - numPreviousReads;
|
||||||
|
assertThat(numReadsForGet).isEqualTo(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue