diff --git a/javatests/google/registry/flows/FlowTestCase.java b/javatests/google/registry/flows/FlowTestCase.java index 12e0858f3..d6920d16e 100644 --- a/javatests/google/registry/flows/FlowTestCase.java +++ b/javatests/google/registry/flows/FlowTestCase.java @@ -83,6 +83,7 @@ public abstract class FlowTestCase extends ShardableTestCase { @Rule public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastore() + .withMemcache() .withTaskQueue() .build(); diff --git a/javatests/google/registry/testing/AppEngineRule.java b/javatests/google/registry/testing/AppEngineRule.java index 8a0f4343a..404e9a12b 100644 --- a/javatests/google/registry/testing/AppEngineRule.java +++ b/javatests/google/registry/testing/AppEngineRule.java @@ -21,6 +21,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.json.XML.toJSONObject; import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; +import com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig; import com.google.appengine.tools.development.testing.LocalModulesServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestConfig; import com.google.appengine.tools.development.testing.LocalServiceTestHelper; @@ -95,6 +96,7 @@ public final class AppEngineRule extends ExternalResource { private boolean withDatastore; private boolean withLocalModules; + private boolean withMemcache; private boolean withTaskQueue; private boolean withUserService; private boolean withUrlFetch; @@ -120,6 +122,12 @@ public final class AppEngineRule extends ExternalResource { return this; } + /** Turn on the use of local modules. */ + public Builder withMemcache() { + rule.withMemcache = true; + return this; + } + /** Turn on the task queue service. */ public Builder withTaskQueue() { @@ -273,6 +281,9 @@ public final class AppEngineRule extends ExternalResource { .addBasicScalingModuleVersion("tools", "1", 1) .addBasicScalingModuleVersion("backend", "1", 1)); } + if (withMemcache) { + configs.add(new LocalMemcacheServiceTestConfig()); + } if (withTaskQueue) { File queueFile = temporaryFolder.newFile("queue.xml"); Files.asCharSink(queueFile, UTF_8).write(taskQueueXml); diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index 37e5369ec..9b6ace72a 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -819,8 +819,10 @@ public class DatastoreHelper { public void vrun() { saveResource(resource, wantBackup); }}); - // Force the session to be cleared so that when we read it back, we read from Datastore - // and not from the transaction cache or memcache. + // Force the session cache to be cleared so that when we read the resource back, we read from + // Datastore (or memcache) and not from the session cache. This is needed to trigger Objectify's + // load process (unmarshalling entity protos to POJOs, nulling out empty collections, calling + // @OnLoad methods, etc.) which is bypassed for entities loaded from the session cache. ofy().clearSessionCache(); return ofy().load().entity(resource).now(); }