Make Registrar.loadByClientId explicitly use memcache

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154712979
This commit is contained in:
cgoldfeder 2017-05-01 06:56:59 -07:00 committed by Ben McIlwain
parent f9df4cf3f1
commit 386d2bc6be
2 changed files with 13 additions and 2 deletions

View file

@ -863,7 +863,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
return ofy().doTransactionless(new Work<Registrar>() { return ofy().doTransactionless(new Work<Registrar>() {
@Override @Override
public Registrar run() { public Registrar run() {
return ofy().load() return ofy().loadWithMemcache()
.type(Registrar.class) .type(Registrar.class)
.parent(getCrossTldKey()) .parent(getCrossTldKey())
.id(clientId) .id(clientId)

View file

@ -1,4 +1,4 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved. // Copyright 2017 The Nomulus Authors. All Rights Reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResource; import static google.registry.testing.DatastoreHelper.persistSimpleResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResources; import static google.registry.testing.DatastoreHelper.persistSimpleResources;
import static google.registry.testing.MemcacheHelper.setMemcacheContents;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -34,6 +35,7 @@ import com.googlecode.objectify.Key;
import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.VoidWork;
import google.registry.model.EntityTestCase; import google.registry.model.EntityTestCase;
import google.registry.model.common.EntityGroupRoot; import google.registry.model.common.EntityGroupRoot;
import google.registry.model.ofy.RequestCapturingAsyncDatastoreService;
import google.registry.model.registrar.Registrar.State; import google.registry.model.registrar.Registrar.State;
import google.registry.model.registrar.Registrar.Type; import google.registry.model.registrar.Registrar.Type;
import google.registry.testing.ExceptionRule; import google.registry.testing.ExceptionRule;
@ -394,4 +396,13 @@ public class RegistrarTest extends EntityTestCase {
assertThat(Registrar.loadByClientId("registrar")).isNotNull(); assertThat(Registrar.loadByClientId("registrar")).isNotNull();
assertThat(ofy().getSessionKeys()).contains(Key.create(registrar)); assertThat(ofy().getSessionKeys()).contains(Key.create(registrar));
} }
@Test
public void testLoadByClientId_usesMemcache() {
setMemcacheContents(Key.create(registrar));
int numPreviousReads = RequestCapturingAsyncDatastoreService.getReads().size();
Registrar.loadByClientId("registrar");
int numReadsInLoad = RequestCapturingAsyncDatastoreService.getReads().size() - numPreviousReads;
assertThat(numReadsInLoad).isEqualTo(0);
}
} }