mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 12:13:19 +02:00
Stop dual read and dual write of SMDRL (#1095)
* Stop dual read and dual write of SMDRL * Remove some more stuff from SignedMarkRevocationListDaoTest * Change some names
This commit is contained in:
parent
fff95b20e6
commit
a0995fa0eb
3 changed files with 27 additions and 299 deletions
|
@ -16,39 +16,22 @@ package google.registry.model.smd;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.persistence.transaction.JpaTestRules;
|
||||
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageExtension;
|
||||
import google.registry.testing.DatastoreEntityExtension;
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.SystemPropertyExtension;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
@DualDatabaseTest
|
||||
public class SignedMarkRevocationListDaoTest extends EntityTestCase {
|
||||
|
||||
@RegisterExtension
|
||||
final JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
@RegisterExtension
|
||||
@Order(value = 1)
|
||||
final DatastoreEntityExtension datastoreEntityExtension = new DatastoreEntityExtension();
|
||||
|
||||
@RegisterExtension
|
||||
@Order(value = Integer.MAX_VALUE)
|
||||
final SystemPropertyExtension systemPropertyExtension = new SystemPropertyExtension();
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSave_cloudSqlPrimary_success() {
|
||||
@Test
|
||||
void testSave_success() {
|
||||
SignedMarkRevocationList list =
|
||||
SignedMarkRevocationList.create(
|
||||
fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1)));
|
||||
|
@ -57,8 +40,8 @@ public class SignedMarkRevocationListDaoTest extends EntityTestCase {
|
|||
assertAboutImmutableObjects().that(fromDb).isEqualExceptFields(list);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSaveAndLoad_cloudSqlPrimary_emptyList() {
|
||||
@Test
|
||||
void testSaveAndLoad_emptyList() {
|
||||
SignedMarkRevocationList list =
|
||||
SignedMarkRevocationList.create(fakeClock.nowUtc(), ImmutableMap.of());
|
||||
SignedMarkRevocationListDao.save(list);
|
||||
|
@ -66,8 +49,8 @@ public class SignedMarkRevocationListDaoTest extends EntityTestCase {
|
|||
assertAboutImmutableObjects().that(fromDb).isEqualExceptFields(list, "revisionId");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSave_cloudSqlPrimary_multipleVersions() {
|
||||
@Test
|
||||
void testSave_multipleVersions() {
|
||||
SignedMarkRevocationList list =
|
||||
SignedMarkRevocationList.create(
|
||||
fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1)));
|
||||
|
@ -83,52 +66,4 @@ public class SignedMarkRevocationListDaoTest extends EntityTestCase {
|
|||
.isFalse();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_cloudSqlPrimary_unequalLists() {
|
||||
fakeClock.setTo(DateTime.parse("1984-12-26T00:00:00.000Z"));
|
||||
SignedMarkRevocationList list =
|
||||
SignedMarkRevocationList.create(
|
||||
fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1)));
|
||||
SignedMarkRevocationListDao.save(list);
|
||||
SignedMarkRevocationList list2 =
|
||||
SignedMarkRevocationList.create(
|
||||
fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(3)));
|
||||
jpaTm().transact(() -> jpaTm().put(list2));
|
||||
RuntimeException thrown =
|
||||
assertThrows(RuntimeException.class, SignedMarkRevocationListDao::load);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"SMD mark has key 1984-12-25T21:00:00.000Z in Cloud SQL and key"
|
||||
+ " 1984-12-25T23:00:00.000Z in Datastore.");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_cloudSqlPrimary_unequalLists_succeedsInProduction() {
|
||||
RegistryEnvironment.PRODUCTION.setup(systemPropertyExtension);
|
||||
SignedMarkRevocationList list =
|
||||
SignedMarkRevocationList.create(
|
||||
fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1)));
|
||||
SignedMarkRevocationListDao.save(list);
|
||||
SignedMarkRevocationList list2 =
|
||||
SignedMarkRevocationList.create(
|
||||
fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(3)));
|
||||
jpaTm().transact(() -> jpaTm().put(list2));
|
||||
SignedMarkRevocationList fromDb = SignedMarkRevocationListDao.load();
|
||||
assertAboutImmutableObjects().that(fromDb).isEqualExceptFields(list2, "revisionId");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_cloudSqlPrimary_noListInDatastore() {
|
||||
SignedMarkRevocationList list =
|
||||
SignedMarkRevocationList.create(
|
||||
fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1)));
|
||||
jpaTm().transact(() -> jpaTm().put(list));
|
||||
RuntimeException thrown =
|
||||
assertThrows(RuntimeException.class, SignedMarkRevocationListDao::load);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
"SignedMarkRevocationList in Datastore is empty while it is not empty in Cloud SQL.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,7 @@
|
|||
package google.registry.model.smd;
|
||||
|
||||
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.model.smd.SignedMarkRevocationList.SHARD_SIZE;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
@ -40,24 +36,6 @@ public class SignedMarkRevocationListTest {
|
|||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z"));
|
||||
|
||||
@Test
|
||||
void testUnshardedSaveFails() {
|
||||
// Our @Entity's @OnSave method will notice that this shouldn't be saved.
|
||||
assertThrows(
|
||||
SignedMarkRevocationList.UnshardedSaveException.class,
|
||||
() ->
|
||||
tm()
|
||||
.transact(
|
||||
() -> {
|
||||
SignedMarkRevocationList smdrl =
|
||||
SignedMarkRevocationList.create(
|
||||
tm().getTransactionTime(),
|
||||
ImmutableMap.of("a", tm().getTransactionTime()));
|
||||
smdrl.id = 1; // Without an id this won't save anyways.
|
||||
ofy().saveWithoutBackup().entity(smdrl).now();
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmpty() {
|
||||
// When Datastore is empty, it should give us an empty thing.
|
||||
|
@ -65,41 +43,6 @@ public class SignedMarkRevocationListTest {
|
|||
.isEqualTo(SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSharding2() {
|
||||
final int rows = SHARD_SIZE + 1;
|
||||
// Create a SignedMarkRevocationList that will need 2 shards to save.
|
||||
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
||||
for (int i = 0; i < rows; i++) {
|
||||
revokes.put(Integer.toString(i), clock.nowUtc());
|
||||
}
|
||||
// Save it with sharding, and make sure that reloading it works.
|
||||
SignedMarkRevocationList unsharded =
|
||||
SignedMarkRevocationList.create(clock.nowUtc(), revokes.build()).save();
|
||||
assertAboutImmutableObjects()
|
||||
.that(SignedMarkRevocationList.get())
|
||||
.isEqualExceptFields(unsharded, "revisionId");
|
||||
assertThat(ofy().load().type(SignedMarkRevocationList.class).count()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSharding4() {
|
||||
final int rows = SHARD_SIZE * 3 + 1;
|
||||
// Create a SignedMarkRevocationList that will need 4 shards to save.
|
||||
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
||||
for (int i = 0; i < rows; i++) {
|
||||
revokes.put(Integer.toString(i), clock.nowUtc());
|
||||
}
|
||||
// Save it with sharding, and make sure that reloading it works.
|
||||
SignedMarkRevocationList unsharded = SignedMarkRevocationList
|
||||
.create(clock.nowUtc(), revokes.build())
|
||||
.save();
|
||||
assertAboutImmutableObjects()
|
||||
.that(SignedMarkRevocationList.get())
|
||||
.isEqualExceptFields(unsharded, "revisionId");
|
||||
assertThat(ofy().load().type(SignedMarkRevocationList.class).count()).isEqualTo(4);
|
||||
}
|
||||
|
||||
private SignedMarkRevocationList createSaveGetHelper(int rows) {
|
||||
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
||||
for (int i = 0; i < rows; i++) {
|
||||
|
@ -139,22 +82,6 @@ public class SignedMarkRevocationListTest {
|
|||
.isEqualTo(DateTime.parse("2000-01-01T00:00:00Z"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_getCreationTime_unequalListsInDatabases() {
|
||||
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
|
||||
createSaveGetHelper(1);
|
||||
ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
revokes.put(Integer.toString(i), clock.nowUtc());
|
||||
}
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> jpaTm().insert(SignedMarkRevocationList.create(clock.nowUtc(), revokes.build())));
|
||||
RuntimeException thrown =
|
||||
assertThrows(RuntimeException.class, () -> SignedMarkRevocationList.get());
|
||||
assertThat(thrown).hasMessageThat().contains("Unequal SignedMarkRevocationList detected:");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_isSmdRevoked_present() {
|
||||
final int rows = SHARD_SIZE + 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue