mirror of
https://github.com/google/nomulus
synced 2026-01-09 23:47:49 +00:00
Test that marshaling a domain only does one datastore fetch.
This is true even though the domain has three fields (a contact, a host, and the registrant) whose foreign keys need to be loaded. This CL also adds the generic ability to do these sort of tests elsewhere in the code, by instrumenting the datastore instance used by Objectify to store static counts of method calls. TESTED=patched in a rollback of [] and confirmed that the test failed because there were three reads. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123885768
This commit is contained in:
@@ -20,6 +20,8 @@ import static com.google.common.base.Predicates.not;
|
||||
import static com.googlecode.objectify.ObjectifyService.factory;
|
||||
import static google.registry.util.TypeUtils.hasAnnotation;
|
||||
|
||||
import com.google.appengine.api.datastore.AsyncDatastoreService;
|
||||
import com.google.appengine.api.datastore.DatastoreServiceConfig;
|
||||
import com.google.appengine.api.datastore.DatastoreServiceFactory;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -99,6 +101,16 @@ public class ObjectifyService {
|
||||
@Override
|
||||
public Objectify begin() {
|
||||
return new SessionKeyExposingObjectify(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AsyncDatastoreService createRawAsyncDatastoreService(DatastoreServiceConfig cfg) {
|
||||
// In the unit test environment, wrap the datastore service in a proxy that can be used to
|
||||
// examine the number of requests sent to datastore.
|
||||
AsyncDatastoreService service = super.createRawAsyncDatastoreService(cfg);
|
||||
return RegistryEnvironment.get().equals(RegistryEnvironment.UNITTEST)
|
||||
? new RequestCountingAsyncDatastoreService(service)
|
||||
: service;
|
||||
}});
|
||||
|
||||
// Translators must be registered before any entities can be registered.
|
||||
|
||||
Reference in New Issue
Block a user