Set clock precision to milliseconds for Datetime->Instant migration (#2999)

Our existing precision is milliseconds so we want to stick with that for
Instants. If we want to increase the precision globally after that we can do so
all in one go post-migration, but for now, it would be a bad thing to have mixed
precision going on just depending on whether a class happens to be migrated yet
or not.

This PR also migrates all existing DateTime.nowUtc() calls to use the Clock
interface, so that when they are migrated they will get the benefit of this
precision-setting as well.

BUG= http://b/496985355
This commit is contained in:
Ben McIlwain
2026-04-03 20:38:26 +00:00
committed by GitHub
parent d2881b47dc
commit 49f14b5e1b
69 changed files with 466 additions and 320 deletions
@@ -45,6 +45,7 @@ import google.registry.model.tld.Tld.TldType;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import google.registry.testing.SystemPropertyExtension;
import google.registry.util.RegistryEnvironment;
import java.time.Instant;
@@ -62,9 +63,11 @@ class DeleteProberDataActionTest {
private static final DateTime DELETION_TIME = DateTime.parse("2010-01-01T00:00:00.000Z");
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension();
@RegisterExtension
final SystemPropertyExtension systemPropertyExtension = new SystemPropertyExtension();
@@ -94,7 +97,9 @@ class DeleteProberDataActionTest {
}
private void resetAction() {
action = new DeleteProberDataAction(false, ImmutableSet.of(), Optional.empty(), "TheRegistrar");
action =
new DeleteProberDataAction(
false, ImmutableSet.of(), Optional.empty(), "TheRegistrar", clock);
}
@AfterEach
@@ -124,7 +129,7 @@ class DeleteProberDataActionTest {
Set<ImmutableObject> oaEntities = persistLotsOfDomains("oa-canary.test");
// Create action with batch size of 3
DeleteProberDataAction batchedAction =
new DeleteProberDataAction(false, ImmutableSet.of(), Optional.of(3), "TheRegistrar");
new DeleteProberDataAction(false, ImmutableSet.of(), Optional.of(3), "TheRegistrar", clock);
batchedAction.run();
assertAllAbsent(ibEntities);
assertAllAbsent(oaEntities);
@@ -97,7 +97,8 @@ class SendExpiringCertificateNotificationEmailActionTest {
EXPIRATION_WARNING_EMAIL_SUBJECT_TEXT,
sendEmailService,
certificateChecker,
response);
response,
clock);
sampleRegistrar =
persistResource(createRegistrar("clientId", "sampleRegistrar", null, null).build());
@@ -85,10 +85,13 @@ class SafeBrowsingTransformsTest {
private final CloseableHttpClient mockHttpClient =
mock(CloseableHttpClient.class, withSettings().serializable());
private final FakeClock clock = new FakeClock();
private final EvaluateSafeBrowsingFn safeBrowsingFn =
new EvaluateSafeBrowsingFn(
"API_KEY",
new Retrier(new FakeSleeper(new FakeClock()), 1),
new Retrier(new FakeSleeper(clock), 1),
clock,
Suppliers.ofInstance(mockHttpClient));
@RegisterExtension
@@ -187,7 +187,8 @@ class Spec11PipelineTest {
EvaluateSafeBrowsingFn safeBrowsingFn =
new EvaluateSafeBrowsingFn(
SAFE_BROWSING_API_KEY,
new Retrier(new FakeSleeper(new FakeClock()), 1),
new Retrier(new FakeSleeper(fakeClock), 1),
fakeClock,
Suppliers.ofInstance(mockHttpClient));
when(mockHttpClient.execute(any(HttpPost.class))).thenAnswer(new HttpResponder());
Spec11Pipeline spec11Pipeline = new Spec11Pipeline(options, safeBrowsingFn);
@@ -17,6 +17,7 @@ package google.registry.export;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.export.ExportPremiumTermsAction.EXPORT_MIME_TYPE;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.deleteTld;
import static google.registry.testing.DatabaseHelper.persistResource;
@@ -75,7 +76,7 @@ public class ExportPremiumTermsActionTest {
@BeforeEach
void beforeEach() throws Exception {
createTld("tld");
PremiumList pl = PremiumListDao.save("pl-name", USD, PREMIUM_NAMES);
PremiumList pl = tm().transact(() -> PremiumListDao.save("pl-name", USD, PREMIUM_NAMES));
persistResource(
Tld.get("tld").asBuilder().setPremiumList(pl).setDriveFolderId("folder_id").build());
when(driveConnection.createOrUpdateFile(
@@ -24,6 +24,7 @@ import static google.registry.model.reporting.DomainTransactionRecord.Transactio
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_CREATE;
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_TRANSFER_APPROVE;
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.assertBillingEventsForResource;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.deleteTestDomain;
@@ -512,12 +513,14 @@ class DomainTransferApproveFlowTest
@Test
void testSuccess_nonpremiumPriceRenewalBehavior_carriesOver() throws Exception {
PremiumList pl =
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build()));
persistResource(Tld.get("tld").asBuilder().setPremiumList(pl).build());
domain = loadByEntity(domain);
persistResource(
@@ -558,12 +561,14 @@ class DomainTransferApproveFlowTest
@Test
void testSuccess_specifiedPriceRenewalBehavior_carriesOver() throws Exception {
PremiumList pl =
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build()));
persistResource(Tld.get("tld").asBuilder().setPremiumList(pl).build());
domain = loadByEntity(domain);
persistResource(
@@ -1160,12 +1160,14 @@ class DomainTransferRequestFlowTest
throws Exception {
setupDomain("example", "tld");
PremiumList pl =
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build()));
persistResource(Tld.get("tld").asBuilder().setPremiumList(pl).build());
domain = loadByEntity(domain);
persistResource(
@@ -1214,12 +1216,14 @@ class DomainTransferRequestFlowTest
throws Exception {
setupDomain("example", "tld");
PremiumList pl =
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setCurrency(USD)
.setName("tld")
.setLabelsToPrices(ImmutableMap.of("example", new BigDecimal("67.89")))
.build()));
persistResource(Tld.get("tld").asBuilder().setPremiumList(pl).build());
domain = loadByEntity(domain);
persistResource(
@@ -84,7 +84,7 @@ public class PremiumListDaoTest {
@Test
void saveNew_worksSuccessfully() {
PremiumListDao.save(testList);
tm().transact(() -> PremiumListDao.save(testList));
tm().transact(
() -> {
Optional<PremiumList> persistedListOpt = PremiumListDao.getLatestRevision("testname");
@@ -118,24 +118,26 @@ public class PremiumListDaoTest {
@Test
void update_worksSuccessfully() {
PremiumListDao.save(testList);
tm().transact(() -> PremiumListDao.save(testList));
Optional<PremiumList> persistedList = PremiumListDao.getLatestRevision("testname");
assertThat(persistedList).isPresent();
long firstRevisionId = persistedList.get().getRevisionId();
PremiumListDao.save(
new PremiumList.Builder()
.setName("testname")
.setCurrency(USD)
.setLabelsToPrices(
ImmutableMap.of(
"save",
BigDecimal.valueOf(55343.12),
"new",
BigDecimal.valueOf(0.01),
"silver",
BigDecimal.valueOf(30.03)))
.setCreationTimestamp(fakeClock.nowUtc())
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setName("testname")
.setCurrency(USD)
.setLabelsToPrices(
ImmutableMap.of(
"save",
BigDecimal.valueOf(55343.12),
"new",
BigDecimal.valueOf(0.01),
"silver",
BigDecimal.valueOf(30.03)))
.setCreationTimestamp(fakeClock.nowUtc())
.build()));
tm().transact(
() -> {
Optional<PremiumList> savedListOpt = PremiumListDao.getLatestRevision("testname");
@@ -158,7 +160,7 @@ public class PremiumListDaoTest {
@Test
void checkExists_worksSuccessfully() {
assertThat(PremiumListDao.getLatestRevision("testname")).isEmpty();
PremiumListDao.save(testList);
tm().transact(() -> PremiumListDao.save(testList));
assertThat(PremiumListDao.getLatestRevision("testname")).isPresent();
}
@@ -169,20 +171,24 @@ public class PremiumListDaoTest {
@Test
void getLatestRevision_worksSuccessfully() {
PremiumListDao.save(
new PremiumList.Builder()
.setName("list1")
.setCurrency(USD)
.setLabelsToPrices(ImmutableMap.of("wrong", BigDecimal.valueOf(1000.50)))
.setCreationTimestamp(fakeClock.nowUtc())
.build());
PremiumListDao.save(
new PremiumList.Builder()
.setName("list1")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setName("list1")
.setCurrency(USD)
.setLabelsToPrices(ImmutableMap.of("wrong", BigDecimal.valueOf(1000.50)))
.setCreationTimestamp(fakeClock.nowUtc())
.build()));
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setName("list1")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build()));
tm().transact(
() -> {
Optional<PremiumList> persistedList = PremiumListDao.getLatestRevision("list1");
@@ -196,13 +202,15 @@ public class PremiumListDaoTest {
@Test
void getLabelsToPrices_worksForJpy() {
PremiumListDao.save(
new PremiumList.Builder()
.setName("list1")
.setCurrency(JPY)
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setName("list1")
.setCurrency(JPY)
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build()));
tm().transact(
() -> {
PremiumList premiumList = PremiumListDao.getLatestRevision("list1").get();
@@ -220,13 +228,15 @@ public class PremiumListDaoTest {
@Test
void getPremiumPrice_worksSuccessfully() {
PremiumList premiumList =
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTimestamp(fakeClock.nowUtc())
.build()));
persistResource(newTld("foobar", "FOOBAR").asBuilder().setPremiumList(premiumList).build());
assertThat(PremiumListDao.getPremiumPrice("premlist", "silver")).hasValue(Money.of(USD, 10.23));
assertThat(PremiumListDao.getPremiumPrice("premlist", "gold")).hasValue(Money.of(USD, 1305.47));
@@ -236,20 +246,22 @@ public class PremiumListDaoTest {
@Test
void testGetPremiumPrice_worksForJPY() {
PremiumList premiumList =
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(JPY)
.setLabelsToPrices(
ImmutableMap.of(
"silver",
BigDecimal.valueOf(10.00),
"gold",
BigDecimal.valueOf(1000.0),
"palladium",
BigDecimal.valueOf(15000)))
.setCreationTimestamp(fakeClock.nowUtc())
.build());
tm().transact(
() ->
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(JPY)
.setLabelsToPrices(
ImmutableMap.of(
"silver",
BigDecimal.valueOf(10.00),
"gold",
BigDecimal.valueOf(1000.0),
"palladium",
BigDecimal.valueOf(15000)))
.setCreationTimestamp(fakeClock.nowUtc())
.build()));
persistResource(newTld("foobar", "FOOBAR").asBuilder().setPremiumList(premiumList).build());
assertThat(PremiumListDao.getPremiumPrice("premlist", "silver")).hasValue(moneyOf(JPY, 10));
assertThat(PremiumListDao.getPremiumPrice("premlist", "gold")).hasValue(moneyOf(JPY, 1000));
@@ -262,14 +274,18 @@ public class PremiumListDaoTest {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> PremiumListDao.save("test-list", CurrencyUnit.GBP, ImmutableList.of()));
() ->
tm().transact(
() ->
PremiumListDao.save(
"test-list", CurrencyUnit.GBP, ImmutableList.of())));
assertThat(thrown).hasMessageThat().isEqualTo("New premium list data cannot be empty");
}
@Test
void test_savePremiumList_clearsCache() {
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull();
PremiumListDao.save(testList);
tm().transact(() -> PremiumListDao.save(testList));
PremiumList pl = PremiumListDao.getLatestRevision("testname").get();
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).hasValue(pl);
tm().transact(() -> PremiumListDao.save("testname", USD, ImmutableList.of("test,USD 1")));
@@ -288,7 +304,7 @@ public class PremiumListDaoTest {
.setLabelsToPrices(prices)
.setCreationTimestamp(fakeClock.nowUtc())
.build();
PremiumListDao.save(list);
tm().transact(() -> PremiumListDao.save(list));
long duration = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
if (duration >= 6000) {
// Don't fail directly since we can't rely on what sort of machines the test is running on
@@ -16,6 +16,7 @@ package google.registry.model.tld.label;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistReservedList;
@@ -101,7 +102,8 @@ public class PremiumListTest {
@Test
void testParse_canIncludeOrNotIncludeCurrencyUnit() {
PremiumListDao.save("tld", USD, ImmutableList.of("rofl,USD 90", "paper, 80"));
tm().transact(
() -> PremiumListDao.save("tld", USD, ImmutableList.of("rofl,USD 90", "paper, 80")));
assertThat(PremiumListDao.getPremiumPrice("tld", "rofl")).hasValue(Money.of(USD, 90));
assertThat(PremiumListDao.getPremiumPrice("tld", "paper")).hasValue(Money.of(USD, 80));
}
@@ -21,16 +21,22 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
import java.math.BigDecimal;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link PremiumListUtils}. */
class PremiumListUtilsTest {
private static final DateTime SAMPLE_TIME = DateTime.parse("2026-01-26T21:06:12.284Z");
@Test
void parseInputToPremiumList_works() {
PremiumList premiumList =
parseToPremiumList(
"testlist", USD, ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,USD 10"));
"testlist",
USD,
ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,USD 10"),
SAMPLE_TIME);
assertThat(premiumList.getName()).isEqualTo("testlist");
assertThat(premiumList.getLabelsToPrices())
.containsExactly("foo", twoDigits(99.50), "bar", twoDigits(30), "baz", twoDigits(10));
@@ -45,7 +51,8 @@ class PremiumListUtilsTest {
parseToPremiumList(
"testlist",
USD,
ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,JPY 990")));
ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,JPY 990"),
SAMPLE_TIME));
assertThat(thrown).hasMessageThat().isEqualTo("The currency unit must be USD");
}
@@ -31,15 +31,18 @@ import google.registry.bigquery.BigqueryConnection.DestinationTable;
import google.registry.bigquery.BigqueryUtils.TableType;
import google.registry.gcs.GcsUtils;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import org.joda.time.DateTime;
import org.joda.time.YearMonth;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link google.registry.reporting.icann.IcannReportingStager}. */
class IcannReportingStagerTest {
private final FakeClock clock = new FakeClock(DateTime.parse("2026-01-26T21:06:12.284Z"));
private BigqueryConnection bigquery = mock(BigqueryConnection.class);
FakeResponse response = new FakeResponse();
private YearMonth yearMonth = new YearMonth(2017, 6);
@@ -63,7 +66,7 @@ class IcannReportingStagerTest {
when(bigquery.startQuery(any(String.class), any(DestinationTable.class)))
.thenReturn(fakeFuture());
DestinationTable.Builder tableBuilder =
new DestinationTable.Builder()
new DestinationTable.Builder(clock)
.datasetId("testdataset")
.type(TableType.TABLE)
.name("tablename")
@@ -346,7 +346,7 @@ public final class DatabaseHelper {
// increasing sequence, if we don't pad out the ID here, we would have to renumber hundreds of
// unit tests.
tm().reTransact(tm()::allocateId);
PremiumListDao.save(premiumList);
tm().transact(() -> PremiumListDao.save(premiumList));
maybeAdvanceClock();
return premiumList;
}
@@ -30,7 +30,6 @@ import google.registry.model.poll.PollMessage.OneTime;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -38,13 +37,12 @@ import org.junit.jupiter.api.Test;
/** Unit tests for {@link AckPollMessagesCommand}. */
public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesCommand> {
private final FakeClock clock = new FakeClock(DateTime.parse("2015-02-04T08:16:32.064Z"));
private DomainHistory domainHistory;
@BeforeEach
final void beforeEach() {
command.clock = clock;
command.clock = fakeClock;
fakeClock.setTo(DateTime.parse("2015-02-04T08:16:32.064Z"));
createTld("tld");
Domain domain =
DatabaseHelper.newDomain("example.tld").asBuilder().setRepoId("FSDGS-TLD").build();
@@ -52,12 +50,12 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
domainHistory =
persistResource(
new DomainHistory.Builder()
.setModificationTime(clock.nowUtc())
.setModificationTime(fakeClock.nowUtc())
.setDomain(domain)
.setRegistrarId(domain.getCreationRegistrarId())
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.build());
clock.advanceOneMilli();
fakeClock.advanceOneMilli();
}
@Test
@@ -68,10 +68,10 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
command.mapper = objectMapper;
premiumList = persistPremiumList("test", USD, "silver,USD 50", "gold,USD 80");
command.validDnsWriterNames = ImmutableSet.of("VoidDnsWriter", "FooDnsWriter");
command.clock = fakeClock;
logger.addHandler(logHandler);
}
@@ -31,6 +31,7 @@ class CreateAnchorTenantCommandTest extends EppToolCommandTestCase<CreateAnchorT
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
}
@@ -37,6 +37,7 @@ class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomainCommand
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
command.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
command.printStream = System.out;
}
@@ -45,6 +45,7 @@ abstract class CreateOrUpdatePremiumListCommandTestCase<T extends CreateOrUpdate
@BeforeEach
void beforeEachCreateOrUpdatePremiumListCommandTestCase() throws IOException {
command.clock = fakeClock;
// initial set up for both CreatePremiumListCommand and UpdatePremiumListCommand test cases;
initialPremiumListData = "doge,USD 9090";
File premiumTermsFile = tmpDir.resolve(TLD_TEST + ".txt").toFile();
@@ -44,6 +44,7 @@ abstract class CreateOrUpdateReservedListCommandTestCase<
@BeforeEach
void beforeEachCreateOrUpdateReservedListCommandTestCase() throws IOException {
command.clock = fakeClock;
File reservedTermsFile = tmpDir.resolve("xn--q9jyb4c_common-reserved.txt").toFile();
File invalidReservedTermsFile = tmpDir.resolve("reserved-terms-wontparse.csv").toFile();
String reservedTermsCsv =
@@ -54,7 +54,6 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
// since the old entity is always null and file cannot be empty, the prompt will NOT be "No entity
// changes to apply."
void commandPrompt_successStageNewEntity() throws Exception {
CreatePremiumListCommand command = new CreatePremiumListCommand();
command.inputFile = Paths.get(premiumTermsPath);
command.currencyUnit = "USD";
command.prompt();
@@ -63,7 +62,6 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@Test
void commandPrompt_successStageNewEntityWithOverride() throws Exception {
CreatePremiumListCommand command = new CreatePremiumListCommand();
String alterTld = "override";
command.inputFile = Paths.get(premiumTermsPath);
command.override = true;
@@ -75,7 +73,6 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@Test
void commandPrompt_failureNoInputFile() {
CreatePremiumListCommand command = new CreatePremiumListCommand();
assertThrows(NullPointerException.class, command::prompt);
}
@@ -83,7 +80,6 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
void commandPrompt_failurePremiumListAlreadyExists() {
String randomStr = "random";
DatabaseHelper.createTld(randomStr);
CreatePremiumListCommand command = new CreatePremiumListCommand();
command.name = randomStr;
command.currencyUnit = "USD";
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
@@ -92,7 +88,6 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@Test
void commandPrompt_failureMismatchedTldFileName_noOverride() throws Exception {
CreatePremiumListCommand command = new CreatePremiumListCommand();
String fileName = "random";
Path tmpPath = tmpDir.resolve(String.format("%s.txt", fileName));
Files.write(new byte[0], tmpPath.toFile());
@@ -111,7 +106,6 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@Test
void commandPrompt_failureMismatchedTldName_noOverride() {
CreatePremiumListCommand command = new CreatePremiumListCommand();
String fileName = "random";
command.name = fileName;
command.currencyUnit = "USD";
@@ -58,6 +58,7 @@ class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand>
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
command.setConnection(connection);
command.certificateChecker =
new CertificateChecker(
@@ -36,6 +36,7 @@ class CreateReservedListCommandTest
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
createTlds("xn--q9jyb4c", "soy");
}
@@ -162,7 +163,6 @@ class CreateReservedListCommandTest
@Test
void testStageEntityChange_succeeds() throws Exception {
CreateReservedListCommand command = new CreateReservedListCommand();
// file content is populated in @BeforeEach of CreateOrUpdateReservedListCommandTestCase.java
command.input = Paths.get(reservedTermsPath);
command.init();
@@ -176,7 +176,6 @@ class CreateReservedListCommandTest
void testStageEntityChange_succeedsWithEmptyFile() throws Exception {
Path tmpPath = tmpDir.resolve("xn--q9jyb4c_common-tmp.txt");
Files.write(new byte[0], tmpPath.toFile());
CreateReservedListCommand command = new CreateReservedListCommand();
command.input = tmpPath;
command.init();
assertThat(command.prompt()).contains("reservedListMap=[]");
@@ -33,6 +33,7 @@ public abstract class EppToolCommandTestCase<C extends EppToolCommand> extends C
@BeforeEach
public void beforeEachEppToolCommandTestCase() {
command.clock = fakeClock;
// Create two TLDs for commands that allow multiple TLDs at once.
createTlds("tld", "tld2");
eppVerifier = EppToolVerifier.create(command).expectRegistrarId("NewRegistrar");
@@ -22,7 +22,6 @@ import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.testing.DatabaseHelper.persistActiveHost;
import static google.registry.testing.DatabaseHelper.persistResource;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
@@ -36,13 +35,11 @@ import google.registry.model.domain.secdns.DomainDsData;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.Host;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.joda.time.DateTime;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.junit.jupiter.api.BeforeEach;
@@ -51,8 +48,6 @@ import org.junit.jupiter.api.Test;
/** Unit tests for {@link GenerateDnsReportCommand}. */
class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportCommand> {
private final DateTime now = DateTime.now(UTC);
private final FakeClock clock = new FakeClock();
private Path output;
private Object getOutputAsJson() throws IOException, ParseException {
@@ -117,8 +112,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
@BeforeEach
void beforeEach() {
output = tmpDir.resolve("out.dat");
command.clock = clock;
clock.setTo(now);
command.clock = fakeClock;
createTlds("xn--q9jyb4c", "example");
nameserver1 =
@@ -170,7 +164,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
@Test
void testSuccess_skipDeletedDomain() throws Exception {
persistResource(domain1.asBuilder().setDeletionTime(now).build());
persistResource(domain1.asBuilder().setDeletionTime(fakeClock.nowUtc()).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
assertThat((Iterable<?>) getOutputAsJson())
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
@@ -178,7 +172,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
@Test
void testSuccess_skipDeletedNameserver() throws Exception {
persistResource(nameserver1.asBuilder().setDeletionTime(now).build());
persistResource(nameserver1.asBuilder().setDeletionTime(fakeClock.nowUtc()).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
Iterable<?> output = (Iterable<?>) getOutputAsJson();
assertThat(output).containsAnyOf(DOMAIN1_OUTPUT, DOMAIN1_OUTPUT_ALT);
@@ -207,7 +201,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
domain1
.asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE)
.setDeletionTime(now.plusDays(30))
.setDeletionTime(fakeClock.nowUtc().plusDays(30))
.build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
assertThat((Iterable<?>) getOutputAsJson())
@@ -30,8 +30,8 @@ class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
@BeforeEach
void beforeEach() {
createTld("tld");
command.clock = fakeClock;
createTld("tld");
}
@Test
@@ -22,7 +22,6 @@ import static google.registry.testing.FullFieldsTestEntityHelper.makeHistoryEntr
import google.registry.model.domain.Domain;
import google.registry.model.domain.Period;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -30,12 +29,12 @@ import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetClaimsListCommand}. */
class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesCommand> {
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01T00:00:00Z"));
private Domain domain;
@BeforeEach
void beforeEach() {
fakeClock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
command.clock = fakeClock;
createTld("tld");
domain = persistActiveDomain("example.tld");
}
@@ -48,18 +47,18 @@ class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesComm
HistoryEntry.Type.DOMAIN_CREATE,
Period.create(1, Period.Unit.YEARS),
"created",
clock.nowUtc()));
fakeClock.nowUtc()));
runCommand("--id=example.tld", "--type=DOMAIN");
assertStdoutIs(
"""
Client: TheRegistrar
Time: 2000-01-01T00:00:00.000Z
Client TRID: ABC-123
Server TRID: server-trid
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml/>
Client: TheRegistrar
Time: 2000-01-01T00:00:00.000Z
Client TRID: ABC-123
Server TRID: server-trid
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml/>
""");
""");
}
@Test
@@ -70,8 +69,8 @@ class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesComm
HistoryEntry.Type.DOMAIN_CREATE,
Period.create(1, Period.Unit.YEARS),
"created",
clock.nowUtc()));
runCommand("--before", clock.nowUtc().minusMinutes(1).toString());
fakeClock.nowUtc()));
runCommand("--before", fakeClock.nowUtc().minusMinutes(1).toString());
assertStdoutIs("");
}
@@ -83,8 +82,8 @@ class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesComm
HistoryEntry.Type.DOMAIN_CREATE,
Period.create(1, Period.Unit.YEARS),
"created",
clock.nowUtc()));
runCommand("--after", clock.nowUtc().plusMinutes(1).toString());
fakeClock.nowUtc()));
runCommand("--after", fakeClock.nowUtc().plusMinutes(1).toString());
assertStdoutIs("");
}
@@ -96,22 +95,22 @@ class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesComm
HistoryEntry.Type.DOMAIN_CREATE,
Period.create(1, Period.Unit.YEARS),
"created",
clock.nowUtc()));
fakeClock.nowUtc()));
runCommand(
"--after",
clock.nowUtc().minusMinutes(1).toString(),
fakeClock.nowUtc().minusMinutes(1).toString(),
"--before",
clock.nowUtc().plusMinutes(1).toString());
fakeClock.nowUtc().plusMinutes(1).toString());
assertStdoutIs(
"""
Client: TheRegistrar
Time: 2000-01-01T00:00:00.000Z
Client TRID: ABC-123
Server TRID: server-trid
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml/>
Client: TheRegistrar
Time: 2000-01-01T00:00:00.000Z
Client TRID: ABC-123
Server TRID: server-trid
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml/>
""");
""");
}
@Test
@@ -122,20 +121,20 @@ class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntriesComm
HistoryEntry.Type.DOMAIN_CREATE,
Period.create(1, Period.Unit.YEARS),
"created",
clock.nowUtc())
fakeClock.nowUtc())
.asBuilder()
.setTrid(null)
.build());
runCommand("--id=example.tld", "--type=DOMAIN");
assertStdoutIs(
"""
Client: TheRegistrar
Time: 2000-01-01T00:00:00.000Z
Client TRID: null
Server TRID: null
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml/>
Client: TheRegistrar
Time: 2000-01-01T00:00:00.000Z
Client TRID: null
Server TRID: null
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xml/>
""");
""");
}
}
@@ -30,8 +30,8 @@ class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
@BeforeEach
void beforeEach() {
createTld("tld");
command.clock = fakeClock;
createTld("tld");
}
@Test
@@ -47,7 +47,6 @@ import google.registry.model.tld.Tld.TldState;
import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.FakeClock;
import google.registry.util.CidrAddressBlock;
import java.security.cert.CertificateParsingException;
import java.util.Optional;
@@ -70,8 +69,9 @@ class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
@BeforeEach
void beforeEach() {
fakeClock.setTo(DateTime.parse("2018-07-07TZ"));
command.clock = fakeClock;
command.passwordGenerator = passwordGenerator;
command.clock = new FakeClock(DateTime.parse("2018-07-07TZ"));
command.maybeGroupEmailAddress = Optional.of("group@example.com");
command.cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils();
command.iamClient = iamClient;
@@ -41,6 +41,7 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
registry = createTld(TLD_TEST, USD, initialPremiumListData);
}
@@ -60,7 +61,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
File tmpFile = tmpDir.resolve(String.format("%s.txt", TLD_TEST)).toFile();
String newPremiumListData = "omg,USD 1234";
Files.asCharSink(tmpFile, UTF_8).write(newPremiumListData);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = Paths.get(tmpFile.getPath());
command.name = TLD_TEST;
assertThat(command.prompt()).contains("Update premium list for prime?");
@@ -69,7 +69,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
@Test
void commandPrompt_successStageNoChange() throws Exception {
File tmpFile = tmpDir.resolve(String.format("%s.txt", TLD_TEST)).toFile();
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = Paths.get(tmpFile.getPath());
command.name = TLD_TEST;
assertThat(command.prompt())
@@ -82,7 +81,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
String newPremiumListData = "eth,USD 9999";
Files.asCharSink(tmpFile, UTF_8).write(newPremiumListData);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
// data come from @beforeEach of CreateOrUpdatePremiumListCommandTestCase.java
command.inputFile = Paths.get(tmpFile.getPath());
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile);
@@ -96,7 +94,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
void commandRun_successNoChange() throws Exception {
File tmpFile = tmpDir.resolve(String.format("%s.txt", TLD_TEST)).toFile();
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = Paths.get(tmpFile.getPath());
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile);
@@ -113,7 +110,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
String newPremiumListData = "eth,USD 9999";
Files.asCharSink(newPremiumFile, UTF_8).write(newPremiumListData);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
// data come from @beforeEach of CreateOrUpdatePremiumListCommandTestCase.java
command.inputFile = Paths.get(newPremiumFile.getPath());
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile);
@@ -129,7 +125,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
String premiumTerms = "foo,USD 9000\ndoge,USD 100\nelon,USD 2021";
Files.asCharSink(tmpFile, UTF_8).write(premiumTerms);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = Paths.get(tmpFile.getPath());
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile);
@@ -146,7 +141,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
Path tmpPath = tmpDir.resolve(String.format("%s.txt", TLD_TEST));
Files.write(new byte[0], tmpPath.toFile());
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = tmpPath;
command.name = TLD_TEST;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
@@ -156,7 +150,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
@Test
void commandPrompt_failureNoPreviousVersion() {
registry = createTld("random", null, null);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.name = "random";
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown)
@@ -166,13 +159,11 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
@Test
void commandPrompt_failureNoInputFile() {
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
assertThrows(NullPointerException.class, command::prompt);
}
@Test
void commandPrompt_failureTldFromNameDoesNotExist() {
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.name = "random2";
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown)
@@ -182,7 +173,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
@Test
void commandPrompt_failureTldFromInputFileDoesNotExist() {
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
// using tld extracted from file name but this tld is not part of the registry
command.inputFile = Paths.get(tmpDir.resolve("random3.txt").toFile().getPath());
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
@@ -197,7 +187,6 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
String newPremiumListData = "eth,USD 9999";
Files.asCharSink(tmpFile, UTF_8).write(newPremiumListData);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = Paths.get(tmpFile.getPath());
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile, "--dry_run");
@@ -53,6 +53,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
command.certificateChecker =
new CertificateChecker(
ImmutableSortedMap.of(START_OF_TIME, 825, DateTime.parse("2020-09-01T00:00:00Z"), 398),
@@ -98,7 +98,6 @@ class UpdateReservedListCommandTest
Files.asCharSink(reservedTermsFile, UTF_8).write(reservedTermsCsv);
reservedTermsPath = reservedTermsFile.getPath();
// create a command instance and assign its input
UpdateReservedListCommand command = new UpdateReservedListCommand();
command.input = Paths.get(reservedTermsPath);
// run again with terms from example_reserved_terms.csv
command.init();
@@ -110,7 +109,6 @@ class UpdateReservedListCommandTest
void testSuccess_withChanges() throws Exception {
// changes come from example_reserved_terms.csv, which are populated in @BeforeEach of
// CreateOrUpdateReservedListCommandTestCases.java
UpdateReservedListCommand command = new UpdateReservedListCommand();
command.input = Paths.get(reservedTermsPath);
command.init();
@@ -50,6 +50,7 @@ class ValidateLoginCredentialsCommandTest extends CommandTestCase<ValidateLoginC
@BeforeEach
void beforeEach() {
command.clock = fakeClock;
createTld("tld");
persistResource(
loadRegistrar("NewRegistrar")