Cache Registrars in memory

This replaces the memcache caching, which we think is overall a bad idea.
We load all registrars at once instead of caching each as needed, so that
the loadAllCached() methods can be cached as well, and therefore will
always produce results consistent with loadByClientIdCached()'s view of the
registrar's values. All of our prod registrars together total 300k of data
right now, so this is hardly worth optimizing further, and in any case this
will likely reduce latency even further since most requests will be
served out of memory.

While I was in the Registrar file I standardized the error messages for incorrect
password and clientId length to be the same format, and cleaned up a few
random things I noticed in the code.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=156151828
This commit is contained in:
cgoldfeder 2017-05-16 00:42:49 -07:00 committed by Ben McIlwain
parent 9a48aae107
commit c9d7e75946
17 changed files with 149 additions and 179 deletions

View file

@ -142,19 +142,19 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testFailure_passwordNull() throws Exception {
thrown.expect(IllegalArgumentException.class, "Password must be [6,16] characters long.");
thrown.expect(IllegalArgumentException.class, "Password must be 6-16 characters long.");
new Registrar.Builder().setPassword(null);
}
@Test
public void testFailure_passwordTooShort() throws Exception {
thrown.expect(IllegalArgumentException.class, "Password must be [6,16] characters long.");
thrown.expect(IllegalArgumentException.class, "Password must be 6-16 characters long.");
new Registrar.Builder().setPassword("abcde");
}
@Test
public void testFailure_passwordTooLong() throws Exception {
thrown.expect(IllegalArgumentException.class, "Password must be [6,16] characters long.");
thrown.expect(IllegalArgumentException.class, "Password must be 6-16 characters long.");
new Registrar.Builder().setPassword("abcdefghijklmnopq");
}
@ -397,11 +397,11 @@ public class RegistrarTest extends EntityTestCase {
}
@Test
public void testLoadByClientId_isTransactionless() {
public void testLoadByClientIdCached_isTransactionless() {
ofy().transact(new VoidWork() {
@Override
public void vrun() {
assertThat(Registrar.loadByClientId("registrar")).isNotNull();
assertThat(Registrar.loadByClientIdCached("registrar")).isNotNull();
// Load something as a control to make sure we are seeing loaded keys in the session cache.
ofy().load().entity(abuseAdminContact).now();
assertThat(ofy().getSessionKeys()).contains(Key.create(abuseAdminContact));
@ -409,7 +409,7 @@ public class RegistrarTest extends EntityTestCase {
}});
ofy().clearSessionCache();
// Conversely, loads outside of a transaction should end up in the session cache.
assertThat(Registrar.loadByClientId("registrar")).isNotNull();
assertThat(Registrar.loadByClientIdCached("registrar")).isNotNull();
assertThat(ofy().getSessionKeys()).contains(Key.create(registrar));
}
}