mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02: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:
parent
07a89c8d05
commit
aa10792f73
3 changed files with 230 additions and 2 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue