From 386d2bc6be55c59bd0eb044f0c2378bdd550ed5d Mon Sep 17 00:00:00 2001 From: cgoldfeder Date: Mon, 1 May 2017 06:56:59 -0700 Subject: [PATCH] Make Registrar.loadByClientId explicitly use memcache ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=154712979 --- java/google/registry/model/registrar/Registrar.java | 2 +- .../registry/model/registrar/RegistrarTest.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/java/google/registry/model/registrar/Registrar.java b/java/google/registry/model/registrar/Registrar.java index 92410e874..c6a8d37f6 100644 --- a/java/google/registry/model/registrar/Registrar.java +++ b/java/google/registry/model/registrar/Registrar.java @@ -863,7 +863,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable return ofy().doTransactionless(new Work() { @Override public Registrar run() { - return ofy().load() + return ofy().loadWithMemcache() .type(Registrar.class) .parent(getCrossTldKey()) .id(clientId) diff --git a/javatests/google/registry/model/registrar/RegistrarTest.java b/javatests/google/registry/model/registrar/RegistrarTest.java index ed6122753..c0a6460b2 100644 --- a/javatests/google/registry/model/registrar/RegistrarTest.java +++ b/javatests/google/registry/model/registrar/RegistrarTest.java @@ -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"); // 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.persistSimpleResource; 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.ImmutableMap; @@ -34,6 +35,7 @@ import com.googlecode.objectify.Key; import com.googlecode.objectify.VoidWork; import google.registry.model.EntityTestCase; 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.Type; import google.registry.testing.ExceptionRule; @@ -394,4 +396,13 @@ public class RegistrarTest extends EntityTestCase { assertThat(Registrar.loadByClientId("registrar")).isNotNull(); 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); + } }