mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +02:00
Define TestRule that manages cache use in tests
All current tests that use caches with custom data expiry values now restore the default config when teardown. We need to prevent new unsafe uses from being introduced. Restoration code have also been added to a few other tests that modifies static fields. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=228888041
This commit is contained in:
parent
a6476862fd
commit
a80a44cd06
12 changed files with 231 additions and 53 deletions
|
@ -20,21 +20,25 @@ import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
|||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.testing.TestCacheRule;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
/** Unit tests for {@link EppResource}. */
|
||||
public class EppResourceTest extends EntityTestCase {
|
||||
|
||||
@Rule
|
||||
public final TestCacheRule testCacheRule =
|
||||
new TestCacheRule.Builder().withEppResourceCache(Duration.standardDays(1)).build();
|
||||
|
||||
@Test
|
||||
public void test_loadCached_ignoresContactChange() {
|
||||
setNonZeroCachingInterval();
|
||||
ContactResource originalContact = persistActiveContact("contact123");
|
||||
assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalContact))))
|
||||
.containsExactly(Key.create(originalContact), originalContact);
|
||||
|
@ -48,7 +52,6 @@ public class EppResourceTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void test_loadCached_ignoresHostChange() {
|
||||
setNonZeroCachingInterval();
|
||||
HostResource originalHost = persistActiveHost("ns1.example.com");
|
||||
assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalHost))))
|
||||
.containsExactly(Key.create(originalHost), originalHost);
|
||||
|
@ -60,8 +63,4 @@ public class EppResourceTest extends EntityTestCase {
|
|||
assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", clock.nowUtc()))
|
||||
.hasValue(modifiedHost);
|
||||
}
|
||||
|
||||
private static void setNonZeroCachingInterval() {
|
||||
EppResource.setCacheForTest(CacheBuilder.newBuilder().expireAfterWrite(1L, DAYS));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue