mirror of
https://github.com/google/nomulus
synced 2026-09-19 14:34:18 +00:00
Always use Cloud SQL as primary for Reserved and Premium Lists (#1113)
* Always use Cloud SQL as primary for Reserved and Premium Lists * small typos * Add a state check * Add test for bloom filter * fix import
This commit is contained in:
+6
-60
@@ -15,40 +15,27 @@
|
||||
package google.registry.model.registry.label;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.newRegistry;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.truth.Truth8;
|
||||
import google.registry.dns.writer.VoidDnsWriter;
|
||||
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.model.pricing.StaticPremiumListPricingEngine;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.schema.tld.PremiumListSqlDao;
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.TestCacheExtension;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link PremiumListDualDao}. */
|
||||
@DualDatabaseTest
|
||||
public class PremiumListDualDaoTest extends EntityTestCase {
|
||||
|
||||
// Set long persist times on caches so they can be tested (cache times default to 0 in tests).
|
||||
@@ -63,19 +50,6 @@ public class PremiumListDualDaoTest extends EntityTestCase {
|
||||
void before() {
|
||||
createTld("tld");
|
||||
fakeClock.setAutoIncrementStep(Duration.millis(1));
|
||||
fakeClock.setTo(DateTime.parse("1984-12-21T00:00:00.000Z"));
|
||||
DatabaseTransitionSchedule schedule =
|
||||
DatabaseTransitionSchedule.create(
|
||||
TransitionId.DOMAIN_LABEL_LISTS,
|
||||
TimedTransitionProperty.fromValueMap(
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME,
|
||||
PrimaryDatabase.DATASTORE,
|
||||
fakeClock.nowUtc().plusDays(1),
|
||||
PrimaryDatabase.CLOUD_SQL),
|
||||
PrimaryDatabaseTransition.class));
|
||||
|
||||
tm().transactNew(() -> ofyTm().putWithoutBackup(schedule));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -83,22 +57,8 @@ public class PremiumListDualDaoTest extends EntityTestCase {
|
||||
fakeClock.setAutoIncrementStep(Duration.ZERO);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testGetPremiumPrice_secondaryLoadMissingSql() {
|
||||
PremiumListSqlDao.delete(PremiumListSqlDao.getLatestRevision("tld").get());
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> PremiumListDualDao.getPremiumPrice("brass", Registry.get("tld"))))
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Unequal prices for domain brass.tld from primary Datastore DB "
|
||||
+ "(Optional[USD 20.00]) and secondary SQL db (Optional.empty).");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@Test
|
||||
void testGetPremiumPrice_secondaryLoadMissingOfy() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
PremiumList premiumList = PremiumListDatastoreDao.getLatestRevision("tld").get();
|
||||
PremiumListDatastoreDao.delete(premiumList);
|
||||
assertThat(
|
||||
@@ -111,22 +71,8 @@ public class PremiumListDualDaoTest extends EntityTestCase {
|
||||
+ "and secondary Datastore db (Optional.empty).");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testGetPremiumPrice_secondaryDifferentSql() {
|
||||
PremiumListSqlDao.save("tld", ImmutableList.of("brass,USD 50"));
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> PremiumListDualDao.getPremiumPrice("brass", Registry.get("tld"))))
|
||||
.hasMessageThat()
|
||||
.isEqualTo(
|
||||
"Unequal prices for domain brass.tld from primary Datastore DB "
|
||||
+ "(Optional[USD 20.00]) and secondary SQL db (Optional[USD 50.00]).");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@Test
|
||||
void testGetPremiumPrice_secondaryDifferentOfy() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
PremiumListDatastoreDao.save("tld", ImmutableList.of("brass,USD 50"));
|
||||
assertThat(
|
||||
assertThrows(
|
||||
@@ -138,7 +84,7 @@ public class PremiumListDualDaoTest extends EntityTestCase {
|
||||
+ "(Optional[USD 20.00]) and secondary Datastore db (Optional[USD 50.00]).");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@Test
|
||||
void testGetPremiumPrice_returnsNoPriceWhenNoPremiumListConfigured() {
|
||||
createTld("ghost");
|
||||
persistResource(
|
||||
@@ -151,14 +97,14 @@ public class PremiumListDualDaoTest extends EntityTestCase {
|
||||
Truth8.assertThat(PremiumListDualDao.getPremiumPrice("blah", Registry.get("ghost"))).isEmpty();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@Test
|
||||
void testGetPremiumPrice_emptyWhenPremiumListDeleted() {
|
||||
PremiumList toDelete = PremiumListDualDao.getLatestRevision("tld").get();
|
||||
PremiumListDualDao.delete(toDelete);
|
||||
Truth8.assertThat(PremiumListDualDao.getPremiumPrice("blah", Registry.get("tld"))).isEmpty();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@Test
|
||||
void getPremiumPrice_returnsNoneWhenNoPremiumListConfigured() {
|
||||
persistResource(newRegistry("foobar", "FOOBAR").asBuilder().setPremiumList(null).build());
|
||||
Truth8.assertThat(PremiumListDualDao.getPremiumPrice("rich", Registry.get("foobar"))).isEmpty();
|
||||
|
||||
@@ -16,7 +16,6 @@ package google.registry.model.registry.label;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistPremiumList;
|
||||
import static google.registry.testing.DatabaseHelper.persistReservedList;
|
||||
@@ -24,9 +23,9 @@ import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.hash.BloomFilter;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.label.PremiumList.PremiumListEntry;
|
||||
import google.registry.model.registry.label.PremiumList.PremiumListRevision;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import org.joda.money.Money;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -68,13 +67,13 @@ public class PremiumListTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProbablePremiumLabels() {
|
||||
void testBloomFilter() {
|
||||
PremiumList pl = PremiumListDualDao.getLatestRevision("tld").get();
|
||||
PremiumListRevision revision = ofy().load().key(pl.getRevisionKey()).now();
|
||||
assertThat(revision.getProbablePremiumLabels().mightContain("notpremium")).isFalse();
|
||||
BloomFilter<String> bloomFilter = pl.getBloomFilter();
|
||||
assertThat(bloomFilter.mightContain("notpremium")).isFalse();
|
||||
for (String label : ImmutableList.of("rich", "lol", "johnny-be-goode", "icann")) {
|
||||
assertWithMessage(label + " should be a probable premium")
|
||||
.that(revision.getProbablePremiumLabels().mightContain(label))
|
||||
.that(bloomFilter.mightContain(label))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
+15
-172
@@ -15,36 +15,17 @@
|
||||
package google.registry.model.registry.label;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
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.model.registry.label.ReservedList.ReservedListEntry;
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.SystemPropertyExtension;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DualDatabaseTest
|
||||
public class ReservedListDualDatabaseDaoTest extends EntityTestCase {
|
||||
|
||||
@RegisterExtension
|
||||
final SystemPropertyExtension systemPropertyExtension = new SystemPropertyExtension();
|
||||
|
||||
private ImmutableMap<String, ReservedListEntry> reservations;
|
||||
|
||||
private ReservedList reservedList;
|
||||
@@ -65,41 +46,18 @@ public class ReservedListDualDatabaseDaoTest extends EntityTestCase {
|
||||
.setShouldPublish(false)
|
||||
.setReservedListMap(reservations)
|
||||
.build();
|
||||
|
||||
fakeClock.setTo(DateTime.parse("1984-12-21T00:00:00.000Z"));
|
||||
DatabaseTransitionSchedule schedule =
|
||||
DatabaseTransitionSchedule.create(
|
||||
TransitionId.DOMAIN_LABEL_LISTS,
|
||||
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());
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSave_datastorePrimary_success() {
|
||||
@Test
|
||||
void testSave_success() {
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
Optional<ReservedList> savedList =
|
||||
ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName());
|
||||
assertThat(savedList.get()).isEqualTo(reservedList);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSave_cloudSqlPrimary_success() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
Optional<ReservedList> savedList =
|
||||
ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName());
|
||||
assertThat(savedList.get()).isEqualTo(reservedList);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testDelete_datastorePrimary_success() {
|
||||
@Test
|
||||
void testDelete_success() {
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
assertThat(ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName()).isPresent())
|
||||
.isTrue();
|
||||
@@ -108,19 +66,8 @@ public class ReservedListDualDatabaseDaoTest extends EntityTestCase {
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testDelete_cloudSqlPrimary_success() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
assertThat(ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName()).isPresent())
|
||||
.isTrue();
|
||||
ReservedListDualDatabaseDao.delete(reservedList);
|
||||
assertThat(ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName()).isPresent())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSaveAndLoad_datastorePrimary_emptyList() {
|
||||
@Test
|
||||
void testSaveAndLoad_emptyList() {
|
||||
ReservedList list =
|
||||
new ReservedList.Builder()
|
||||
.setName("empty")
|
||||
@@ -132,22 +79,8 @@ public class ReservedListDualDatabaseDaoTest extends EntityTestCase {
|
||||
assertThat(savedList.get()).isEqualTo(list);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSaveAndLoad_cloudSqlPrimary_emptyList() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
ReservedList list =
|
||||
new ReservedList.Builder()
|
||||
.setName("empty")
|
||||
.setLastUpdateTime(fakeClock.nowUtc())
|
||||
.setReservedListMap(ImmutableMap.of())
|
||||
.build();
|
||||
ReservedListDualDatabaseDao.save(list);
|
||||
Optional<ReservedList> savedList = ReservedListDualDatabaseDao.getLatestRevision("empty");
|
||||
assertThat(savedList.get()).isEqualTo(list);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSave_datastorePrimary_multipleVersions() {
|
||||
@Test
|
||||
void testSave_multipleVersions() {
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
assertThat(
|
||||
ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName())
|
||||
@@ -173,36 +106,8 @@ public class ReservedListDualDatabaseDaoTest extends EntityTestCase {
|
||||
.isEqualTo(newReservations);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testSave_cloudSqlPrimary_multipleVersions() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
assertThat(
|
||||
ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName())
|
||||
.get()
|
||||
.getReservedListEntries())
|
||||
.isEqualTo(reservations);
|
||||
ImmutableMap<String, ReservedListEntry> newReservations =
|
||||
ImmutableMap.of(
|
||||
"food",
|
||||
ReservedListEntry.create("food", ReservationType.RESERVED_FOR_SPECIFIC_USE, null));
|
||||
ReservedList secondList =
|
||||
new ReservedList.Builder()
|
||||
.setName("testlist2")
|
||||
.setLastUpdateTime(fakeClock.nowUtc())
|
||||
.setShouldPublish(false)
|
||||
.setReservedListMap(newReservations)
|
||||
.build();
|
||||
ReservedListDualDatabaseDao.save(secondList);
|
||||
assertThat(
|
||||
ReservedListDualDatabaseDao.getLatestRevision(secondList.getName())
|
||||
.get()
|
||||
.getReservedListEntries())
|
||||
.isEqualTo(newReservations);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_datastorePrimary_unequalLists() {
|
||||
@Test
|
||||
void testLoad_unequalLists() {
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
ReservedList secondList =
|
||||
new ReservedList.Builder()
|
||||
@@ -222,78 +127,16 @@ public class ReservedListDualDatabaseDaoTest extends EntityTestCase {
|
||||
() -> ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName()));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Domain label music has entry in Datastore, but not in the secondary database.");
|
||||
.contains("Domain label music has entry in Datastore, but not in Cloud SQL.");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_cloudSqlPrimary_unequalLists() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
ReservedList secondList =
|
||||
new ReservedList.Builder()
|
||||
.setName(reservedList.name)
|
||||
.setLastUpdateTime(fakeClock.nowUtc())
|
||||
.setShouldPublish(false)
|
||||
.setReservedListMap(
|
||||
ImmutableMap.of(
|
||||
"food",
|
||||
ReservedListEntry.create(
|
||||
"food", ReservationType.RESERVED_FOR_SPECIFIC_USE, null)))
|
||||
.build();
|
||||
ReservedListSqlDao.save(secondList);
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName()));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Domain label music has entry in Datastore, but not in the primary database.");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_cloudSqlPrimary_unequalLists_succeedsInProduction() {
|
||||
RegistryEnvironment.PRODUCTION.setup(systemPropertyExtension);
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
ReservedListDualDatabaseDao.save(reservedList);
|
||||
ReservedList secondList =
|
||||
new ReservedList.Builder()
|
||||
.setName(reservedList.name)
|
||||
.setLastUpdateTime(fakeClock.nowUtc())
|
||||
.setShouldPublish(false)
|
||||
.setReservedListMap(
|
||||
ImmutableMap.of(
|
||||
"food",
|
||||
ReservedListEntry.create(
|
||||
"food", ReservationType.RESERVED_FOR_SPECIFIC_USE, null)))
|
||||
.build();
|
||||
ReservedListSqlDao.save(secondList);
|
||||
Optional<ReservedList> savedList =
|
||||
ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName());
|
||||
assertThat(savedList.get()).isEqualTo(secondList);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_DatastorePrimary_noListInCloudSql() {
|
||||
ReservedListDatastoreDao.save(reservedList);
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName()));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Reserved list in the secondary database (Cloud SQL) is empty.");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testLoad_cloudSqlPrimary_noListInDatastore() {
|
||||
fakeClock.advanceBy(Duration.standardDays(5));
|
||||
@Test
|
||||
void testLoad_noListInDatastore() {
|
||||
ReservedListSqlDao.save(reservedList);
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> ReservedListDualDatabaseDao.getLatestRevision(reservedList.getName()));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Reserved list in the secondary database (Datastore) is empty.");
|
||||
assertThat(thrown).hasMessageThat().contains("Reserved list in Datastore is empty.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,10 @@ import static google.registry.testing.DatabaseHelper.createTlds;
|
||||
import static google.registry.testing.DatabaseHelper.persistReservedList;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
|
||||
import google.registry.model.registry.label.ReservedListSqlDao;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -58,16 +53,6 @@ class CreateReservedListCommandTest
|
||||
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_timestampsSetCorrectly() throws Exception {
|
||||
DateTime before = DateTime.now(UTC);
|
||||
runCommandForced("--input=" + reservedTermsPath);
|
||||
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isPresent();
|
||||
ReservedList rl = ReservedList.get("xn--q9jyb4c_common-reserved").get();
|
||||
assertThat(rl.getCreationTime()).isAtLeast(before);
|
||||
assertThat(rl.getLastUpdateTime()).isEqualTo(rl.getCreationTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_shouldPublishDefaultsToTrue() throws Exception {
|
||||
runCommandForced("--input=" + reservedTermsPath);
|
||||
@@ -187,21 +172,6 @@ class CreateReservedListCommandTest
|
||||
verifyXnq9jyb4cInCloudSql();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSaveToCloudSql_noExceptionThrownWhenSaveFail() throws Exception {
|
||||
// Note that, during the dual-write phase, we want to make sure that no exception will be
|
||||
// thrown if saving reserved list to Cloud SQL fails.
|
||||
ReservedListSqlDao.save(
|
||||
createCloudSqlReservedList(
|
||||
"xn--q9jyb4c_common-reserved",
|
||||
fakeClock.nowUtc(),
|
||||
true,
|
||||
ImmutableMap.of(
|
||||
"testdomain", ReservedListEntry.create("testdomain", FULLY_BLOCKED, ""))));
|
||||
runCommandForced("--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath);
|
||||
verifyXnq9jyb4cInDatastore();
|
||||
}
|
||||
|
||||
private void runNameTestExpectedFailure(String name, String expectedErrorMsg) {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
|
||||
@@ -16,7 +16,6 @@ package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.loadPremiumListEntries;
|
||||
import static google.registry.testing.DatabaseHelper.persistPremiumList;
|
||||
@@ -25,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.label.PremiumList;
|
||||
import google.registry.model.registry.label.PremiumList.PremiumListEntry;
|
||||
import google.registry.model.registry.label.PremiumListDualDao;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -38,13 +36,6 @@ class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumListComm
|
||||
assertThat(loadPremiumListEntries(premiumList)).hasSize(1);
|
||||
runCommand("--force", "--name=xn--q9jyb4c");
|
||||
assertThat(PremiumListDualDao.getLatestRevision("xn--q9jyb4c")).isEmpty();
|
||||
|
||||
// Ensure that the Datastore premium list entry entities were deleted correctly.
|
||||
assertThat(ofy().load()
|
||||
.type(PremiumListEntry.class)
|
||||
.ancestor(premiumList.getRevisionKey())
|
||||
.keys())
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -74,16 +74,6 @@ class UpdateReservedListCommandTest
|
||||
runSuccessfulUpdateTest("--input=" + reservedTermsPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_lastUpdateTime_updatedCorrectly() throws Exception {
|
||||
ReservedList original = ReservedList.get("xn--q9jyb4c_common-reserved").get();
|
||||
runCommandForced("--input=" + reservedTermsPath);
|
||||
ReservedList updated = ReservedList.get("xn--q9jyb4c_common-reserved").get();
|
||||
assertThat(updated.getLastUpdateTime()).isGreaterThan(original.getLastUpdateTime());
|
||||
assertThat(updated.getCreationTime()).isEqualTo(original.getCreationTime());
|
||||
assertThat(updated.getLastUpdateTime()).isGreaterThan(updated.getCreationTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_shouldPublish_setToFalseCorrectly() throws Exception {
|
||||
runSuccessfulUpdateTest("--input=" + reservedTermsPath, "--should_publish=false");
|
||||
|
||||
@@ -16,15 +16,11 @@ package google.registry.tools.server;
|
||||
|
||||
import static google.registry.testing.DatabaseHelper.persistPremiumList;
|
||||
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import google.registry.testing.TestOfyOnly;
|
||||
import google.registry.testing.TestSqlOnly;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link ListPremiumListsAction}. */
|
||||
@DualDatabaseTest
|
||||
class ListPremiumListsActionTest extends ListActionTestCase {
|
||||
|
||||
private ListPremiumListsAction action;
|
||||
@@ -36,7 +32,7 @@ class ListPremiumListsActionTest extends ListActionTestCase {
|
||||
action = new ListPremiumListsAction();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@Test
|
||||
void testRun_noParameters() {
|
||||
testRunSuccess(
|
||||
action,
|
||||
@@ -47,20 +43,7 @@ class ListPremiumListsActionTest extends ListActionTestCase {
|
||||
"^xn--q9jyb4c$");
|
||||
}
|
||||
|
||||
@TestOfyOnly // only ofy has revisionKey
|
||||
void testRun_withParameters() {
|
||||
testRunSuccess(
|
||||
action,
|
||||
Optional.of("revisionKey"),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
"^name\\s+revisionKey\\s*$",
|
||||
"^-+\\s+-+\\s*$",
|
||||
"^how\\s+.*PremiumList.*$",
|
||||
"^xn--q9jyb4c\\s+.*PremiumList.*$");
|
||||
}
|
||||
|
||||
@TestSqlOnly
|
||||
@Test
|
||||
void testRun_withLabelsToPrices() {
|
||||
testRunSuccess(
|
||||
action,
|
||||
@@ -69,24 +52,11 @@ class ListPremiumListsActionTest extends ListActionTestCase {
|
||||
Optional.empty(),
|
||||
"^name\\s+labelsToPrices\\s*$",
|
||||
"^-+\\s+-+\\s*$",
|
||||
"^how\\s+\\{richer=5000\\}\\s+$",
|
||||
"^how\\s+\\{richer=5000.00\\}$",
|
||||
"^xn--q9jyb4c\\s+\\{rich=100\\.00\\}\\s+$");
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
void testRun_withWildcard() {
|
||||
testRunSuccess(
|
||||
action,
|
||||
Optional.of("*"),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
"^name\\s+.*revisionKey",
|
||||
"^-+\\s+-+.*",
|
||||
"^how\\s+.*PremiumList",
|
||||
"^xn--q9jyb4c\\s+.*PremiumList");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@Test
|
||||
void testRun_withBadField_returnsError() {
|
||||
testRunError(
|
||||
action,
|
||||
|
||||
Reference in New Issue
Block a user