1
0
mirror of https://github.com/google/nomulus synced 2026-02-10 06:50:30 +00:00

Always use Cloud SQL as primary for ClaimsList (#1127)

* Always use Cloud SQL as primary for ClaimsList

* Add a test back
This commit is contained in:
sarahcaseybot
2021-05-10 16:47:34 -04:00
committed by GitHub
parent 984f1118e3
commit 65be65fb24
2 changed files with 33 additions and 110 deletions

View File

@@ -16,23 +16,14 @@ package google.registry.model.tmch;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import google.registry.config.RegistryEnvironment;
import google.registry.model.EntityTestCase;
import google.registry.model.common.DatabaseTransitionSchedule;
import google.registry.model.common.DatabaseTransitionSchedule.PrimaryDatabase;
import google.registry.model.common.DatabaseTransitionSchedule.PrimaryDatabaseTransition;
import google.registry.model.common.DatabaseTransitionSchedule.TransitionId;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.testing.SystemPropertyExtension;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -44,64 +35,25 @@ public class ClaimsListDualDatabaseDaoTest extends EntityTestCase {
@Order(value = Integer.MAX_VALUE)
final SystemPropertyExtension systemPropertyExtension = new SystemPropertyExtension();
@BeforeEach
void beforeEach() {
DatabaseTransitionSchedule schedule =
DatabaseTransitionSchedule.create(
TransitionId.CLAIMS_LIST,
TimedTransitionProperty.fromValueMap(
ImmutableSortedMap.of(
START_OF_TIME,
PrimaryDatabase.DATASTORE,
fakeClock.nowUtc().plusDays(1),
PrimaryDatabase.CLOUD_SQL),
PrimaryDatabaseTransition.class));
tm().transactNew(() -> ofy().saveWithoutBackup().entity(schedule).now());
}
@Test
void testGetList_missingSql() {
createClaimsList().saveToDatastore();
assertThat(assertThrows(IllegalStateException.class, ClaimsListDualDatabaseDao::get))
.hasMessageThat()
.isEqualTo("Claims list found in primary DB but not in secondary DB.");
}
@Test
void testGetList_missingOfy() {
fakeClock.advanceBy(Duration.standardDays(5));
ClaimsListSqlDao.save(createClaimsList());
assertThat(assertThrows(IllegalStateException.class, ClaimsListDualDatabaseDao::get))
.hasMessageThat()
.isEqualTo("Claims list found in primary DB but not in secondary DB.");
}
@Test
void testGetList_fromOfy_different() {
createClaimsList().saveToDatastore();
ClaimsListSqlDao.save(
ClaimsListShard.create(fakeClock.nowUtc(), ImmutableMap.of("foo", "bar")));
assertThat(assertThrows(IllegalStateException.class, ClaimsListDualDatabaseDao::get))
.hasMessageThat()
.isEqualTo(
"Unequal claims lists detected:\n"
+ "Domain label label1 with key key1 only appears in the primary DB.\n"
+ "Domain label label2 with key key2 only appears in the primary DB.\n"
+ "Domain label foo with key bar only appears in the secondary DB.\n");
.isEqualTo("Claims list found in Cloud SQL but not in Datastore.");
}
@Test
void testGetList_fromSql_different() {
fakeClock.advanceBy(Duration.standardDays(5));
ClaimsListShard.create(fakeClock.nowUtc(), ImmutableMap.of("foo", "bar")).saveToDatastore();
ClaimsListSqlDao.save(createClaimsList());
assertThat(assertThrows(IllegalStateException.class, ClaimsListDualDatabaseDao::get))
.hasMessageThat()
.isEqualTo(
"Unequal claims lists detected:\n"
+ "Domain label label1 with key key1 only appears in the primary DB.\n"
+ "Domain label label2 with key key2 only appears in the primary DB.\n"
+ "Domain label foo with key bar only appears in the secondary DB.\n");
+ "Domain label label1 with key key1 only appears in Cloud SQL.\n"
+ "Domain label label2 with key key2 only appears in Cloud SQL.\n"
+ "Domain label foo with key bar only appears in Datastore.\n");
}
@Test
@@ -117,15 +69,6 @@ public class ClaimsListDualDatabaseDaoTest extends EntityTestCase {
assertThat(tm().transact(ClaimsListDualDatabaseDao::get).getLabelsToKeys()).isEmpty();
}
@Test
void testGetList_missingSql_notInTest() {
RegistryEnvironment.PRODUCTION.setup(systemPropertyExtension);
createClaimsList().saveToDatastore();
// Shouldn't fail in production
assertThat(ClaimsListDualDatabaseDao.get().getLabelsToKeys())
.isEqualTo(createClaimsList().getLabelsToKeys());
}
@Test
void testGetList_missingOfy_notInTest() {
RegistryEnvironment.PRODUCTION.setup(systemPropertyExtension);