Refactor bsa, dns, batch, and reporting packages to java.time (#3031)

This commit migrates the BSA, DNS, batch, and reporting packages from Joda-Time
to java.time. Key changes include:

- Updated Sleeper, Clock, and BigqueryUtils to use java.time types natively.
- Refactored models like RdeRevision and Tld to eliminate redundant Joda
  conversions, utilizing new DateTimeUtils static utilities for LocalDate.
- Improved test safety by replacing dynamic Instant.now() calls with static
  parsed constants.
- Migrated temporal arithmetic in test suites to use DateTimeUtils convenience
  methods (plusDays, minusDays).
- Updated BigqueryUtils serialization to preserve millisecond precision and
  formatting for large years, ensuring consistency with previous Joda behavior.
- Enhanced code readability by converting long concatenated strings to Java
  text blocks in LordnLogTest.
- Resolved environmental test failures in SyncRegistrarsSheetTest by
  synchronizing the FakeClock with the JPA extension.
- Updated project engineering standards (GEMINI.md) to prefer Truth's
  .hasValue() for Optional assertions.

Verified with a clean full build and all relevant test suites passing.
This commit is contained in:
Ben McIlwain
2026-05-06 21:44:40 +00:00
committed by GitHub
parent 81b3a2fc5b
commit 74f9f5d478
221 changed files with 1786 additions and 1587 deletions
@@ -20,6 +20,8 @@ import static google.registry.batch.AsyncTaskEnqueuer.PARAM_RESOURCE_KEY;
import static google.registry.batch.AsyncTaskEnqueuer.QUEUE_ASYNC_ACTIONS;
import static google.registry.testing.DatabaseHelper.persistActiveHost;
import static google.registry.testing.TestLogHandlerUtils.assertLogMessage;
import static google.registry.util.DateTimeUtils.plusDays;
import static google.registry.util.DateTimeUtils.plusHours;
import com.google.cloud.tasks.v2.HttpMethod;
import com.google.common.collect.ImmutableSortedSet;
@@ -31,9 +33,8 @@ import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeClock;
import google.registry.util.CapturingLogHandler;
import google.registry.util.JdkLoggerConfig;
import java.time.Instant;
import java.util.logging.Level;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -52,7 +53,7 @@ public class AsyncTaskEnqueuerTest {
private AsyncTaskEnqueuer asyncTaskEnqueuer;
private final CapturingLogHandler logHandler = new CapturingLogHandler();
private final FakeClock clock = new FakeClock(DateTime.parse("2015-05-18T12:34:56Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2015-05-18T12:34:56Z"));
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper(clock);
@BeforeEach
@@ -69,7 +70,7 @@ public class AsyncTaskEnqueuerTest {
void test_enqueueAsyncResave_success() {
Host host = persistActiveHost("ns1.example.tld");
asyncTaskEnqueuer.enqueueAsyncResave(
host.createVKey(), clock.nowUtc(), ImmutableSortedSet.of(clock.nowUtc().plusDays(5)));
host.createVKey(), clock.now(), ImmutableSortedSet.of(plusDays(clock.now(), 5)));
cloudTasksHelper.assertTasksEnqueued(
QUEUE_ASYNC_ACTIONS,
new CloudTasksHelper.TaskMatcher()
@@ -78,18 +79,18 @@ public class AsyncTaskEnqueuerTest {
.service("backend")
.header("content-type", "application/x-www-form-urlencoded")
.param(PARAM_RESOURCE_KEY, host.createVKey().stringify())
.param(PARAM_REQUESTED_TIME, clock.nowUtc().toString())
.scheduleTime(clock.nowUtc().plus(Duration.standardDays(5))));
.param(PARAM_REQUESTED_TIME, clock.now().toString())
.scheduleTime(plusDays(clock.now(), 5)));
}
@Test
void test_enqueueAsyncResave_multipleResaves() {
Host host = persistActiveHost("ns1.example.tld");
DateTime now = clock.nowUtc();
Instant now = clock.now();
asyncTaskEnqueuer.enqueueAsyncResave(
host.createVKey(),
now,
ImmutableSortedSet.of(now.plusHours(24), now.plusHours(50), now.plusHours(75)));
ImmutableSortedSet.of(plusHours(now, 24), plusHours(now, 50), plusHours(now, 75)));
cloudTasksHelper.assertTasksEnqueued(
QUEUE_ASYNC_ACTIONS,
new TaskMatcher()
@@ -99,8 +100,8 @@ public class AsyncTaskEnqueuerTest {
.header("content-type", "application/x-www-form-urlencoded")
.param(PARAM_RESOURCE_KEY, host.createVKey().stringify())
.param(PARAM_REQUESTED_TIME, now.toString())
.param(PARAM_RESAVE_TIMES, "2015-05-20T14:34:56.000Z,2015-05-21T15:34:56.000Z")
.scheduleTime(clock.nowUtc().plus(Duration.standardHours(24))));
.param(PARAM_RESAVE_TIMES, "2015-05-20T14:34:56Z,2015-05-21T15:34:56Z")
.scheduleTime(clock.nowUtc().plusHours(24)));
}
@MockitoSettings(strictness = Strictness.LENIENT)
@@ -108,7 +109,7 @@ public class AsyncTaskEnqueuerTest {
void test_enqueueAsyncResave_ignoresTasksTooFarIntoFuture() {
Host host = persistActiveHost("ns1.example.tld");
asyncTaskEnqueuer.enqueueAsyncResave(
host.createVKey(), clock.nowUtc(), ImmutableSortedSet.of(clock.nowUtc().plusDays(31)));
host.createVKey(), clock.now(), ImmutableSortedSet.of(plusDays(clock.now(), 31)));
cloudTasksHelper.assertNoTasksEnqueued(QUEUE_ASYNC_ACTIONS);
assertLogMessage(logHandler, Level.INFO, "Ignoring async re-save");
}
@@ -20,6 +20,10 @@ import static google.registry.testing.DatabaseHelper.loadByEntity;
import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
import static google.registry.testing.DatabaseHelper.persistDomainWithDependentResources;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.minusDays;
import static google.registry.util.DateTimeUtils.minusMonths;
import static google.registry.util.DateTimeUtils.plusMonths;
import static google.registry.util.DateTimeUtils.toDateTime;
import static org.mockito.Mockito.mock;
import com.google.common.collect.ImmutableList;
@@ -37,7 +41,6 @@ import google.registry.testing.FakeLockHandler;
import google.registry.testing.FakeResponse;
import google.registry.util.DateTimeUtils;
import java.time.Instant;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -45,7 +48,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Tests for {@link BulkDomainTransferAction}. */
public class BulkDomainTransferActionTest {
private final FakeClock fakeClock = new FakeClock(DateTime.parse("2024-01-01T00:00:00.000Z"));
private final FakeClock fakeClock = new FakeClock(Instant.parse("2024-01-01T00:00:00.000Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@@ -62,26 +65,26 @@ public class BulkDomainTransferActionTest {
@BeforeEach
void beforeEach() throws Exception {
createTld("tld");
DateTime now = fakeClock.nowUtc();
Instant now = fakeClock.now();
// The default registrar is TheRegistrar, which will be the losing registrar
activeDomain =
persistDomainWithDependentResources(
"active", "tld", now, now.minusDays(1), DateTimeUtils.END_OF_TIME);
"active", "tld", now, minusDays(now, 1), DateTimeUtils.END_INSTANT);
alreadyTransferredDomain =
persistResource(
persistDomainWithDependentResources(
"alreadytransferred", "tld", now, now.minusDays(1), DateTimeUtils.END_OF_TIME)
"alreadytransferred", "tld", now, minusDays(now, 1), DateTimeUtils.END_INSTANT)
.asBuilder()
.setPersistedCurrentSponsorRegistrarId("NewRegistrar")
.build());
pendingDeleteDomain =
persistResource(
persistDomainWithDependentResources(
"pendingdelete", "tld", now, now.minusDays(1), now.plusMonths(1))
"pendingdelete", "tld", now, minusDays(now, 1), plusMonths(now, 1))
.asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build());
deletedDomain = persistDeletedDomain("deleted.tld", now.minusMonths(1));
deletedDomain = persistDeletedDomain("deleted.tld", toDateTime(minusMonths(now, 1)));
}
@Test
@@ -47,7 +47,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -57,7 +56,7 @@ import org.mockito.ArgumentCaptor;
/** Unit tests for {@link CheckBulkComplianceAction}. */
public class CheckBulkComplianceActionTest {
// This is the default creation time for test data.
private final FakeClock clock = new FakeClock(DateTime.parse("2012-03-25TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("2012-03-25T00:00:00Z"));
private static final String CREATE_LIMIT_EMAIL_SUBJECT = "create limit subject";
private static final String DOMAIN_LIMIT_WARNING_EMAIL_SUBJECT = "domain limit warning subject";
private static final String DOMAIN_LIMIT_UPGRADE_EMAIL_SUBJECT = "domain limit upgrade subject";
@@ -39,10 +39,9 @@ import google.registry.testing.FakeClock;
import google.registry.testing.FakeSleeper;
import google.registry.util.Retrier;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
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.Test;
@@ -51,7 +50,7 @@ public class CloudTasksUtilsTest {
// Use a LinkedListMultimap to preserve order of the inserted entries for assertion.
private final LinkedListMultimap<String, String> params = LinkedListMultimap.create();
private final SerializableCloudTasksClient mockClient = mock(SerializableCloudTasksClient.class);
private final FakeClock clock = new FakeClock(DateTime.parse("2021-11-08"));
private final FakeClock clock = new FakeClock(Instant.parse("2021-11-08T00:00:00Z"));
private final CloudTasksUtils cloudTasksUtils =
new CloudTasksUtils(
new Retrier(new FakeSleeper(clock), 1),
@@ -78,7 +77,7 @@ public class CloudTasksUtilsTest {
IllegalArgumentException.class,
() ->
cloudTasksUtils.createTaskWithDelay(
TheAction.class, GET, params, Duration.standardMinutes(-10)));
TheAction.class, GET, params, Duration.ofMinutes(-10)));
assertThat(thrown).hasMessageThat().isEqualTo("Negative duration is not supported.");
}
@@ -217,8 +216,8 @@ public class CloudTasksUtilsTest {
assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0);
Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds());
Instant lowerBoundTime = Instant.ofEpochMilli(clock.nowUtc().getMillis());
Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(100).getMillis());
Instant lowerBoundTime = Instant.ofEpochMilli(clock.now().toEpochMilli());
Instant upperBound = Instant.ofEpochMilli(clock.now().plusSeconds(100).toEpochMilli());
assertThat(scheduleTime.isBefore(lowerBoundTime)).isFalse();
assertThat(upperBound.isBefore(scheduleTime)).isFalse();
@@ -248,14 +247,13 @@ public class CloudTasksUtilsTest {
@Test
void testSuccess_createTasks_withDelay() {
Task task =
cloudTasksUtils.createTaskWithDelay(
TheAction.class, GET, params, Duration.standardMinutes(10));
cloudTasksUtils.createTaskWithDelay(TheAction.class, GET, params, Duration.ofMinutes(10));
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(Instant.ofEpochSecond(task.getScheduleTime().getSeconds()))
.isEqualTo(Instant.ofEpochMilli(clock.nowUtc().plusMinutes(10).getMillis()));
.isEqualTo(Instant.ofEpochMilli(clock.now().plus(Duration.ofMinutes(10)).toEpochMilli()));
}
@Test
@@ -24,7 +24,6 @@ import static google.registry.testing.DatabaseHelper.loadByEntity;
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.END_INSTANT;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.minusDays;
import static google.registry.util.DateTimeUtils.minusMonths;
import static google.registry.util.DateTimeUtils.plusDays;
@@ -48,8 +47,8 @@ import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeLockHandler;
import google.registry.testing.FakeResponse;
import java.time.Instant;
import java.util.Optional;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -57,7 +56,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DeleteExpiredDomainsAction}. */
class DeleteExpiredDomainsActionTest {
private final FakeClock clock = new FakeClock(DateTime.parse("2016-06-13T20:21:22Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2016-06-13T20:21:22Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@@ -208,7 +207,7 @@ class DeleteExpiredDomainsActionTest {
.setTargetId("fizz.tld")
.setRegistrarId("TheRegistrar")
.setEventTime(plusYears(clock.now(), 1))
.setAutorenewEndTime(END_OF_TIME)
.setAutorenewEndTime(END_INSTANT)
.setHistoryEntry(createHistoryEntry);
}
}
@@ -28,7 +28,8 @@ import static google.registry.testing.DatabaseHelper.persistDomainAsDeleted;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.END_INSTANT;
import static google.registry.util.DateTimeUtils.minusYears;
import static google.registry.util.DateTimeUtils.toInstant;
import static google.registry.util.DateTimeUtils.plusYears;
import static google.registry.util.DateTimeUtils.toDateTime;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableSet;
@@ -49,11 +50,11 @@ import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import google.registry.testing.SystemPropertyExtension;
import google.registry.util.RegistryEnvironment;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.Set;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -62,7 +63,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DeleteProberDataAction}. */
class DeleteProberDataActionTest {
private static final DateTime DELETION_TIME = DateTime.parse("2010-01-01T00:00:00.000Z");
private static final Instant DELETION_TIME = Instant.parse("2010-01-01T00:00:00.000Z");
private final FakeClock clock = new FakeClock(Instant.parse("2021-01-01T00:00:00Z"));
@@ -270,7 +271,7 @@ class DeleteProberDataActionTest {
.asBuilder()
.setSubordinateHosts(ImmutableSet.of("ns1.blah.ib-any.test"))
.build(),
clock.nowUtc().minusYears(1));
minusYears(clock.now(), 1));
action.run();
assertAllExist(ImmutableSet.of(domainWithSubord));
@@ -293,32 +294,32 @@ class DeleteProberDataActionTest {
* Persists and returns a domain and a descendant history entry, billing event, and poll message.
*/
private static Set<ImmutableObject> persistDomainAndDescendants(String fqdn) {
Domain domain = persistDeletedDomain(fqdn, DELETION_TIME);
Domain domain = persistDeletedDomain(fqdn, toDateTime(DELETION_TIME));
DomainHistory historyEntry =
persistResource(
new DomainHistory.Builder()
.setDomain(domain)
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setRegistrarId("TheRegistrar")
.setModificationTime(toInstant(DELETION_TIME.minusYears(3)))
.setModificationTime(minusYears(DELETION_TIME, 3))
.build());
BillingEvent billingEvent =
persistResource(
new BillingEvent.Builder()
.setDomainHistory(historyEntry)
.setBillingTime(toInstant(DELETION_TIME.plusYears(1)))
.setBillingTime(plusYears(DELETION_TIME, 1))
.setCost(Money.parse("USD 10"))
.setPeriodYears(1)
.setReason(Reason.CREATE)
.setRegistrarId("TheRegistrar")
.setEventTime(toInstant(DELETION_TIME))
.setEventTime(DELETION_TIME)
.setTargetId(fqdn)
.build());
PollMessage.OneTime pollMessage =
persistResource(
new PollMessage.OneTime.Builder()
.setHistoryEntry(historyEntry)
.setEventTime(toInstant(DELETION_TIME))
.setEventTime(DELETION_TIME)
.setRegistrarId("TheRegistrar")
.setMsg("Domain registered")
.build());
@@ -327,7 +328,7 @@ class DeleteProberDataActionTest {
GracePeriod.create(
ADD,
domain.getRepoId(),
toInstant(DELETION_TIME.plusDays(5)),
DELETION_TIME.plus(Duration.ofDays(5)),
"TheRegistrar",
billingEvent.createVKey()));
domain = persistResource(domain.asBuilder().addGracePeriod(gracePeriod).build());
@@ -16,7 +16,6 @@ package google.registry.batch;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.toDateTime;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
@@ -74,10 +73,7 @@ public class ExpandBillingRecurrencesActionTest extends BeamActionTestBase {
expectedParameters.put("endTime", "2020-02-02T00:00:00Z");
expectedParameters.put("isDryRun", "false");
expectedParameters.put("advanceCursor", "true");
tm().transact(
() ->
tm().put(
Cursor.createGlobal(CursorType.RECURRING_BILLING, toDateTime(cursorTime))));
tm().transact(() -> tm().put(Cursor.createGlobal(CursorType.RECURRING_BILLING, cursorTime)));
}
@Test
@@ -51,9 +51,9 @@ import google.registry.tools.DomainLockUtils;
import google.registry.util.EmailMessage;
import google.registry.util.StringGenerator.Alphabets;
import jakarta.mail.internet.InternetAddress;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
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;
@@ -71,7 +71,7 @@ public class RelockDomainActionTest {
private static final String LOCK_EMAIL_ADDRESS = "Marla.Singer.RegistryLock@crr.com";
private final FakeResponse response = new FakeResponse();
private final FakeClock clock = new FakeClock(DateTime.parse("2015-05-18T12:34:56Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2015-05-18T12:34:56Z"));
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper(clock);
private final DomainLockUtils domainLockUtils =
new DomainLockUtils(
@@ -130,7 +130,7 @@ public class RelockDomainActionTest {
action.run();
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
assertThat(response.getPayload()).isEqualTo("Re-lock failed: Unknown revision ID 12128675309");
assertTaskEnqueued(1, 12128675309L, Duration.standardMinutes(10)); // should retry, transient
assertTaskEnqueued(1, 12128675309L, Duration.ofMinutes(10)); // should retry, transient
}
@Test
@@ -169,7 +169,7 @@ public class RelockDomainActionTest {
@Test
void testFailure_domainDeleted() throws Exception {
persistDomainAsDeleted(domain, clock.nowUtc());
persistDomainAsDeleted(domain, clock.now());
action.run();
String expectedFailureMessage = "Domain example.tld has been deleted.";
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
@@ -248,7 +248,7 @@ public class RelockDomainActionTest {
assertTaskEnqueued(
RelockDomainAction.ATTEMPTS_BEFORE_SLOWDOWN + 1,
oldLock.getRevisionId(),
Duration.standardHours(1));
Duration.ofHours(1));
}
private void assertSuccessEmailSent() throws Exception {
@@ -304,7 +304,7 @@ public class RelockDomainActionTest {
}
private void assertTaskEnqueued(int numAttempts) {
assertTaskEnqueued(numAttempts, oldLock.getRevisionId(), Duration.standardMinutes(10));
assertTaskEnqueued(numAttempts, oldLock.getRevisionId(), Duration.ofMinutes(10));
}
private void assertTaskEnqueued(int numAttempts, long oldUnlockRevisionId, Duration duration) {
@@ -317,7 +317,7 @@ public class RelockDomainActionTest {
RelockDomainAction.OLD_UNLOCK_REVISION_ID_PARAM,
String.valueOf(oldUnlockRevisionId))
.param(RelockDomainAction.PREVIOUS_ATTEMPTS_PARAM, String.valueOf(numAttempts))
.scheduleTime(clock.nowUtc().plus(duration)));
.scheduleTime(clock.nowUtc().plusMillis((int) duration.toMillis())));
}
private RelockDomainAction createAction(Long oldUnlockRevisionId) throws Exception {
@@ -41,7 +41,7 @@ import google.registry.request.Response;
import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -60,7 +60,7 @@ public class ResaveEntityActionTest {
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
@Mock private Response response;
private final FakeClock clock = new FakeClock(DateTime.parse("2016-02-11T10:00:00Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2016-02-11T10:00:00Z"));
private AsyncTaskEnqueuer asyncTaskEnqueuer;
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper(clock);
@@ -72,7 +72,7 @@ public class ResaveEntityActionTest {
}
private void runAction(
String resourceKey, DateTime requestedTime, ImmutableSortedSet<DateTime> resaveTimes) {
String resourceKey, Instant requestedTime, ImmutableSortedSet<Instant> resaveTimes) {
ResaveEntityAction action =
new ResaveEntityAction(
resourceKey, requestedTime, resaveTimes, asyncTaskEnqueuer, response);
@@ -87,17 +87,17 @@ public class ResaveEntityActionTest {
persistDomainWithDependentResources(
"domain",
"tld",
DateTime.parse("2016-02-06T10:00:00Z"),
DateTime.parse("2016-02-06T10:00:00Z"),
DateTime.parse("2017-01-02T10:11:00Z")),
DateTime.parse("2016-02-06T10:00:00Z"),
DateTime.parse("2016-02-11T10:00:00Z"),
DateTime.parse("2017-01-02T10:11:00Z"));
Instant.parse("2016-02-06T10:00:00Z"),
Instant.parse("2016-02-06T10:00:00Z"),
Instant.parse("2017-01-02T10:11:00Z")),
Instant.parse("2016-02-06T10:00:00Z"),
Instant.parse("2016-02-11T10:00:00Z"),
Instant.parse("2017-01-02T10:11:00Z"));
clock.advanceOneMilli();
assertThat(domain.getCurrentSponsorRegistrarId()).isEqualTo("TheRegistrar");
runAction(
domain.createVKey().stringify(),
DateTime.parse("2016-02-06T10:00:01Z"),
Instant.parse("2016-02-06T10:00:01Z"),
ImmutableSortedSet.of());
Domain resavedDomain = loadByEntity(domain);
assertThat(resavedDomain.getCurrentSponsorRegistrarId()).isEqualTo("NewRegistrar");
@@ -122,13 +122,13 @@ public class ResaveEntityActionTest {
"TheRegistrar")))
.build());
clock.advanceBy(standardDays(30));
DateTime requestedTime = clock.nowUtc();
Instant requestedTime = clock.now();
assertThat(domain.getGracePeriods()).isNotEmpty();
runAction(
domain.createVKey().stringify(),
requestedTime,
ImmutableSortedSet.of(requestedTime.plusDays(5)));
ImmutableSortedSet.of(plusDays(requestedTime, 5)));
Domain resavedDomain = loadByEntity(domain);
assertThat(resavedDomain.getGracePeriods()).isEmpty();
@@ -141,17 +141,17 @@ public class ResaveEntityActionTest {
.header("content-type", "application/x-www-form-urlencoded")
.param(PARAM_RESOURCE_KEY, resavedDomain.createVKey().stringify())
.param(PARAM_REQUESTED_TIME, requestedTime.toString())
.scheduleTime(clock.nowUtc().plus(standardDays(5))));
.scheduleTime(clock.nowUtc().plusDays(5)));
}
@Test
void test_queuedTaskForNonExistentDomain_failsPermanently() {
DateTime requestedTime = clock.nowUtc();
Instant requestedTime = clock.now();
// It should complete its run without throwing an exception (that would cause a retry) ...
runAction(
newDomain("nonexistent.tld").createVKey().stringify(),
requestedTime,
ImmutableSortedSet.of(requestedTime.plusDays(5)));
ImmutableSortedSet.of(plusDays(requestedTime, 5)));
// ... and it shouldn't enqueue the subsequent re-save 5 days later.
cloudTasksHelper.assertNoTasksEnqueued(QUEUE_ASYNC_ACTIONS);
}
@@ -19,6 +19,7 @@ import static google.registry.persistence.transaction.JpaTransactionManagerExten
import static google.registry.testing.DatabaseHelper.loadByEntity;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.DatabaseHelper.persistResources;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.apache.http.HttpStatus.SC_OK;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -44,6 +45,7 @@ import google.registry.testing.FakeResponse;
import google.registry.util.SelfSignedCaCertificate;
import jakarta.mail.internet.InternetAddress;
import java.security.cert.X509Certificate;
import java.time.Instant;
import java.util.Optional;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
@@ -122,7 +124,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
.build());
persistSampleContacts(registrar, Type.TECH);
assertThat(
action.sendNotificationEmail(registrar, START_OF_TIME, CertificateType.FAILOVER, cert))
action.sendNotificationEmail(registrar, START_INSTANT, CertificateType.FAILOVER, cert))
.isEqualTo(true);
}
@@ -144,7 +146,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
.build());
persistSampleContacts(registrar, Type.ADMIN);
assertThat(
action.sendNotificationEmail(registrar, START_OF_TIME, CertificateType.FAILOVER, cert))
action.sendNotificationEmail(registrar, START_INSTANT, CertificateType.FAILOVER, cert))
.isEqualTo(true);
}
@@ -166,7 +168,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
assertThat(
action.sendNotificationEmail(
registrar,
START_OF_TIME,
START_INSTANT,
CertificateType.FAILOVER,
Optional.of(
certificateChecker.serializeCertificate(
@@ -190,7 +192,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
Optional.of(certificateChecker.serializeCertificate(expiringCertificate));
assertThat(
action.sendNotificationEmail(
sampleRegistrar, START_OF_TIME, CertificateType.FAILOVER, cert))
sampleRegistrar, START_INSTANT, CertificateType.FAILOVER, cert))
.isEqualTo(false);
}
@@ -231,7 +233,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
RuntimeException.class,
() ->
action.sendNotificationEmail(
registrar, START_OF_TIME, CertificateType.FAILOVER, cert));
registrar, START_INSTANT, CertificateType.FAILOVER, cert));
assertThat(thrown)
.hasMessageThat()
.contains(
@@ -244,7 +246,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
void sendNotificationEmail_returnsFalse_noCertificate() {
assertThat(
action.sendNotificationEmail(
sampleRegistrar, START_OF_TIME, CertificateType.FAILOVER, Optional.empty()))
sampleRegistrar, START_INSTANT, CertificateType.FAILOVER, Optional.empty()))
.isEqualTo(false);
}
@@ -338,7 +340,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
Registrar registrar =
createRegistrar("testClientId", "registrar", expiringCertificate, null).build();
persistResource(registrar);
action.updateLastNotificationSentDate(registrar, clock.nowUtc(), CertificateType.PRIMARY);
action.updateLastNotificationSentDate(registrar, clock.now(), CertificateType.PRIMARY);
assertThat(loadByEntity(registrar).getLastExpiringCertNotificationSentDate())
.isEqualTo(clock.now());
}
@@ -354,7 +356,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
Registrar registrar =
createRegistrar("testClientId", "registrar", null, expiringCertificate).build();
persistResource(registrar);
action.updateLastNotificationSentDate(registrar, clock.nowUtc(), CertificateType.FAILOVER);
action.updateLastNotificationSentDate(registrar, clock.now(), CertificateType.FAILOVER);
assertThat(loadByEntity(registrar).getLastExpiringFailoverCertNotificationSentDate())
.isEqualTo(clock.now());
}
@@ -395,7 +397,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
IllegalArgumentException.class,
() ->
action.updateLastNotificationSentDate(
registrar, clock.nowUtc(), CertificateType.valueOf("randomType")));
registrar, clock.now(), CertificateType.valueOf("randomType")));
assertThat(thrown).hasMessageThat().contains("No enum constant");
}
@@ -574,15 +576,15 @@ class SendExpiringCertificateNotificationEmailActionTest {
@Test
void getEmailBody_returnsEmailBodyText() {
String registrarName = "good registrar";
String certExpirationDateStr = "2021-06-15";
String certExpirationDateStr = "2021-06-15T00:00:00Z";
CertificateType certificateType = CertificateType.PRIMARY;
String registrarId = "registrarid";
String emailBody =
action.getEmailBody(
registrarName, certificateType, DateTime.parse(certExpirationDateStr), registrarId);
registrarName, certificateType, Instant.parse(certExpirationDateStr), registrarId);
assertThat(emailBody).contains(registrarName);
assertThat(emailBody).contains(certificateType.getDisplayName());
assertThat(emailBody).contains(certExpirationDateStr);
assertThat(emailBody).contains("2021-06-15");
assertThat(emailBody).contains(registrarId + "@registry.example");
assertThat(emailBody).doesNotContain("%1$s");
assertThat(emailBody).doesNotContain("%2$s");
@@ -608,7 +610,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
IllegalArgumentException.class,
() ->
action.getEmailBody(
"good registrar", null, DateTime.parse("2021-06-15"), "registrarId"));
"good registrar", null, Instant.parse("2021-06-15T00:00:00Z"), "registrarId"));
assertThat(thrown).hasMessageThat().contains("Certificate type cannot be null");
}
@@ -621,7 +623,7 @@ class SendExpiringCertificateNotificationEmailActionTest {
action.getEmailBody(
"good registrar",
CertificateType.FAILOVER,
DateTime.parse("2021-06-15"),
Instant.parse("2021-06-15T00:00:00Z"),
null));
assertThat(thrown).hasMessageThat().contains("Registrar Id cannot be null");
}
@@ -135,7 +135,7 @@ class SyncRemoteCacheActionTest {
assertThat(
DatabaseHelper.loadByKey(Cursor.createGlobalVKey(REMOTE_CACHE_DOMAIN_SYNC))
.getCursorTimeInstant()
.getCursorTime()
.toString())
.isEqualTo("2025-01-01T00:00:00.001Z");
}
@@ -205,7 +205,7 @@ class SyncRemoteCacheActionTest {
assertThat(
DatabaseHelper.loadByKey(Cursor.createGlobalVKey(REMOTE_CACHE_HOST_SYNC))
.getCursorTimeInstant()
.getCursorTime()
.toString())
.isEqualTo("2025-01-01T00:00:00.001Z");
}
@@ -36,6 +36,9 @@ import static google.registry.util.DateTimeUtils.plusDays;
import static google.registry.util.DateTimeUtils.plusYears;
import static google.registry.util.DateTimeUtils.toDateTime;
import static google.registry.util.DateTimeUtils.toInstant;
import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.HOURS;
import static java.time.temporal.ChronoUnit.MILLIS;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -59,7 +62,6 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -82,10 +84,9 @@ public class ExpandBillingRecurrencesPipelineTest {
private final FakeClock clock = new FakeClock(Instant.parse("2021-02-02T00:00:05.000Z"));
private final Instant startTime = Instant.parse("2021-02-01T00:00:00.000Z");
private Instant endTime = Instant.parse("2021-02-02T00:00:00.000Z");
private final Cursor cursor = Cursor.createGlobal(RECURRING_BILLING, toDateTime(startTime));
private final Cursor cursor = Cursor.createGlobal(RECURRING_BILLING, startTime);
private Domain domain;
@@ -117,14 +118,13 @@ public class ExpandBillingRecurrencesPipelineTest {
// Set up the database.
createTld("tld");
billingRecurrence =
createDomainAtTime("example.tld", minusYears(startTime, 1).plus(12, ChronoUnit.HOURS));
billingRecurrence = createDomainAtTime("example.tld", minusYears(startTime, 1).plus(12, HOURS));
domain = ForeignKeyUtils.loadResource(Domain.class, "example.tld", clock.now()).get();
}
@Test
void testFailure_endTimeAfterNow() {
options.setEndTime(clock.now().plus(1, ChronoUnit.MILLIS).toString());
options.setEndTime(clock.now().plus(1, MILLIS).toString());
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, this::runPipeline);
assertThat(thrown)
@@ -134,7 +134,7 @@ public class ExpandBillingRecurrencesPipelineTest {
@Test
void testFailure_endTimeBeforeStartTime() {
options.setEndTime(startTime.minus(1, ChronoUnit.MILLIS).toString());
options.setEndTime(startTime.minus(1, MILLIS).toString());
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, this::runPipeline);
assertThat(thrown)
@@ -189,11 +189,7 @@ public class ExpandBillingRecurrencesPipelineTest {
@Test
void testFailure_expandSingleEvent_cursorNotAtStartTime() {
tm().transact(
() ->
tm().put(
Cursor.createGlobal(
RECURRING_BILLING, toDateTime(startTime.plusMillis(1)))));
tm().transact(() -> tm().put(Cursor.createGlobal(RECURRING_BILLING, startTime.plusMillis(1))));
PipelineExecutionException thrown =
assertThrows(PipelineExecutionException.class, this::runPipeline);
@@ -222,7 +218,7 @@ public class ExpandBillingRecurrencesPipelineTest {
persistResource(
billingRecurrence
.asBuilder()
.setRecurrenceEndTime(billingRecurrence.getEventTime().minus(1, ChronoUnit.DAYS))
.setRecurrenceEndTime(billingRecurrence.getEventTime().minus(1, DAYS))
.build());
runPipeline();
assertNoExpansionsHappened();
@@ -232,10 +228,7 @@ public class ExpandBillingRecurrencesPipelineTest {
void testSuccess_noExpansion_recurrenceClosedBeforeStartTime() {
billingRecurrence =
persistResource(
billingRecurrence
.asBuilder()
.setRecurrenceEndTime(startTime.minus(1, ChronoUnit.DAYS))
.build());
billingRecurrence.asBuilder().setRecurrenceEndTime(startTime.minus(1, DAYS)).build());
runPipeline();
assertNoExpansionsHappened();
}
@@ -247,7 +240,7 @@ public class ExpandBillingRecurrencesPipelineTest {
billingRecurrence
.asBuilder()
.setEventTime(minusYears(billingRecurrence.getEventTime(), 1))
.setRecurrenceEndTime(startTime.plus(6, ChronoUnit.HOURS))
.setRecurrenceEndTime(startTime.plus(6, HOURS))
.build());
runPipeline();
assertNoExpansionsHappened();
@@ -330,7 +323,7 @@ public class ExpandBillingRecurrencesPipelineTest {
.asBuilder()
.setPremiumList(persistPremiumList("premium", USD, "other,USD 100"))
.build());
Instant otherCreateTime = minusYears(startTime, 1).plus(5, ChronoUnit.HOURS);
Instant otherCreateTime = minusYears(startTime, 1).plus(5, HOURS);
BillingRecurrence otherBillingRecurrence = createDomainAtTime("other.test", otherCreateTime);
Domain otherDomain =
ForeignKeyUtils.loadResource(Domain.class, "other.test", clock.now()).get();
@@ -530,7 +523,7 @@ public class ExpandBillingRecurrencesPipelineTest {
private static void assertCursorAt(Instant expectedCursorTime) {
Cursor cursor = tm().transact(() -> tm().loadByKey(Cursor.createGlobalVKey(RECURRING_BILLING)));
assertThat(cursor).isNotNull();
assertThat(cursor.getCursorTimeInstant()).isEqualTo(expectedCursorTime);
assertThat(cursor.getCursorTime()).isEqualTo(expectedCursorTime);
}
private static void assertCursorAt(DateTime expectedCursorTime) {
@@ -83,6 +83,7 @@ import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeKeyringModule;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.function.Function;
import java.util.regex.Matcher;
@@ -96,7 +97,6 @@ import org.apache.beam.sdk.values.PCollection;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -120,12 +120,9 @@ public class RdePipelineTest {
private final ImmutableSet<PendingDeposit> pendings =
ImmutableSet.of(
PendingDeposit.create(
"soy", toDateTime(now), FULL, RDE_STAGING, Duration.standardDays(1)),
PendingDeposit.create(
"soy", toDateTime(now), THIN, RDE_STAGING, Duration.standardDays(1)),
PendingDeposit.create(
"fun", toDateTime(now), FULL, RDE_STAGING, Duration.standardDays(1)));
PendingDeposit.create("soy", now, FULL, RDE_STAGING, Duration.ofDays(1)),
PendingDeposit.create("soy", now, THIN, RDE_STAGING, Duration.ofDays(1)),
PendingDeposit.create("fun", now, FULL, RDE_STAGING, Duration.ofDays(1)));
private final ImmutableList<DepositFragment> brdaFragments =
ImmutableList.of(
@@ -229,10 +226,10 @@ public class RdePipelineTest {
tm().transact(
() -> {
tm().put(Cursor.createScoped(CursorType.BRDA, toDateTime(now), Tld.get("soy")));
tm().put(Cursor.createScoped(RDE_STAGING, toDateTime(now), Tld.get("soy")));
RdeRevision.saveRevision("soy", toDateTime(now), THIN, 0);
RdeRevision.saveRevision("soy", toDateTime(now), FULL, 0);
tm().put(Cursor.createScoped(CursorType.BRDA, now, Tld.get("soy")));
tm().put(Cursor.createScoped(RDE_STAGING, now, Tld.get("soy")));
RdeRevision.saveRevision("soy", now, THIN, 0);
RdeRevision.saveRevision("soy", now, FULL, 0);
});
// This host is never referenced.
@@ -281,7 +278,7 @@ public class RdePipelineTest {
// Set the clock to 2000-01-02, any change after hereafter should not show up in the
// resulting deposit fragments.
clock.advanceBy(Duration.standardDays(2));
clock.advanceBy(Duration.ofDays(2));
persistDomainHistory(kittyDomain.asBuilder().setDeletionTime(clock.now()).build());
Host futureHost = persistActiveHost("ns1.future.tld");
persistHostHistory(futureHost);
@@ -313,14 +310,9 @@ public class RdePipelineTest {
options.setPendings(
encodePendingDeposits(
ImmutableSet.of(
PendingDeposit.create("soy", now, FULL, RDE_STAGING, Duration.ofDays(1)),
PendingDeposit.create(
"soy", toDateTime(now), FULL, RDE_STAGING, Duration.standardDays(1)),
PendingDeposit.create(
"soy",
toDateTime(now.plusSeconds(1)),
THIN,
RDE_STAGING,
Duration.standardDays(1)))));
"soy", now.plusSeconds(1), THIN, RDE_STAGING, Duration.ofDays(1)))));
assertThrows(
IllegalArgumentException.class,
() -> new RdePipeline(options, gcsUtils, cloudTasksHelper.getTestCloudTasksUtils()));
@@ -438,10 +430,9 @@ public class RdePipelineTest {
@RetryingTest(4)
void testSuccess_persistData() throws Exception {
PendingDeposit brdaKey =
PendingDeposit.create(
"soy", toDateTime(now), THIN, CursorType.BRDA, Duration.standardDays(1));
PendingDeposit.create("soy", now, THIN, CursorType.BRDA, Duration.ofDays(1));
PendingDeposit rdeKey =
PendingDeposit.create("soy", toDateTime(now), FULL, RDE_STAGING, Duration.standardDays(1));
PendingDeposit.create("soy", now, FULL, RDE_STAGING, Duration.ofDays(1));
verifyFiles(ImmutableMap.of(brdaKey, brdaFragments, rdeKey, rdeFragments), false);
@@ -464,7 +455,7 @@ public class RdePipelineTest {
.path("/_dr/task/brdaCopy")
.service("backend")
.param("tld", "soy")
.param("watermark", toDateTime(now).toString())
.param("watermark", now.toString())
.param("prefix", "rde-job/"));
cloudTasksHelper.assertTasksEnqueued(
"rde-upload",
@@ -478,10 +469,8 @@ public class RdePipelineTest {
// The GCS folder listing can be a bit flaky, so retry if necessary
@RetryingTest(4)
void testSuccess_persistData_manual() throws Exception {
PendingDeposit brdaKey =
PendingDeposit.createInManualOperation("soy", toDateTime(now), THIN, "test/", 0);
PendingDeposit rdeKey =
PendingDeposit.createInManualOperation("soy", toDateTime(now), FULL, "test/", 0);
PendingDeposit brdaKey = PendingDeposit.createInManualOperation("soy", now, THIN, "test/", 0);
PendingDeposit rdeKey = PendingDeposit.createInManualOperation("soy", now, FULL, "test/", 0);
verifyFiles(ImmutableMap.of(brdaKey, brdaFragments, rdeKey, rdeFragments), true);
@@ -561,9 +550,7 @@ public class RdePipelineTest {
private static Instant loadCursorTime(CursorType type) {
return tm().transact(
() ->
tm().loadByKey(Cursor.createScopedVKey(type, Tld.get("soy")))
.getCursorTimeInstant());
() -> tm().loadByKey(Cursor.createScopedVKey(type, Tld.get("soy"))).getCursorTime());
}
private static Function<DepositFragment, String> getXmlElement(String pattern) {
@@ -27,6 +27,7 @@ import static google.registry.testing.DatabaseHelper.persistDomainWithPendingTra
import static google.registry.testing.DatabaseHelper.persistNewRegistrars;
import static google.registry.util.DateTimeUtils.plusYears;
import static google.registry.util.DateTimeUtils.toDateTime;
import static java.time.temporal.ChronoUnit.DAYS;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -44,7 +45,6 @@ import google.registry.persistence.transaction.JpaTransactionManager;
import google.registry.persistence.transaction.TransactionManagerFactory;
import google.registry.testing.FakeClock;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
import org.hibernate.cfg.Environment;
import org.joda.time.DateTime;
@@ -101,11 +101,11 @@ public class ResaveAllEppResourcesPipelineTest {
persistDomainWithDependentResources(
"domain",
"tld",
toDateTime(now.minus(5, ChronoUnit.DAYS)),
toDateTime(now.minus(5, ChronoUnit.DAYS)),
toDateTime(now.minus(5, DAYS)),
toDateTime(now.minus(5, DAYS)),
toDateTime(plusYears(now, 2))),
toDateTime(now.minus(4, ChronoUnit.DAYS)),
toDateTime(now.minus(1, ChronoUnit.DAYS)),
toDateTime(now.minus(4, DAYS)),
toDateTime(now.minus(1, DAYS)),
toDateTime(plusYears(now, 2)));
assertThat(domain.getStatusValues()).contains(StatusValue.PENDING_TRANSFER);
assertThat(domain.getUpdateTimestamp().getTimestamp()).isEqualTo(now);
@@ -19,46 +19,45 @@ import static google.registry.bigquery.BigqueryUtils.fromBigqueryTimestampString
import static google.registry.bigquery.BigqueryUtils.toBigqueryTimestamp;
import static google.registry.bigquery.BigqueryUtils.toBigqueryTimestampString;
import static google.registry.bigquery.BigqueryUtils.toJobReferenceString;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.END_INSTANT;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.api.services.bigquery.model.JobReference;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import java.util.concurrent.TimeUnit;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link BigqueryUtils}. */
class BigqueryUtilsTest {
private static final DateTime DATE_0 = DateTime.parse("2014-07-17T20:35:42Z");
private static final DateTime DATE_1 = DateTime.parse("2014-07-17T20:35:42.1Z");
private static final DateTime DATE_2 = DateTime.parse("2014-07-17T20:35:42.12Z");
private static final DateTime DATE_3 = DateTime.parse("2014-07-17T20:35:42.123Z");
private static final Instant DATE_0 = Instant.parse("2014-07-17T20:35:42Z");
private static final Instant DATE_1 = Instant.parse("2014-07-17T20:35:42.1Z");
private static final Instant DATE_2 = Instant.parse("2014-07-17T20:35:42.12Z");
private static final Instant DATE_3 = Instant.parse("2014-07-17T20:35:42.123Z");
@Test
void test_toBigqueryTimestampString() {
assertThat(toBigqueryTimestampString(START_OF_TIME)).isEqualTo("1970-01-01 00:00:00.000");
assertThat(toBigqueryTimestampString(START_INSTANT)).isEqualTo("1970-01-01 00:00:00.000");
assertThat(toBigqueryTimestampString(DATE_0)).isEqualTo("2014-07-17 20:35:42.000");
assertThat(toBigqueryTimestampString(DATE_1)).isEqualTo("2014-07-17 20:35:42.100");
assertThat(toBigqueryTimestampString(DATE_2)).isEqualTo("2014-07-17 20:35:42.120");
assertThat(toBigqueryTimestampString(DATE_3)).isEqualTo("2014-07-17 20:35:42.123");
assertThat(toBigqueryTimestampString(END_OF_TIME)).isEqualTo("294247-01-10 04:00:54.775");
assertThat(toBigqueryTimestampString(END_INSTANT)).isEqualTo("294247-01-10 04:00:54.775");
}
@Test
void test_toBigqueryTimestampString_convertsToUtc() {
assertThat(toBigqueryTimestampString(START_OF_TIME.withZone(DateTimeZone.forOffsetHours(5))))
.isEqualTo("1970-01-01 00:00:00.000");
assertThat(toBigqueryTimestampString(DateTime.parse("1970-01-01T00:00:00-0500")))
assertThat(toBigqueryTimestampString(Instant.parse("1970-01-01T05:00:00Z")))
.isEqualTo("1970-01-01 05:00:00.000");
}
@Test
void test_fromBigqueryTimestampString_startAndEndOfTime() {
assertThat(fromBigqueryTimestampString("1970-01-01 00:00:00 UTC")).isEqualTo(START_OF_TIME);
assertThat(fromBigqueryTimestampString("294247-01-10 04:00:54.775 UTC")).isEqualTo(END_OF_TIME);
assertThat(fromBigqueryTimestampString("1970-01-01 00:00:00 UTC")).isEqualTo(START_INSTANT);
assertThat(fromBigqueryTimestampString("294247-01-10 04:00:54.775 UTC")).isEqualTo(END_INSTANT);
}
@Test
@@ -78,20 +77,20 @@ class BigqueryUtilsTest {
@Test
void testFailure_fromBigqueryTimestampString_nonUtcTimeZone() {
assertThrows(
IllegalArgumentException.class,
DateTimeParseException.class,
() -> fromBigqueryTimestampString("2014-01-01 01:01:01 +05:00"));
}
@Test
void testFailure_fromBigqueryTimestampString_noTimeZone() {
assertThrows(
IllegalArgumentException.class, () -> fromBigqueryTimestampString("2014-01-01 01:01:01"));
DateTimeParseException.class, () -> fromBigqueryTimestampString("2014-01-01 01:01:01"));
}
@Test
void testFailure_fromBigqueryTimestampString_tooManyMillisecondDigits() {
assertThrows(
IllegalArgumentException.class,
DateTimeParseException.class,
() -> fromBigqueryTimestampString("2014-01-01 01:01:01.1234 UTC"));
}
@@ -116,12 +115,12 @@ class BigqueryUtilsTest {
@Test
void test_toBigqueryTimestamp_datetimeConversion() {
assertThat(toBigqueryTimestamp(START_OF_TIME)).isEqualTo("0.000000");
assertThat(toBigqueryTimestamp(START_INSTANT)).isEqualTo("0.000000");
assertThat(toBigqueryTimestamp(DATE_0)).isEqualTo("1405629342.000000");
assertThat(toBigqueryTimestamp(DATE_1)).isEqualTo("1405629342.100000");
assertThat(toBigqueryTimestamp(DATE_2)).isEqualTo("1405629342.120000");
assertThat(toBigqueryTimestamp(DATE_3)).isEqualTo("1405629342.123000");
assertThat(toBigqueryTimestamp(END_OF_TIME)).isEqualTo("9223372036854.775000");
assertThat(toBigqueryTimestamp(END_INSTANT)).isEqualTo("9223372036854.775000");
}
@Test
@@ -20,9 +20,8 @@ import static google.registry.bsa.persistence.BsaTestingUtils.createDownloadSche
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTlds;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.Duration.standardDays;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -43,11 +42,11 @@ import google.registry.testing.FakeClock;
import google.registry.testing.FakeLockHandler;
import google.registry.testing.FakeResponse;
import java.security.MessageDigest;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.stream.Stream;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -59,7 +58,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class BsaDownloadFunctionalTest {
static final DateTime TEST_START_TIME = DateTime.parse("2024-01-01T00:00:00Z");
static final Instant TEST_START_TIME = Instant.parse("2024-01-01T00:00:00Z");
static final String BSA_CSV_HEADER = "domainLabel,orderIDs";
@Mock BlockListFetcher blockListFetcher;
@Mock BsaReportSender bsaReportSender;
@@ -83,7 +82,9 @@ class BsaDownloadFunctionalTest {
.forEach(
tld ->
persistResource(
tld.asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()));
tld.asBuilder()
.setBsaEnrollStartTimeInstant(Optional.of(START_INSTANT))
.build()));
gcsClient =
new GcsClient(new GcsUtils(LocalStorageHelper.getOptions()), "my-bucket", "SHA-256");
response = new FakeResponse();
@@ -96,8 +97,7 @@ class BsaDownloadFunctionalTest {
gcsClient,
() -> new IdnChecker(fakeClock),
bsaEmailSender,
new BsaLock(
new FakeLockHandler(/* lockSucceeds= */ true), Duration.standardSeconds(30)),
new BsaLock(new FakeLockHandler(/* lockSucceeds= */ true), Duration.ofSeconds(30)),
fakeClock,
/* transactionBatchSize= */ 5,
response);
@@ -133,7 +133,7 @@ class BsaDownloadFunctionalTest {
mockBlockListFetcher(blockList, blockPlusList, blockList2, blockPlusList2);
action.run();
assertThat(getPersistedLabels()).containsExactly("abc", "def");
fakeClock.advanceBy(standardDays(1));
fakeClock.advanceBy(Duration.ofDays(1));
action.run();
assertThat(getPersistedLabels()).containsExactly("abc");
}
@@ -28,8 +28,8 @@ import google.registry.request.Response;
import google.registry.testing.FakeClock;
import google.registry.util.EmailMessage;
import jakarta.mail.internet.InternetAddress;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import java.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -40,7 +40,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class BsaRefreshActionTest {
FakeClock fakeClock = new FakeClock(DateTime.parse("2023-11-09T02:08:57.880Z"));
FakeClock fakeClock = new FakeClock(Instant.parse("2023-11-09T02:08:57.880Z"));
@Mock RefreshScheduler scheduler;
@@ -66,7 +66,7 @@ public class BsaRefreshActionTest {
gcsClient,
bsaReportSender,
/* transactionBatchSize= */ 5,
/* domainCreateTxnCommitTimeLag= */ Duration.millis(1),
/* domainCreateTxnCommitTimeLag= */ Duration.ofMillis(1),
new BsaEmailSender(gmailClient, emailRecipient),
bsaLock,
fakeClock,
@@ -28,7 +28,7 @@ import static google.registry.testing.DatabaseHelper.createTlds;
import static google.registry.testing.DatabaseHelper.deleteTestDomain;
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
@@ -55,9 +55,9 @@ import google.registry.testing.FakeClock;
import google.registry.testing.FakeLockHandler;
import google.registry.testing.FakeResponse;
import java.io.UncheckedIOException;
import java.time.Duration;
import java.time.Instant;
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.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -74,7 +74,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class BsaRefreshFunctionalTest {
static final DateTime TEST_START_TIME = DateTime.parse("2024-01-01T00:00:00Z");
static final Instant TEST_START_TIME = Instant.parse("2024-01-01T00:00:00Z");
static final String RESERVED_LIST_NAME = "reserved";
@@ -103,17 +103,16 @@ class BsaRefreshFunctionalTest {
gcsClient,
bsaReportSender,
/* transactionBatchSize= */ 5,
/* domainCreateTxnCommitTimeLag= */ Duration.millis(1),
/* domainCreateTxnCommitTimeLag= */ Duration.ofMillis(1),
emailSender,
new BsaLock(
new FakeLockHandler(/* lockSucceeds= */ true), Duration.standardSeconds(30)),
new BsaLock(new FakeLockHandler(/* lockSucceeds= */ true), Duration.ofSeconds(30)),
fakeClock,
response);
initDb();
}
private String getRefreshJobName(DateTime jobStartTime) {
private String getRefreshJobName(Instant jobStartTime) {
return jobStartTime.toString() + "-refresh";
}
@@ -123,7 +122,9 @@ class BsaRefreshFunctionalTest {
.forEach(
tld ->
persistResource(
tld.asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()));
tld.asBuilder()
.setBsaEnrollStartTimeInstant(Optional.of(START_INSTANT))
.build()));
createReservedList(RESERVED_LIST_NAME, "dummy", RESERVED_FOR_SPECIFIC_USE);
addReservedListsToTld("app", ImmutableList.of(RESERVED_LIST_NAME));
@@ -139,7 +140,7 @@ class BsaRefreshFunctionalTest {
void newReservedDomain_addedAsUnblockable() throws Exception {
addReservedDomainToList(
RESERVED_LIST_NAME, ImmutableMap.of("blocked1", RESERVED_FOR_SPECIFIC_USE));
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
action.run();
UnblockableDomain newUnblockable = new UnblockableDomain("blocked1.app", Reason.RESERVED);
assertThat(queryUnblockableDomains()).containsExactly(newUnblockable);
@@ -156,7 +157,7 @@ class BsaRefreshFunctionalTest {
void newRegisteredDomain_addedAsUnblockable() throws Exception {
persistActiveDomain("blocked1.dev", fakeClock.nowUtc());
persistActiveDomain("dummy.dev", fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
action.run();
UnblockableDomain newUnblockable = new UnblockableDomain("blocked1.dev", Reason.REGISTERED);
assertThat(queryUnblockableDomains()).containsExactly(newUnblockable);
@@ -178,7 +179,7 @@ class BsaRefreshFunctionalTest {
deleteTestDomain(domain, fakeClock.nowUtc());
fakeClock.advanceOneMilli();
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
Mockito.reset(bsaReportSender);
action.run();
assertThat(queryUnblockableDomains()).isEmpty();
@@ -201,7 +202,7 @@ class BsaRefreshFunctionalTest {
fakeClock.advanceOneMilli();
removeReservedDomainFromList(RESERVED_LIST_NAME, ImmutableSet.of("blocked1"));
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
Mockito.reset(bsaReportSender);
action.run();
assertThat(queryUnblockableDomains()).isEmpty();
@@ -226,7 +227,7 @@ class BsaRefreshFunctionalTest {
deleteTestDomain(domain, fakeClock.nowUtc());
fakeClock.advanceOneMilli();
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
Mockito.reset(bsaReportSender);
action.run();
assertThat(queryUnblockableDomains())
@@ -254,7 +255,7 @@ class BsaRefreshFunctionalTest {
fakeClock.advanceOneMilli();
Mockito.reset(bsaReportSender);
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
action.run();
UnblockableDomain changed = new UnblockableDomain("blocked1.app", Reason.REGISTERED);
assertThat(queryUnblockableDomains()).containsExactly(changed);
@@ -274,7 +275,7 @@ class BsaRefreshFunctionalTest {
addReservedDomainToList(
RESERVED_LIST_NAME, ImmutableMap.of("blocked1", RESERVED_FOR_SPECIFIC_USE));
persistActiveDomain("blocked1.app", fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
action.run();
UnblockableDomain newUnblockable = new UnblockableDomain("blocked1.app", Reason.REGISTERED);
assertThat(queryUnblockableDomains()).containsExactly(newUnblockable);
@@ -295,7 +296,7 @@ class BsaRefreshFunctionalTest {
fakeClock.advanceOneMilli();
Mockito.reset(bsaReportSender);
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
action.run();
assertThat(queryUnblockableDomains())
.containsExactly(new UnblockableDomain("blocked1.app", Reason.REGISTERED));
@@ -320,7 +321,7 @@ class BsaRefreshFunctionalTest {
fakeClock.advanceOneMilli();
Mockito.reset(bsaReportSender);
String jobName = getRefreshJobName(fakeClock.nowUtc());
String jobName = getRefreshJobName(fakeClock.now());
action.run();
assertThat(queryUnblockableDomains())
.containsExactly(new UnblockableDomain("blocked1.app", Reason.REGISTERED));
@@ -26,7 +26,6 @@ import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.time.Duration.millis;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.startsWith;
@@ -108,7 +107,7 @@ public class BsaValidateActionTest {
idnChecker,
new BsaEmailSender(gmailClient, emailRecipient),
/* transactionBatchSize= */ 500,
millis(MAX_STALENESS.toMillis()),
MAX_STALENESS,
fakeClock,
response);
createTld("app");
@@ -239,7 +238,7 @@ public class BsaValidateActionTest {
void isStalenessAllowed_newDomain_allowed() {
persistBsaLabel("label");
Domain domain = persistActiveDomain("label.app", fakeClock.nowUtc());
fakeClock.advanceBy(millis(MAX_STALENESS.minusSeconds(1).toMillis()));
fakeClock.advanceBy(MAX_STALENESS.minusSeconds(1));
assertThat(action.isStalenessAllowed(domain)).isTrue();
}
@@ -247,7 +246,7 @@ public class BsaValidateActionTest {
void isStalenessAllowed_newDomain_notAllowed() {
persistBsaLabel("label");
Domain domain = persistActiveDomain("label.app", fakeClock.nowUtc());
fakeClock.advanceBy(millis(MAX_STALENESS.toMillis()));
fakeClock.advanceBy(MAX_STALENESS);
assertThat(action.isStalenessAllowed(domain)).isFalse();
}
@@ -21,7 +21,7 @@ import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
import static google.registry.testing.DatabaseHelper.persistReservedList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.LogsSubject.assertAboutLogs;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static google.registry.util.NetworkUtils.pickUnusedPort;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
@@ -60,12 +60,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.time.Instant;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -81,7 +81,7 @@ public class UploadBsaUnavailableDomainsActionTest {
private static final String API_URL = "https://upload.test/bsa";
private final FakeClock clock = new FakeClock(DateTime.parse("2024-02-02T02:02:02Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2024-02-02T02:02:02Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@@ -112,7 +112,7 @@ public class UploadBsaUnavailableDomainsActionTest {
Tld.get("tld")
.asBuilder()
.setReservedLists(reservedList)
.setBsaEnrollStartTime(Optional.of(START_OF_TIME))
.setBsaEnrollStartTimeInstant(Optional.of(START_INSTANT))
.setTldType(TldType.REAL)
.build());
action =
@@ -36,8 +36,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.time.Duration;
import javax.net.ssl.HttpsURLConnection;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -48,7 +48,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class BsaCredentialTest {
private static final Duration AUTH_TOKEN_EXPIRY = Duration.standardMinutes(30);
private static final Duration AUTH_TOKEN_EXPIRY = Duration.ofMinutes(30);
@Mock OutputStream connectionOutputStream;
@Mock HttpsURLConnection connection;
@@ -82,7 +82,7 @@ class BsaCredentialTest {
credential = spy(credential);
doReturn("a", "b", "c").when(credential).fetchNewAuthToken();
assertThat(credential.getAuthToken()).isEqualTo("a");
clock.advanceBy(AUTH_TOKEN_EXPIRY.minus(Duration.millis(1)));
clock.advanceBy(AUTH_TOKEN_EXPIRY.minus(Duration.ofMillis(1)));
assertThat(credential.getAuthToken()).isEqualTo("a");
verify(credential, times(1)).fetchNewAuthToken();
}
@@ -17,19 +17,18 @@ package google.registry.bsa.persistence;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.bsa.RefreshStage.CHECK_FOR_CHANGES;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.joda.time.DateTimeZone.UTC;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit test for {@link BsaDomainRefresh}. */
public class BsaDomainRefreshTest {
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
protected FakeClock fakeClock = new FakeClock(Instant.parse("2024-01-01T00:00:00Z"));
@RegisterExtension
final JpaIntegrationWithCoverageExtension jpa =
@@ -19,21 +19,20 @@ import static google.registry.bsa.BlockListType.BLOCK;
import static google.registry.bsa.BlockListType.BLOCK_PLUS;
import static google.registry.bsa.DownloadStage.DOWNLOAD_BLOCK_LISTS;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableMap;
import google.registry.bsa.BlockListType;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit test for {@link BsaDownload}. */
public class BsaDownloadTest {
FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
FakeClock fakeClock = new FakeClock(Instant.parse("2024-01-01T00:00:00Z"));
@RegisterExtension
final JpaIntegrationWithCoverageExtension jpa =
@@ -21,9 +21,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import static google.registry.persistence.transaction.TransactionManagerFactory.setJpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.setReplicaJpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.millis;
import static org.joda.time.Duration.standardMinutes;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -35,14 +32,15 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
import google.registry.persistence.transaction.JpaTransactionManager;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import java.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link BsaLabelUtils}. */
public class BsaLabelUtilsTest {
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
protected FakeClock fakeClock = new FakeClock(Instant.parse("2024-01-01T00:00:00Z"));
@RegisterExtension
final JpaIntegrationWithCoverageExtension jpa =
@@ -90,7 +88,7 @@ public class BsaLabelUtilsTest {
assertThat(isLabelBlocked("abc")).isTrue();
// If test fails, check and fix cache expiry in the config file. Do not increase the duration
// on the line below without proper discussion.
fakeClock.advanceBy(standardMinutes(1).plus(millis(1)));
fakeClock.advanceBy(Duration.ofMinutes(1).plus(Duration.ofMillis(1)));
assertThat(isLabelBlocked("abc")).isTrue();
verify(replicaTm, times(2)).loadByKey(any());
} catch (Throwable e) {
@@ -21,14 +21,14 @@ import com.google.common.collect.ImmutableList;
import google.registry.bsa.DownloadStage;
import google.registry.bsa.api.UnblockableDomain;
import google.registry.util.Clock;
import java.time.Duration;
import java.time.Instant;
import org.joda.time.Duration;
/** Exposes BSA persistence entities and tools to test classes. */
public final class BsaTestingUtils {
public static final Duration DEFAULT_DOWNLOAD_INTERVAL = Duration.standardHours(1);
public static final Duration DEFAULT_NOP_INTERVAL = Duration.standardDays(1);
public static final Duration DEFAULT_DOWNLOAD_INTERVAL = Duration.ofHours(1);
public static final Duration DEFAULT_NOP_INTERVAL = Duration.ofDays(1);
/** An arbitrary point of time used as BsaLabels' creation time. */
public static final Instant BSA_LABEL_CREATION_TIME = Instant.parse("2023-12-31T00:00:00Z");
@@ -16,7 +16,6 @@ package google.registry.bsa.persistence;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.bsa.api.UnblockableDomain;
@@ -25,14 +24,14 @@ import google.registry.persistence.transaction.DatabaseException;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link BsaUnblockableDomain}. */
public class BsaUnblockableDomainTest {
FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
FakeClock fakeClock = new FakeClock(Instant.parse("2024-01-01T00:00:00Z"));
@RegisterExtension
final JpaIntegrationWithCoverageExtension jpa =
@@ -22,7 +22,6 @@ import static google.registry.bsa.DownloadStage.MAKE_ORDER_AND_LABEL_DIFF;
import static google.registry.bsa.DownloadStage.NOP;
import static google.registry.bsa.persistence.DownloadScheduler.fetchTwoMostRecentDownloads;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static org.joda.time.Duration.standardSeconds;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -33,9 +32,9 @@ import google.registry.bsa.persistence.DownloadSchedule.CompletedJob;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import org.joda.time.Duration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -44,8 +43,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DownloadScheduler} */
class DownloadSchedulerTest {
static final Duration DOWNLOAD_INTERVAL = Duration.standardMinutes(30);
static final Duration MAX_NOP_INTERVAL = Duration.standardDays(1);
static final Duration DOWNLOAD_INTERVAL = Duration.ofMinutes(30);
static final Duration MAX_NOP_INTERVAL = Duration.ofDays(1);
FakeClock fakeClock = new FakeClock(Instant.parse("2023-11-09T02:08:57.880Z"));
@@ -151,14 +150,14 @@ class DownloadSchedulerTest {
@Test
void doneJob_cronEarlyWithJitter_newSchedule() {
insertOneJobAndAdvanceClock(DONE);
fakeClock.advanceBy(DOWNLOAD_INTERVAL.minus(standardSeconds(5)));
fakeClock.advanceBy(DOWNLOAD_INTERVAL.minus(Duration.ofSeconds(5)));
assertThat(scheduler.schedule()).isPresent();
}
@Test
void doneJob_cronEarlyMoreThanJitter_newSchedule() {
insertOneJobAndAdvanceClock(DONE);
fakeClock.advanceBy(DOWNLOAD_INTERVAL.minus(standardSeconds(6)));
fakeClock.advanceBy(DOWNLOAD_INTERVAL.minus(Duration.ofSeconds(6)));
assertThat(scheduler.schedule()).isEmpty();
}
@@ -22,7 +22,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.tldconfig.idn.IdnTableEnum.UNCONFUSABLE_LATIN;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@@ -39,8 +39,8 @@ import google.registry.model.tld.label.ReservationType;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
import google.registry.testing.FakeClock;
import java.time.Instant;
import java.util.Optional;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -52,7 +52,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class LabelDiffUpdatesTest {
FakeClock fakeClock = new FakeClock(DateTime.parse("2023-11-09T02:08:57.880Z"));
FakeClock fakeClock = new FakeClock(Instant.parse("2023-11-09T02:08:57.880Z"));
@RegisterExtension
final JpaIntegrationWithCoverageExtension jpa =
@@ -74,7 +74,7 @@ class LabelDiffUpdatesTest {
() ->
tm().put(
tld.asBuilder()
.setBsaEnrollStartTime(Optional.of(START_OF_TIME))
.setBsaEnrollStartTimeInstant(Optional.of(START_INSTANT))
.setIdnTables(ImmutableSet.of(UNCONFUSABLE_LATIN))
.build()));
app = tm().transact(() -> tm().loadByEntity(tld));
@@ -96,7 +96,7 @@ class LabelDiffUpdatesTest {
ImmutableList.of(BlockLabel.create("label", LabelType.DELETE, ImmutableSet.of())),
idnChecker,
schedule,
fakeClock.nowUtc());
fakeClock.now());
assertThat(unblockableDomains).isEmpty();
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(BsaLabel.vKey("label")))).isEmpty();
assertThat(
@@ -121,7 +121,7 @@ class LabelDiffUpdatesTest {
BlockLabel.create("label", LabelType.NEW_ORDER_ASSOCIATION, ImmutableSet.of())),
idnChecker,
schedule,
fakeClock.nowUtc());
fakeClock.now());
assertThat(unblockableDomains)
.containsExactly(
new UnblockableDomain("label.app", UnblockableDomain.Reason.REGISTERED),
@@ -148,7 +148,7 @@ class LabelDiffUpdatesTest {
ImmutableList.of(BlockLabel.create("label", LabelType.CREATE, ImmutableSet.of())),
idnChecker,
schedule,
fakeClock.nowUtc());
fakeClock.now());
assertThat(unblockableDomains)
.containsExactly(
new UnblockableDomain("label.app", UnblockableDomain.Reason.REGISTERED),
@@ -36,7 +36,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -47,7 +47,7 @@ public final class DnsInjectionTest {
private final HttpServletRequest req = mock(HttpServletRequest.class);
private final HttpServletResponse rsp = mock(HttpServletResponse.class);
private final StringWriter httpOutput = new StringWriter();
private final FakeClock clock = new FakeClock(DateTime.parse("2014-01-01TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("2014-01-01T00:00:00Z"));
private DnsTestComponent component;
@RegisterExtension
@@ -23,7 +23,8 @@ import static google.registry.dns.DnsUtils.requestHostDnsRefresh;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadAllOf;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static google.registry.util.DateTimeUtils.minusMinutes;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -32,9 +33,9 @@ import google.registry.model.common.DnsRefreshRequest;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import java.util.Comparator;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -47,7 +48,7 @@ public class DnsUtilsTest {
private static final String domainName = "test.tld";
private static final String hostName = "ns1.test.tld";
private final FakeClock clock = new FakeClock(DateTime.parse("2020-02-02T01:23:45Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2020-02-02T01:23:45Z"));
@RegisterExtension
JpaIntegrationTestExtension jpa =
@@ -80,7 +81,7 @@ public class DnsUtilsTest {
void testSuccess_hostRefresh() {
tm().transact(() -> requestHostDnsRefresh(hostName));
DnsRefreshRequest request = Iterables.getOnlyElement(loadAllOf(DnsRefreshRequest.class));
assertRequest(request, TargetType.HOST, hostName, tld, clock.nowUtc());
assertRequest(request, TargetType.HOST, hostName, tld, clock.now());
}
@Test
@@ -89,57 +90,58 @@ public class DnsUtilsTest {
() -> requestDomainDnsRefresh(ImmutableList.of(domainName, "test2.tld", "test3.tld")));
ImmutableList<DnsRefreshRequest> requests = loadAllOf(DnsRefreshRequest.class);
assertThat(requests.size()).isEqualTo(3);
assertRequest(requests.get(0), TargetType.DOMAIN, domainName, tld, clock.nowUtc());
assertRequest(requests.get(1), TargetType.DOMAIN, "test2.tld", tld, clock.nowUtc());
assertRequest(requests.get(2), TargetType.DOMAIN, "test3.tld", tld, clock.nowUtc());
assertRequest(requests.get(0), TargetType.DOMAIN, domainName, tld, clock.now());
assertRequest(requests.get(1), TargetType.DOMAIN, "test2.tld", tld, clock.now());
assertRequest(requests.get(2), TargetType.DOMAIN, "test3.tld", tld, clock.now());
}
@Test
void testSuccess_domainRefreshMultipleDomains() {
tm().transact(() -> requestDomainDnsRefresh(domainName));
DnsRefreshRequest request = Iterables.getOnlyElement(loadAllOf(DnsRefreshRequest.class));
assertRequest(request, TargetType.DOMAIN, domainName, tld, clock.nowUtc());
assertRequest(request, TargetType.DOMAIN, domainName, tld, clock.now());
}
@Test
void testSuccess_domainRefreshWithDelay() {
tm().transact(() -> requestDomainDnsRefresh(domainName, Duration.standardMinutes(3)));
tm().transact(() -> requestDomainDnsRefresh(domainName, Duration.ofMinutes(3)));
DnsRefreshRequest request = Iterables.getOnlyElement(loadAllOf(DnsRefreshRequest.class));
assertRequest(request, TargetType.DOMAIN, domainName, tld, clock.nowUtc().plusMinutes(3));
assertRequest(
request, TargetType.DOMAIN, domainName, tld, clock.now().plus(Duration.ofMinutes(3)));
}
@Test
void testSuccess_ProcessRequests() {
ImmutableList<DnsRefreshRequest> requests = processRequests();
DateTime processtime = clock.nowUtc();
Instant processtime = clock.now();
assertThat(requests.size()).isEqualTo(4);
assertRequest(
requests.get(0),
TargetType.DOMAIN,
"test2.tld",
"tld",
clock.nowUtc().minusMinutes(4),
minusMinutes(clock.now(), 4),
processtime);
assertRequest(
requests.get(1),
TargetType.DOMAIN,
"test1.tld",
"tld",
clock.nowUtc().minusMinutes(3),
minusMinutes(clock.now(), 3),
processtime);
assertRequest(
requests.get(2),
TargetType.HOST,
"ns1.test2.tld",
"tld",
clock.nowUtc().minusMinutes(1),
minusMinutes(clock.now(), 1),
processtime);
assertRequest(
requests.get(3),
TargetType.DOMAIN,
"test5.tld",
"tld",
clock.nowUtc().minusMinutes(1),
minusMinutes(clock.now(), 1),
processtime);
requests = loadAllOf(DnsRefreshRequest.class);
assertThat(requests.size()).isEqualTo(7);
@@ -149,15 +151,15 @@ public class DnsUtilsTest {
clock.advanceOneMilli();
// Requests within cooldown period not included.
requests = readAndUpdateRequestsWithLatestProcessTime("tld", Duration.standardMinutes(1), 4);
requests = readAndUpdateRequestsWithLatestProcessTime("tld", Duration.ofMinutes(1), 4);
assertThat(requests.size()).isEqualTo(1);
assertRequest(
requests.get(0),
TargetType.DOMAIN,
"test6.tld",
"tld",
clock.nowUtc().minusMinutes(1).minusMillis(1),
clock.nowUtc());
minusMinutes(clock.now(), 1).minusMillis(1),
clock.now());
}
@Test
@@ -173,19 +175,19 @@ public class DnsUtilsTest {
TargetType.DOMAIN,
"something.example",
"example",
clock.nowUtc().minusMinutes(2));
minusMinutes(clock.now(), 2));
assertRequest(
remainingRequests.get(1),
TargetType.DOMAIN,
"test6.tld",
"tld",
clock.nowUtc().minusMinutes(1));
minusMinutes(clock.now(), 1));
assertRequest(
remainingRequests.get(2),
TargetType.DOMAIN,
"test4.tld",
"tld",
clock.nowUtc().plusMinutes(1));
clock.now().plus(Duration.ofMinutes(1)));
tm().transact(() -> tm().delete(remainingRequests.get(2)));
assertThat(loadAllOf(DnsRefreshRequest.class).size()).isEqualTo(2);
// Should not throw even though one of the request is already deleted.
@@ -196,28 +198,28 @@ public class DnsUtilsTest {
private ImmutableList<DnsRefreshRequest> processRequests() {
createTld("example");
// Domain Included.
tm().transact(() -> requestDomainDnsRefresh("test1.tld", Duration.standardMinutes(1)));
tm().transact(() -> requestDomainDnsRefresh("test1.tld", Duration.ofMinutes(1)));
// This one should be returned before test1.tld, even though it's added later, because of
// the delay specified in test1.tld.
tm().transact(() -> requestDomainDnsRefresh("test2.tld"));
// Not included because the TLD is not under management.
tm().transact(() -> requestDomainDnsRefresh("something.example", Duration.standardMinutes(2)));
clock.advanceBy(Duration.standardMinutes(3));
tm().transact(() -> requestDomainDnsRefresh("something.example", Duration.ofMinutes(2)));
clock.advanceBy(Duration.ofMinutes(3));
// Host included.
tm().transact(() -> requestHostDnsRefresh("ns1.test2.tld"));
// Not included because the request time is in the future
tm().transact(() -> requestDomainDnsRefresh("test4.tld", Duration.standardMinutes(2)));
tm().transact(() -> requestDomainDnsRefresh("test4.tld", Duration.ofMinutes(2)));
// Included after the previous one. Same request time, order by insertion order (i.e. ID);
tm().transact(() -> requestDomainDnsRefresh("test5.tld"));
// Not included because batch size is exceeded;
tm().transact(() -> requestDomainDnsRefresh("test6.tld"));
clock.advanceBy(Duration.standardMinutes(1));
return readAndUpdateRequestsWithLatestProcessTime("tld", Duration.standardMinutes(1), 4);
clock.advanceBy(Duration.ofMinutes(1));
return readAndUpdateRequestsWithLatestProcessTime("tld", Duration.ofMinutes(1), 4);
}
private static void assertRequest(
DnsRefreshRequest request, TargetType type, String name, String tld, DateTime requestTime) {
assertRequest(request, type, name, tld, requestTime, START_OF_TIME);
DnsRefreshRequest request, TargetType type, String name, String tld, Instant requestTime) {
assertRequest(request, type, name, tld, requestTime, START_INSTANT);
}
private static void assertRequest(
@@ -225,8 +227,8 @@ public class DnsUtilsTest {
TargetType type,
String name,
String tld,
DateTime requestTime,
DateTime processTime) {
Instant requestTime,
Instant processTime) {
assertThat(request.getType()).isEqualTo(type);
assertThat(request.getName()).isEqualTo(name);
assertThat(request.getTld()).isEqualTo(tld);
@@ -65,9 +65,9 @@ import google.registry.testing.FakeResponse;
import google.registry.testing.Lazies;
import google.registry.util.EmailMessage;
import jakarta.mail.internet.InternetAddress;
import java.time.Duration;
import java.time.Instant;
import java.util.Set;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -80,7 +80,7 @@ public class PublishDnsUpdatesActionTest {
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
private final FakeClock clock = new FakeClock(DateTime.parse("1971-01-01TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("1971-01-01T00:00:00Z"));
private final FakeResponse response = new FakeResponse();
private final FakeLockHandler lockHandler = new FakeLockHandler(true);
private final DnsWriter dnsWriter = mock(DnsWriter.class);
@@ -144,14 +144,14 @@ public class PublishDnsUpdatesActionTest {
return new PublishDnsUpdatesAction(
dnsWriterString,
clock.nowUtc().minusHours(1),
clock.nowUtc().minusHours(2),
clock.now().minus(Duration.ofHours(1)),
clock.now().minus(Duration.ofHours(2)),
lockIndex,
numPublishLocks,
domains,
hosts,
tld,
Duration.standardSeconds(10),
Duration.ofSeconds(10),
"Subj",
"Body %1$s %2$s %3$s %4$s %5$s",
"awesomeRegistry",
@@ -188,8 +188,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.SUCCESS,
1,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertNoDnsRequests();
assertThat(response.getStatus()).isEqualTo(SC_OK);
@@ -215,8 +215,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.SUCCESS,
1,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertNoDnsRequests();
assertThat(response.getStatus()).isEqualTo(SC_OK);
@@ -239,8 +239,7 @@ public class PublishDnsUpdatesActionTest {
action.run();
verify(mockLockHandler)
.executeWithLocks(
action, "xn--q9jyb4c", Duration.standardSeconds(10), "DNS updates-lock 2 of 4");
.executeWithLocks(action, "xn--q9jyb4c", Duration.ofSeconds(10), "DNS updates-lock 2 of 4");
}
@Test
@@ -268,8 +267,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.COMMIT_FAILURE,
5,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertNoDnsRequests();
}
@@ -294,8 +293,8 @@ public class PublishDnsUpdatesActionTest {
.param(PARAM_DNS_WRITER, "correctWriter")
.param(PARAM_LOCK_INDEX, "1")
.param(PARAM_NUM_PUBLISH_LOCKS, "1")
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.nowUtc().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.nowUtc().minusHours(2).toString())
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.now().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.now().minus(Duration.ofHours(2)).toString())
.param(PARAM_DOMAINS, "example1.xn--q9jyb4c,example2.xn--q9jyb4c")
.param(PARAM_HOSTS, "")
.header("content-type", "application/x-www-form-urlencoded"),
@@ -305,8 +304,8 @@ public class PublishDnsUpdatesActionTest {
.param(PARAM_DNS_WRITER, "correctWriter")
.param(PARAM_LOCK_INDEX, "1")
.param(PARAM_NUM_PUBLISH_LOCKS, "1")
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.nowUtc().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.nowUtc().minusHours(2).toString())
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.now().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.now().minus(Duration.ofHours(2)).toString())
.param(PARAM_DOMAINS, "example3.xn--q9jyb4c,example4.xn--q9jyb4c")
.param(PARAM_HOSTS, "ns1.example.xn--q9jyb4c")
.header("content-type", "application/x-www-form-urlencoded"));
@@ -333,8 +332,8 @@ public class PublishDnsUpdatesActionTest {
.param(PARAM_DNS_WRITER, "correctWriter")
.param(PARAM_LOCK_INDEX, "1")
.param(PARAM_NUM_PUBLISH_LOCKS, "1")
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.nowUtc().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.nowUtc().minusHours(2).toString())
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.now().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.now().minus(Duration.ofHours(2)).toString())
.param(PARAM_DOMAINS, "example1.xn--q9jyb4c,example2.xn--q9jyb4c")
.param(PARAM_HOSTS, "")
.header("content-type", "application/x-www-form-urlencoded"),
@@ -344,8 +343,8 @@ public class PublishDnsUpdatesActionTest {
.param(PARAM_DNS_WRITER, "correctWriter")
.param(PARAM_LOCK_INDEX, "1")
.param(PARAM_NUM_PUBLISH_LOCKS, "1")
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.nowUtc().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.nowUtc().minusHours(2).toString())
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.now().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.now().minus(Duration.ofHours(2)).toString())
.param(PARAM_DOMAINS, "example3.xn--q9jyb4c,example4.xn--q9jyb4c,example5.xn--q9jyb4c")
.param(PARAM_HOSTS, "ns1.example.xn--q9jyb4c")
.header("content-type", "application/x-www-form-urlencoded"));
@@ -370,8 +369,8 @@ public class PublishDnsUpdatesActionTest {
.param(PARAM_DNS_WRITER, "correctWriter")
.param(PARAM_LOCK_INDEX, "1")
.param(PARAM_NUM_PUBLISH_LOCKS, "1")
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.nowUtc().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.nowUtc().minusHours(2).toString())
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.now().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.now().minus(Duration.ofHours(2)).toString())
.param(PARAM_DOMAINS, "example1.xn--q9jyb4c")
.param(PARAM_HOSTS, "")
.header("content-type", "application/x-www-form-urlencoded"),
@@ -381,8 +380,8 @@ public class PublishDnsUpdatesActionTest {
.param(PARAM_DNS_WRITER, "correctWriter")
.param(PARAM_LOCK_INDEX, "1")
.param(PARAM_NUM_PUBLISH_LOCKS, "1")
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.nowUtc().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.nowUtc().minusHours(2).toString())
.param(PARAM_PUBLISH_TASK_ENQUEUED, clock.now().toString())
.param(PARAM_REFRESH_REQUEST_TIME, clock.now().minus(Duration.ofHours(2)).toString())
.param(PARAM_DOMAINS, "")
.param(PARAM_HOSTS, "ns1.example.xn--q9jyb4c")
.header("content-type", "application/x-www-form-urlencoded"));
@@ -474,8 +473,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.SUCCESS,
5,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertNoDnsRequests();
}
@@ -504,8 +503,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.SUCCESS,
5,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertNoDnsRequests();
}
@@ -532,8 +531,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.LOCK_FAILURE,
5,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertNoDnsRequests();
}
@@ -558,8 +557,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.BAD_LOCK_INDEX,
2,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertDomainDnsRequests("example.com");
assertHostDnsRequests("ns1.example.com");
@@ -586,8 +585,8 @@ public class PublishDnsUpdatesActionTest {
"correctWriter",
ActionStatus.BAD_LOCK_INDEX,
2,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertDomainDnsRequests("example.com");
assertHostDnsRequests("ns1.example.com");
@@ -610,8 +609,8 @@ public class PublishDnsUpdatesActionTest {
"wrongWriter",
ActionStatus.BAD_WRITER,
5,
Duration.standardHours(2),
Duration.standardHours(1));
Duration.ofHours(2),
Duration.ofHours(1));
verifyNoMoreInteractions(dnsMetrics);
assertDomainDnsRequests("example.com");
assertDomainDnsRequests("example2.com");
@@ -19,7 +19,7 @@ import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadAllOf;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.DatabaseHelper.persistResources;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyCollection;
@@ -43,11 +43,10 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
import java.util.Optional;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -56,7 +55,7 @@ import org.mockito.ArgumentCaptor;
/** Unit tests for {@link DnsRefreshRequestTest}. */
public class ReadDnsRefreshRequestsActionTest {
private final FakeClock clock = new FakeClock(DateTime.parse("2020-02-02T01:23:45Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2020-02-02T01:23:45Z"));
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper(clock);
private final Optional<Integer> jitterSeconds = Optional.of(5);
@@ -68,7 +67,7 @@ public class ReadDnsRefreshRequestsActionTest {
spy(
new ReadDnsRefreshRequestsAction(
2,
Duration.standardSeconds(10),
Duration.ofSeconds(10),
jitterSeconds,
"tld",
clock,
@@ -87,15 +86,21 @@ public class ReadDnsRefreshRequestsActionTest {
.build());
requests =
new ImmutableList.Builder<DnsRefreshRequest>()
.add(new DnsRefreshRequest(TargetType.DOMAIN, "domain.tld", "tld", clock.nowUtc()))
.add(new DnsRefreshRequest(TargetType.DOMAIN, "domain.tld", "tld", clock.now()))
.add(
new DnsRefreshRequest(
TargetType.HOST, "ns1.domain.tld", "tld", clock.nowUtc().minusMinutes(1)))
TargetType.HOST,
"ns1.domain.tld",
"tld",
clock.now().minus(Duration.ofMinutes(1))))
.add(
new DnsRefreshRequest(
TargetType.DOMAIN, "future.tld", "tld", clock.nowUtc().plusMinutes(1)))
TargetType.DOMAIN,
"future.tld",
"tld",
clock.now().plus(Duration.ofMinutes(1))))
.build();
clock.advanceBy(Duration.standardMinutes(5));
clock.advanceBy(Duration.ofMinutes(5));
persistResources(requests);
requests = loadAllOf(DnsRefreshRequest.class);
}
@@ -110,7 +115,7 @@ public class ReadDnsRefreshRequestsActionTest {
@Test
void testSuccess_runAction_requestTimeInTheFuture() {
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.run();
verify(action, never()).enqueueUpdates(anyInt(), anyInt(), anyCollection());
verify(action, never()).processRequests(anyCollection());
@@ -176,7 +181,7 @@ public class ReadDnsRefreshRequestsActionTest {
(ImmutableList<DnsRefreshRequest>) invocation.callRealMethod();
// After this function is called once, the loop in run() should top when it checks
// if the current time is before the request end time.
clock.advanceBy(Duration.standardHours(1));
clock.advanceBy(Duration.ofHours(1));
return ans;
})
.when(action)
@@ -187,7 +192,7 @@ public class ReadDnsRefreshRequestsActionTest {
// The third request is left untouched because it is not read;
ImmutableList<DnsRefreshRequest> remainingRequests = loadAllOf(DnsRefreshRequest.class);
assertThat(remainingRequests.size()).isEqualTo(1);
assertThat(remainingRequests.get(0).getLastProcessTime()).isEqualTo(START_OF_TIME);
assertThat(remainingRequests.get(0).getLastProcessTime()).isEqualTo(START_INSTANT);
}
@Test
@@ -231,8 +236,8 @@ public class ReadDnsRefreshRequestsActionTest {
.param("dnsWriter", "FooWriter")
.param("lockIndex", "2")
.param("numPublishLocks", "3")
.param("enqueued", clock.nowUtc().toString())
.param("requestTime", clock.nowUtc().minusMinutes(6).toString())
.param("enqueued", clock.now().toString())
.param("requestTime", clock.now().minus(Duration.ofMinutes(6)).toString())
.param("domains", "domain.tld,future.tld")
.param("hosts", "ns1.domain.tld"),
new TaskMatcher()
@@ -242,18 +247,17 @@ public class ReadDnsRefreshRequestsActionTest {
.param("dnsWriter", "BarWriter")
.param("lockIndex", "2")
.param("numPublishLocks", "3")
.param("enqueued", clock.nowUtc().toString())
.param("requestTime", clock.nowUtc().minusMinutes(6).toString())
.param("enqueued", clock.now().toString())
.param("requestTime", clock.now().minus(Duration.ofMinutes(6)).toString())
.param("domains", "domain.tld,future.tld")
.param("hosts", "ns1.domain.tld"));
cloudTasksHelper
.getTestTasksFor("dns-publish")
.forEach(
task -> {
DateTime scheduledTime =
new DateTime(task.getScheduleTime().getSeconds() * 1000, DateTimeZone.UTC);
assertThat(new Duration(clock.nowUtc(), scheduledTime))
.isAtMost(Duration.standardSeconds(jitterSeconds.get()));
Instant scheduledTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds());
assertThat(Duration.between(clock.now(), scheduledTime))
.isAtMost(Duration.ofSeconds(jitterSeconds.get()));
});
}
}
@@ -33,7 +33,7 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -41,7 +41,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link RefreshDnsOnHostRenameAction}. */
public class RefreshDnsOnHostRenameActionTest {
private final FakeClock clock = new FakeClock(DateTime.parse("2015-01-15T11:22:33Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2015-01-15T11:22:33Z"));
private final FakeResponse response = new FakeResponse();
@RegisterExtension
@@ -54,7 +54,6 @@ import java.io.IOException;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -120,18 +119,18 @@ public class CloudDnsWriterTest {
persistResource(
Tld.get("tld")
.asBuilder()
.setDnsAPlusAaaaTtl(Duration.standardSeconds(11))
.setDnsNsTtl(Duration.standardSeconds(222))
.setDnsDsTtl(Duration.standardSeconds(3333))
.setDnsAPlusAaaaTtl(org.joda.time.Duration.standardSeconds(11))
.setDnsNsTtl(org.joda.time.Duration.standardSeconds(222))
.setDnsDsTtl(org.joda.time.Duration.standardSeconds(3333))
.build());
writer =
new CloudDnsWriter(
dnsConnection,
"projectId",
"triple.secret.tld", // used by testInvalidZoneNames()
Duration.ZERO,
Duration.ZERO,
Duration.ZERO,
java.time.Duration.ZERO,
java.time.Duration.ZERO,
java.time.Duration.ZERO,
RateLimiter.create(20),
10, // max num threads
new SystemClock(),
@@ -402,9 +401,9 @@ public class CloudDnsWriterTest {
dnsConnection,
"projectId",
"triple.secret.tld",
Duration.standardSeconds(11),
Duration.standardSeconds(222),
Duration.standardSeconds(3333),
java.time.Duration.ofSeconds(11),
java.time.Duration.ofSeconds(222),
java.time.Duration.ofSeconds(3333),
RateLimiter.create(20),
10,
new SystemClock(),
@@ -30,9 +30,9 @@ import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Arrays;
import javax.net.SocketFactory;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -121,11 +121,11 @@ class DnsMessageTransportTest {
when(mockSocket.getInputStream()).thenReturn(mockInputStream);
when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream());
Duration testTimeout = Duration.standardSeconds(1);
Duration testTimeout = Duration.ofSeconds(1);
DnsMessageTransport resolver = new DnsMessageTransport(mockFactory, UPDATE_HOST, testTimeout);
Message expectedQuery = new Message();
assertThrows(SocketTimeoutException.class, () -> resolver.send(expectedQuery));
verify(mockSocket).setSoTimeout((int) testTimeout.getMillis());
verify(mockSocket).setSoTimeout((int) testTimeout.toMillis());
}
@Test
@@ -44,10 +44,10 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -83,7 +83,7 @@ public class DnsUpdateWriterTest {
@Mock private DnsMessageTransport mockResolver;
@Captor private ArgumentCaptor<Update> updateCaptor;
private final FakeClock clock = new FakeClock(DateTime.parse("1971-01-01TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("1971-01-01T00:00:00Z"));
private DnsUpdateWriter writer;
@@ -92,8 +92,14 @@ public class DnsUpdateWriterTest {
createTld("tld");
when(mockResolver.send(any(Update.class))).thenReturn(messageWithResponseCode(Rcode.NOERROR));
writer = new DnsUpdateWriter(
"tld", Duration.ZERO, Duration.ZERO, Duration.ZERO, mockResolver, clock);
writer =
new DnsUpdateWriter(
"tld",
java.time.Duration.ZERO,
java.time.Duration.ZERO,
java.time.Duration.ZERO,
mockResolver,
clock);
}
@Test
@@ -22,7 +22,6 @@ import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.plusDays;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -49,6 +48,8 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.storage.drive.DriveConnection;
import google.registry.testing.FakeClock;
import google.registry.util.DateTimeUtils;
import java.time.Instant;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -62,7 +63,7 @@ class ExportDomainListsActionTest {
private final DriveConnection driveConnection = mock(DriveConnection.class);
private final ArgumentCaptor<byte[]> bytesExportedToDrive = ArgumentCaptor.forClass(byte[].class);
private ExportDomainListsAction action;
private final FakeClock clock = new FakeClock(DateTime.parse("2020-02-02T02:02:02Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2020-02-02T02:02:02Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@@ -192,7 +193,7 @@ class ExportDomainListsActionTest {
verifyExportedToDrive(
"brouhaha",
"registered_domains_tld.txt",
"active.tld,\npendingdelete.tld,2020-02-05T02:02:02.000Z\nredemption.tld,");
"active.tld,\npendingdelete.tld,2020-02-05T02:02:02Z\nredemption.tld,");
}
@Test
@@ -261,7 +262,7 @@ class ExportDomainListsActionTest {
new FeatureFlag()
.asBuilder()
.setFeatureName(INCLUDE_PENDING_DELETE_DATE_FOR_DOMAINS)
.setStatusMap(ImmutableSortedMap.of(START_OF_TIME, status))
.setStatusMap(ImmutableSortedMap.of(DateTimeUtils.START_OF_TIME, status))
.build());
}
}
@@ -25,9 +25,9 @@ import static org.mockito.Mockito.when;
import google.registry.testing.FakeLockHandler;
import google.registry.testing.FakeResponse;
import java.time.Duration;
import java.util.Optional;
import javax.annotation.Nullable;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -50,7 +50,7 @@ public class SyncRegistrarsSheetActionTest {
action = new SyncRegistrarsSheetAction();
action.response = response;
action.syncRegistrarsSheet = syncRegistrarsSheet;
action.timeout = Duration.standardHours(1);
action.timeout = Duration.ofHours(1);
action.lockHandler = new FakeLockHandler(true);
}
@@ -28,7 +28,6 @@ import static google.registry.util.DateTimeUtils.minusHours;
import static google.registry.util.DateTimeUtils.plusHours;
import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardMinutes;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
@@ -45,7 +44,6 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import java.time.Instant;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -59,15 +57,15 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class SyncRegistrarsSheetTest {
private final FakeClock clock = new FakeClock(Instant.parse("2024-01-01T00:00:00Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension();
@Captor private ArgumentCaptor<ImmutableList<ImmutableMap<String, String>>> rowsCaptor;
@Mock private SheetSynchronizer sheetSynchronizer;
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
private SyncRegistrarsSheet newSyncRegistrarsSheet() {
SyncRegistrarsSheet result = new SyncRegistrarsSheet();
result.clock = clock;
@@ -318,7 +316,7 @@ public class SyncRegistrarsSheetTest {
Cursor cursor = loadByKey(Cursor.createGlobalVKey(SYNC_REGISTRAR_SHEET));
assertThat(cursor).isNotNull();
assertThat(cursor.getCursorTimeInstant()).isGreaterThan(registrarCreationTime);
assertThat(cursor.getCursorTime()).isGreaterThan(registrarCreationTime);
}
@Test
@@ -67,7 +67,7 @@ public class CreateAutoTimestampTest {
@Test
void testResavingRespectsOriginalTime() {
final Instant oldCreateTime = minusDays(clock.now(), 1);
Instant oldCreateTime = minusDays(clock.now(), 1);
tm().transact(
() -> {
CreateAutoTimestampTestObject object = new CreateAutoTimestampTestObject();
@@ -13,7 +13,6 @@
// limitations under the License.
package google.registry.model;
import static org.joda.time.DateTimeZone.UTC;
import google.registry.persistence.transaction.JpaEntityCoverageExtension;
@@ -20,14 +20,13 @@ import static google.registry.model.common.Cursor.CursorType.RDE_UPLOAD;
import static google.registry.model.common.Cursor.CursorType.RECURRING_BILLING;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.EntityTestCase;
import google.registry.model.tld.Tld;
import google.registry.util.SerializeUtils;
import java.time.Instant;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -40,12 +39,13 @@ public class CursorTest extends EntityTestCase {
@BeforeEach
void setUp() {
fakeClock.setTo(DateTime.parse("2010-10-17TZ"));
createTld("tld");
fakeClock.setTo(Instant.parse("2010-10-17T00:00:00Z"));
}
@Test
void testSerializable() {
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
Instant time = Instant.parse("2012-07-12T03:30:00.000Z");
tm().transact(() -> tm().put(Cursor.createGlobal(RECURRING_BILLING, time)));
Cursor persisted =
tm().transact(() -> tm().loadByKey(Cursor.createGlobalVKey(RECURRING_BILLING)));
@@ -54,9 +54,9 @@ public class CursorTest extends EntityTestCase {
@Test
void testSuccess_persistScopedCursor() {
Tld tld = createTld("tld");
Tld tld = Tld.get("tld");
this.fakeClock.advanceOneMilli();
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
Instant time = Instant.parse("2012-07-12T03:30:00.000Z");
Cursor cursor = Cursor.createScoped(RDE_UPLOAD, time, tld);
tm().transact(() -> tm().put(cursor));
tm().transact(
@@ -70,7 +70,7 @@ public class CursorTest extends EntityTestCase {
@Test
void testSuccess_persistGlobalCursor() {
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
Instant time = Instant.parse("2012-07-12T03:30:00.000Z");
Cursor cursor = Cursor.createGlobal(RECURRING_BILLING, time);
tm().transact(() -> tm().put(cursor));
assertThat(tm().transact(() -> tm().loadByKey(cursor.createVKey())).getCursorTime())
@@ -79,7 +79,7 @@ public class CursorTest extends EntityTestCase {
@Test
void testFailure_VKeyWrongScope() {
Tld tld = createTld("tld");
Tld tld = Tld.get("tld");
assertThrows(
IllegalArgumentException.class,
() -> Cursor.createGlobalVKey(RDE_UPLOAD),
@@ -97,23 +97,21 @@ public class CursorTest extends EntityTestCase {
NullPointerException thrown =
assertThrows(
NullPointerException.class,
() -> Cursor.createScoped(RECURRING_BILLING, START_OF_TIME, null));
() -> Cursor.createScoped(RECURRING_BILLING, START_INSTANT, null));
assertThat(thrown).hasMessageThat().contains("Cursor scope cannot be null");
}
@Test
void testFailure_nullCursorType() {
createTld("tld");
NullPointerException thrown =
assertThrows(
NullPointerException.class,
() -> Cursor.createScoped(null, START_OF_TIME, Tld.get("tld")));
() -> Cursor.createScoped(null, START_INSTANT, Tld.get("tld")));
assertThat(thrown).hasMessageThat().contains("Cursor type cannot be null");
}
@Test
void testFailure_nullTime() {
createTld("tld");
NullPointerException thrown =
assertThrows(
NullPointerException.class,
@@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.loadAllOf;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
@@ -34,12 +34,11 @@ public class DnsRefreshRequestTest extends EntityTestCase {
}
private final DnsRefreshRequest request =
new DnsRefreshRequest(
DnsUtils.TargetType.DOMAIN, "test.example", "example", fakeClock.nowUtc());
new DnsRefreshRequest(DnsUtils.TargetType.DOMAIN, "test.example", "example", fakeClock.now());
@Test
void testPersistence() {
assertThat(request.getLastProcessTime()).isEqualTo(START_OF_TIME);
assertThat(request.getLastProcessTime()).isEqualTo(START_INSTANT);
fakeClock.advanceOneMilli();
tm().transact(() -> tm().insert(request));
fakeClock.advanceOneMilli();
@@ -53,18 +52,17 @@ public class DnsRefreshRequestTest extends EntityTestCase {
// type
assertThrows(
NullPointerException.class,
() -> new DnsRefreshRequest(null, "test.example", "example", fakeClock.nowUtc()));
() -> new DnsRefreshRequest(null, "test.example", "example", fakeClock.now()));
// name
assertThrows(
NullPointerException.class,
() ->
new DnsRefreshRequest(DnsUtils.TargetType.DOMAIN, null, "example", fakeClock.nowUtc()));
() -> new DnsRefreshRequest(DnsUtils.TargetType.DOMAIN, null, "example", fakeClock.now()));
// tld
assertThrows(
NullPointerException.class,
() ->
new DnsRefreshRequest(
DnsUtils.TargetType.DOMAIN, "test.example", null, fakeClock.nowUtc()));
DnsUtils.TargetType.DOMAIN, "test.example", null, fakeClock.now()));
// request time
assertThrows(
NullPointerException.class,
@@ -75,22 +73,21 @@ public class DnsRefreshRequestTest extends EntityTestCase {
void testUpdateProcessTime() {
assertThat(
assertThrows(
IllegalArgumentException.class,
() -> request.updateProcessTime(fakeClock.nowUtc())))
IllegalArgumentException.class, () -> request.updateProcessTime(fakeClock.now())))
.hasMessageThat()
.contains("must be later than request time");
fakeClock.advanceOneMilli();
fakeClock.advanceOneMilli();
DnsRefreshRequest newRequest = request.updateProcessTime(fakeClock.nowUtc());
DnsRefreshRequest newRequest = request.updateProcessTime(fakeClock.now());
assertAboutImmutableObjects().that(newRequest).isEqualExceptFields(request, "lastProcessTime");
assertThat(newRequest.getLastProcessTime()).isEqualTo(fakeClock.nowUtc());
assertThat(newRequest.getLastProcessTime()).isEqualTo(fakeClock.now());
assertThat(
assertThrows(
IllegalArgumentException.class,
() -> newRequest.updateProcessTime(fakeClock.nowUtc().minusMillis(1))))
() -> newRequest.updateProcessTime(fakeClock.now().minusMillis(1))))
.hasMessageThat()
.contains("must be later than the old one");
}
@@ -35,8 +35,8 @@ import static google.registry.util.DateTimeUtils.minusDays;
import static google.registry.util.DateTimeUtils.plusDays;
import static google.registry.util.DateTimeUtils.plusYears;
import static google.registry.util.DateTimeUtils.toInstant;
import static java.time.ZoneOffset.UTC;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
@@ -73,10 +73,10 @@ import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.Optional;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -85,7 +85,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
@SuppressWarnings("WeakerAccess") // Referred to by EppInputTest.
public class DomainTest {
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
protected FakeClock fakeClock = new FakeClock(DateTime.now(DateTimeZone.UTC));
@RegisterExtension
final JpaIntegrationWithCoverageExtension jpa =
@@ -673,8 +673,7 @@ public class DomainTest {
.build();
Domain renewed =
domain.cloneProjectedAtTime(plusYears(domain.getRegistrationExpirationTime(), 4));
assertThat(renewed.getRegistrationExpirationTime().atZone(ZoneOffset.UTC).getDayOfMonth())
.isEqualTo(28);
assertThat(renewed.getRegistrationExpirationTime().atZone(UTC).getDayOfMonth()).isEqualTo(28);
}
@Test
@@ -739,7 +738,7 @@ public class DomainTest {
@Test
void testClone_doNotExtendExpirationOnDeletedDomain() {
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
domain =
persistResource(
domain
@@ -755,7 +754,7 @@ public class DomainTest {
@Test
void testClone_doNotExtendExpirationOnFutureDeletedDomain() {
// if a domain is in pending deletion (StatusValue.PENDING_DELETE), don't extend expiration
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
domain =
persistResource(
domain
@@ -771,7 +770,7 @@ public class DomainTest {
@Test
void testClone_extendsExpirationForExpiredTransferredDomain() {
// If the transfer implicitly succeeded, the expiration time should be extended
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
DateTime transferExpirationTime = now.minusDays(1);
DateTime previousExpiration = now.minusDays(2);
@@ -799,7 +798,7 @@ public class DomainTest {
void testClone_extendsExpirationForNonExpiredTransferredDomain() {
// If the transfer implicitly succeeded, the expiration time should be extended even if it
// hadn't already expired
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
DateTime transferExpirationTime = now.minusDays(1);
DateTime previousExpiration = now.plusWeeks(2);
@@ -827,7 +826,7 @@ public class DomainTest {
void testClone_removesBulkTokenFromTransferredDomain() {
// If the transfer implicitly succeeded, the expiration time should be extended even if it
// hadn't already expired
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
DateTime transferExpirationTime = now.minusDays(1);
DateTime previousExpiration = now.plusWeeks(2);
@@ -868,7 +867,7 @@ public class DomainTest {
@Test
void testClone_doesNotExtendExpirationForPendingTransfer() {
// Pending transfers shouldn't affect the expiration time
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
DateTime transferExpirationTime = now.plusDays(1);
DateTime previousExpiration = now.plusWeeks(2);
@@ -893,7 +892,7 @@ public class DomainTest {
@Test
void testClone_doesNotRemoveBulkTokenForPendingTransfer() {
// Pending transfers shouldn't affect the expiration time
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
DateTime transferExpirationTime = now.plusDays(1);
DateTime previousExpiration = now.plusWeeks(2);
@@ -933,7 +932,7 @@ public class DomainTest {
void testClone_transferDuringAutorenew() {
// When the domain is an autorenew grace period, we should not extend the registration
// expiration by a further year--it should just be whatever the autorenew was
DateTime now = DateTime.now(UTC);
DateTime now = DateTime.now(DateTimeZone.UTC);
DateTime transferExpirationTime = now.minusDays(1);
DateTime previousExpiration = now.minusDays(2);
@@ -15,6 +15,7 @@
package google.registry.model.domain;
import static com.google.common.truth.Truth.assertThat;
import static java.time.temporal.ChronoUnit.DAYS;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.billing.BillingBase.Reason;
@@ -27,7 +28,6 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.junit.jupiter.api.BeforeEach;
@@ -52,7 +52,7 @@ public class GracePeriodTest {
onetime =
new BillingEvent.Builder()
.setEventTime(now)
.setBillingTime(now.plus(1, ChronoUnit.DAYS))
.setBillingTime(now.plus(1, DAYS))
.setRegistrarId("TheRegistrar")
.setCost(Money.of(CurrencyUnit.USD, 42))
.setDomainHistoryId(new HistoryEntryId("domain", 12345))
@@ -71,7 +71,7 @@ public class GracePeriodTest {
assertThat(gracePeriod.getBillingEvent()).isEqualTo(onetime.createVKey());
assertThat(gracePeriod.getBillingRecurrence()).isNull();
assertThat(gracePeriod.getRegistrarId()).isEqualTo("TheRegistrar");
assertThat(gracePeriod.getExpirationTime()).isEqualTo(now.plus(1, ChronoUnit.DAYS));
assertThat(gracePeriod.getExpirationTime()).isEqualTo(now.plus(1, DAYS));
assertThat(gracePeriod.hasBillingEvent()).isTrue();
}
@@ -81,7 +81,7 @@ public class GracePeriodTest {
GracePeriod.createForRecurrence(
GracePeriodStatus.AUTO_RENEW,
"1-TEST",
now.plus(1, ChronoUnit.DAYS),
now.plus(1, DAYS),
"TheRegistrar",
recurrenceKey);
assertThat(gracePeriod.getType()).isEqualTo(GracePeriodStatus.AUTO_RENEW);
@@ -89,7 +89,7 @@ public class GracePeriodTest {
assertThat(gracePeriod.getBillingEvent()).isNull();
assertThat(gracePeriod.getBillingRecurrence()).isEqualTo(recurrenceKey);
assertThat(gracePeriod.getRegistrarId()).isEqualTo("TheRegistrar");
assertThat(gracePeriod.getExpirationTime()).isEqualTo(now.plus(1, ChronoUnit.DAYS));
assertThat(gracePeriod.getExpirationTime()).isEqualTo(now.plus(1, DAYS));
assertThat(gracePeriod.hasBillingEvent()).isTrue();
}
@@ -125,7 +125,7 @@ public class GracePeriodTest {
GracePeriod.createForRecurrence(
GracePeriodStatus.RENEW,
"1-TEST",
now.plus(1, ChronoUnit.DAYS),
now.plus(1, DAYS),
"TheRegistrar",
recurrenceKey));
assertThat(thrown).hasMessageThat().contains("autorenew");
@@ -21,7 +21,7 @@ import static google.registry.model.rde.RdeNamingUtils.makePartialName;
import static google.registry.model.rde.RdeNamingUtils.makeRydeFilename;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link RdeNamingUtils}. */
@@ -29,19 +29,19 @@ class RdeNamingUtilsTest {
@Test
void testMakeRydeFilename_rdeDeposit() {
assertThat(makeRydeFilename("numbness", DateTime.parse("1984-12-18TZ"), FULL, 1, 0))
assertThat(makeRydeFilename("numbness", Instant.parse("1984-12-18T00:00:00Z"), FULL, 1, 0))
.isEqualTo("numbness_1984-12-18_full_S1_R0");
}
@Test
void testMakeRydeFilename_brdaDeposit() {
assertThat(makeRydeFilename("dreary", DateTime.parse("2000-12-18TZ"), THIN, 1, 0))
assertThat(makeRydeFilename("dreary", Instant.parse("2000-12-18T00:00:00Z"), THIN, 1, 0))
.isEqualTo("dreary_2000-12-18_thin_S1_R0");
}
@Test
void testMakeRydeFilename_revisionNumber() {
assertThat(makeRydeFilename("wretched", DateTime.parse("2000-12-18TZ"), THIN, 1, 123))
assertThat(makeRydeFilename("wretched", Instant.parse("2000-12-18T00:00:00Z"), THIN, 1, 123))
.isEqualTo("wretched_2000-12-18_thin_S1_R123");
}
@@ -49,12 +49,12 @@ class RdeNamingUtilsTest {
void testMakeRydeFilename_timestampNotAtTheWitchingHour_throwsIae() {
assertThrows(
IllegalArgumentException.class,
() -> makeRydeFilename("wretched", DateTime.parse("2000-12-18T04:20Z"), THIN, 1, 0));
() -> makeRydeFilename("wretched", Instant.parse("2000-12-18T04:20:00Z"), THIN, 1, 0));
}
@Test
void testMakePartialName() {
assertThat(makePartialName("unholy", DateTime.parse("2000-12-18TZ"), THIN))
assertThat(makePartialName("unholy", Instant.parse("2000-12-18T00:00:00Z"), THIN))
.isEqualTo("unholy_2000-12-18_thin");
}
}
@@ -19,10 +19,12 @@ import static google.registry.model.rde.RdeMode.FULL;
import static google.registry.model.rde.RdeRevision.getNextRevision;
import static google.registry.model.rde.RdeRevision.saveRevision;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.toJodaLocalDate;
import static java.time.temporal.ChronoUnit.DAYS;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.EntityTestCase;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -35,28 +37,25 @@ public class RdeRevisionTest extends EntityTestCase {
@BeforeEach
void beforeEach() {
fakeClock.setTo(DateTime.parse("1984-12-18TZ"));
fakeClock.setTo(Instant.parse("1984-12-18T00:00:00Z"));
}
@Test
void testGetNextRevision_objectDoesntExist_returnsZero() {
tm().transact(
() -> assertThat(getNextRevision("torment", fakeClock.nowUtc(), FULL)).isEqualTo(0));
tm().transact(() -> assertThat(getNextRevision("torment", fakeClock.now(), FULL)).isEqualTo(0));
}
@Test
void testGetNextRevision_objectExistsAtZero_returnsOne() {
save("sorrow", fakeClock.nowUtc(), FULL, 0);
tm().transact(
() -> assertThat(getNextRevision("sorrow", fakeClock.nowUtc(), FULL)).isEqualTo(1));
save("sorrow", fakeClock.now(), FULL, 0);
tm().transact(() -> assertThat(getNextRevision("sorrow", fakeClock.now(), FULL)).isEqualTo(1));
}
@Test
void testSaveRevision_objectDoesntExist_newRevisionIsZero_nextRevIsOne() {
tm().transact(() -> saveRevision("despondency", fakeClock.nowUtc(), FULL, 0));
tm().transact(() -> saveRevision("despondency", fakeClock.now(), FULL, 0));
tm().transact(
() ->
assertThat(getNextRevision("despondency", fakeClock.nowUtc(), FULL)).isEqualTo(1));
() -> assertThat(getNextRevision("despondency", fakeClock.now(), FULL)).isEqualTo(1));
}
@Test
@@ -64,7 +63,7 @@ public class RdeRevisionTest extends EntityTestCase {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> tm().transact(() -> saveRevision("despondency", fakeClock.nowUtc(), FULL, 1)));
() -> tm().transact(() -> saveRevision("despondency", fakeClock.now(), FULL, 1)));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
@@ -74,17 +73,17 @@ public class RdeRevisionTest extends EntityTestCase {
@Test
void testSaveRevision_objectExistsAtZero_newRevisionIsZero_throwsVe() {
save("melancholy", fakeClock.nowUtc(), FULL, 0);
save("melancholy", fakeClock.now(), FULL, 0);
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> tm().transact(() -> saveRevision("melancholy", fakeClock.nowUtc(), FULL, 0)));
() -> tm().transact(() -> saveRevision("melancholy", fakeClock.now(), FULL, 0)));
assertThat(thrown).hasMessageThat().contains("object already created");
}
@Test
void testSaveRevision_objectExistsAtZero_newRevisionIsOne_nextRevIsTwo() {
DateTime startOfDay = fakeClock.nowUtc().withTimeAtStartOfDay();
Instant startOfDay = fakeClock.now().truncatedTo(DAYS);
save("melancholy", startOfDay, FULL, 0);
fakeClock.advanceOneMilli();
tm().transact(() -> saveRevision("melancholy", startOfDay, FULL, 1));
@@ -93,11 +92,11 @@ public class RdeRevisionTest extends EntityTestCase {
@Test
void testSaveRevision_objectExistsAtZero_newRevisionIsTwo_throwsVe() {
save("melancholy", fakeClock.nowUtc(), FULL, 0);
save("melancholy", fakeClock.now(), FULL, 0);
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> tm().transact(() -> saveRevision("melancholy", fakeClock.nowUtc(), FULL, 2)));
() -> tm().transact(() -> saveRevision("melancholy", fakeClock.now(), FULL, 2)));
assertThat(thrown)
.hasMessageThat()
.contains("RDE revision object should be at revision 1 but was");
@@ -108,7 +107,7 @@ public class RdeRevisionTest extends EntityTestCase {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> tm().transact(() -> saveRevision("melancholy", fakeClock.nowUtc(), FULL, -1)));
() -> tm().transact(() -> saveRevision("melancholy", fakeClock.now(), FULL, -1)));
assertThat(thrown).hasMessageThat().contains("Negative revision");
}
@@ -116,12 +115,12 @@ public class RdeRevisionTest extends EntityTestCase {
void testSaveRevision_callerNotInTransaction_throwsIse() {
IllegalStateException thrown =
assertThrows(
IllegalStateException.class, () -> saveRevision("frenzy", fakeClock.nowUtc(), FULL, 1));
IllegalStateException.class, () -> saveRevision("frenzy", fakeClock.now(), FULL, 1));
assertThat(thrown).hasMessageThat().contains("transaction");
}
public static void save(String tld, DateTime date, RdeMode mode, int revision) {
RdeRevision object = RdeRevision.create(tld, date.toLocalDate(), mode, revision);
public static void save(String tld, Instant date, RdeMode mode, int revision) {
RdeRevision object = RdeRevision.create(tld, toJodaLocalDate(date), mode, revision);
tm().transact(() -> tm().put(object));
}
}
@@ -25,8 +25,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import google.registry.model.EntityTestCase;
import google.registry.model.server.Lock.LockState;
import java.time.Duration;
import java.util.Optional;
import org.joda.time.Duration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -35,8 +35,8 @@ import org.junit.jupiter.api.Test;
public class LockTest extends EntityTestCase {
private static final String RESOURCE_NAME = "foo";
private static final Duration ONE_DAY = Duration.standardDays(1);
private static final Duration TWO_MILLIS = Duration.millis(2);
private static final Duration ONE_DAY = Duration.ofDays(1);
private static final Duration TWO_MILLIS = Duration.ofMillis(2);
private LockMetrics origLockMetrics;
@@ -58,7 +58,7 @@ public class LockTest extends EntityTestCase {
Lock.lockMetrics = mock(LockMetrics.class);
lock.release();
verify(Lock.lockMetrics)
.recordRelease(RESOURCE_NAME, expectedTld, Duration.millis(expectedMillis));
.recordRelease(RESOURCE_NAME, expectedTld, Duration.ofMillis(expectedMillis));
verifyNoMoreInteractions(Lock.lockMetrics);
Lock.lockMetrics = null;
}
@@ -81,7 +81,7 @@ public class LockTest extends EntityTestCase {
// We can't get it again at the same time.
assertThat(acquire("", ONE_DAY, IN_USE)).isEmpty();
// But if we release it, it's available.
fakeClock.advanceBy(Duration.millis(123));
fakeClock.advanceBy(Duration.ofMillis(123));
release(lock.get(), "", 123);
assertThat(acquire("", ONE_DAY, FREE)).isPresent();
}
@@ -16,6 +16,7 @@ package google.registry.mosapi.module;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.util.DateTimeUtils.plusYears;
import static java.time.ZoneOffset.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -34,7 +35,6 @@ import java.security.Security;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import javax.net.ssl.SSLContext;
@@ -154,8 +154,7 @@ public class MosApiModuleTest {
keyGen.initialize(2048);
KeyPair keyPair = keyGen.generateKeyPair();
this.generatedPrivateKey = keyPair.getPrivate();
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyyMMddHHmmss'Z'").withZone(ZoneOffset.UTC);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss'Z'").withZone(UTC);
Instant now = Instant.parse("2021-01-01T00:00:00Z");
Instant end = plusYears(now, 1);
// Convert string to Bouncy Castle Time objects
@@ -22,6 +22,7 @@ import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.GpgSystemCommandExtension.GPG_BINARY;
import static google.registry.testing.SystemInfo.hasCommand;
import static google.registry.util.DateTimeUtils.plusDays;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@@ -47,11 +48,11 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.Instant;
import java.util.Optional;
import org.bouncycastle.openpgp.PGPKeyPair;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -116,7 +117,7 @@ public class BrdaCopyActionTest {
createTld("lol");
action.gcsUtils = gcsUtils;
action.tld = "lol";
action.watermark = DateTime.parse("2010-10-17TZ");
action.watermark = Instant.parse("2010-10-17T00:00:00Z");
action.brdaBucket = "tub";
action.stagingBucket = "keg";
action.receiverKey = receiverKey;
@@ -124,9 +125,10 @@ public class BrdaCopyActionTest {
action.stagingDecryptionKey = decryptKey;
tm().transact(
() -> {
RdeRevision.saveRevision("lol", DateTime.parse("2010-10-17TZ"), RdeMode.THIN, 0);
RdeRevision.saveRevision(
"lol", Instant.parse("2010-10-17T00:00:00Z"), RdeMode.THIN, 0);
});
persistResource(Cursor.createScoped(BRDA, action.watermark.plusDays(1), Tld.get("lol")));
persistResource(Cursor.createScoped(BRDA, plusDays(action.watermark, 1), Tld.get("lol")));
}
@ParameterizedTest
@@ -138,8 +140,8 @@ public class BrdaCopyActionTest {
.hasMessageThat()
.isEqualTo(
"Waiting on RdeStagingAction for TLD lol to copy BRDA deposit for"
+ " 2010-10-17T00:00:00.000Z to GCS; last BRDA staging completion was before"
+ " 2010-10-17T00:00:00.000Z");
+ " 2010-10-17T00:00:00Z to GCS; last BRDA staging completion was before"
+ " 2010-10-17T00:00:00Z");
}
@ParameterizedTest
@@ -85,7 +85,7 @@ public class DomainToXjcConverterTest {
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
private final DateTime now = DateTime.parse("2014-01-01T00:00:00Z");
private final Instant now = Instant.parse("2014-01-01T00:00:00Z");
private final FakeClock clock = new FakeClock(now);
@BeforeEach
@@ -207,7 +207,7 @@ public class DomainToXjcConverterTest {
XjcRdeDeposit deposit = new XjcRdeDeposit();
deposit.setId("984302");
deposit.setType(XjcRdeDepositTypeType.FULL);
deposit.setWatermark(new DateTime("2012-01-01T04:20:00Z"));
deposit.setWatermark(DateTime.parse("2012-01-01T04:20:00Z"));
XjcRdeMenuType menu = new XjcRdeMenuType();
menu.setVersion("1.0");
menu.getObjURIs().add("lol");
@@ -18,8 +18,6 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadByKey;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardSeconds;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -34,8 +32,9 @@ import google.registry.request.HttpException.NoContentException;
import google.registry.request.HttpException.ServiceUnavailableException;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeLockHandler;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -49,9 +48,9 @@ public class EscrowTaskRunnerTest {
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
private final EscrowTask task = mock(EscrowTask.class);
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("2000-01-01T00:00:00Z"));
private DateTimeZone previousDateTimeZone;
private ZoneId previousDateTimeZone;
private EscrowTaskRunner runner;
private Tld registry;
@@ -62,64 +61,77 @@ public class EscrowTaskRunnerTest {
runner = new EscrowTaskRunner();
runner.clock = clock;
runner.lockHandler = new FakeLockHandler(true);
previousDateTimeZone = DateTimeZone.getDefault();
DateTimeZone.setDefault(DateTimeZone.forID("America/New_York")); // Make sure UTC stuff works.
previousDateTimeZone = ZoneId.systemDefault();
// java.time.ZoneId does not have a global setDefault
System.setProperty("user.timezone", "America/New_York"); // Make sure UTC stuff works.
}
@AfterEach
void afterEach() {
DateTimeZone.setDefault(previousDateTimeZone);
// Restore timezone
System.setProperty("user.timezone", previousDateTimeZone.getId());
}
@Test
void testRun_cursorIsToday_advancesCursorToTomorrow() throws Exception {
clock.setTo(DateTime.parse("2006-06-06T00:30:00Z"));
clock.setTo(Instant.parse("2006-06-06T00:30:00Z"));
persistResource(
Cursor.createScoped(CursorType.RDE_STAGING, DateTime.parse("2006-06-06TZ"), registry));
Cursor.createScoped(
CursorType.RDE_STAGING, Instant.parse("2006-06-06T00:00:00Z"), registry));
runner.lockRunAndRollForward(
task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1));
verify(task).runWithLock(DateTime.parse("2006-06-06TZ"));
task, registry, Duration.ofSeconds(30), CursorType.RDE_STAGING, Duration.ofDays(1));
verify(task).runWithLock(Instant.parse("2006-06-06T00:00:00Z"));
Cursor cursor = loadByKey(Cursor.createScopedVKey(CursorType.RDE_STAGING, registry));
assertThat(cursor.getCursorTime()).isEqualTo(DateTime.parse("2006-06-07TZ"));
assertThat(cursor.getCursorTime()).isEqualTo(Instant.parse("2006-06-07T00:00:00Z"));
}
@Test
void testRun_cursorMissing_assumesTodayAndAdvancesCursorToTomorrow() throws Exception {
clock.setTo(DateTime.parse("2006-06-06T00:30:00Z"));
clock.setTo(Instant.parse("2006-06-06T00:30:00Z"));
runner.lockRunAndRollForward(
task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1));
verify(task).runWithLock(DateTime.parse("2006-06-06TZ"));
task, registry, Duration.ofSeconds(30), CursorType.RDE_STAGING, Duration.ofDays(1));
verify(task).runWithLock(Instant.parse("2006-06-06T00:00:00Z"));
Cursor cursor = loadByKey(Cursor.createScopedVKey(CursorType.RDE_STAGING, registry));
assertThat(cursor.getCursorTime()).isEqualTo(DateTime.parse("2006-06-07TZ"));
assertThat(cursor.getCursorTime()).isEqualTo(Instant.parse("2006-06-07T00:00:00Z"));
}
@Test
void testRun_cursorInTheFuture_doesNothing() {
clock.setTo(DateTime.parse("2006-06-06T00:30:00Z"));
clock.setTo(Instant.parse("2006-06-06T00:30:00Z"));
persistResource(
Cursor.createScoped(CursorType.RDE_STAGING, DateTime.parse("2006-06-07TZ"), registry));
Cursor.createScoped(
CursorType.RDE_STAGING, Instant.parse("2006-06-07T00:00:00Z"), registry));
NoContentException thrown =
assertThrows(
NoContentException.class,
() ->
runner.lockRunAndRollForward(
task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1)));
task,
registry,
Duration.ofSeconds(30),
CursorType.RDE_STAGING,
Duration.ofDays(1)));
assertThat(thrown).hasMessageThat().contains("Already completed");
}
@Test
void testRun_lockIsntAvailable_throws503() {
String lockName = "EscrowTaskRunner " + task.getClass().getSimpleName();
clock.setTo(DateTime.parse("2006-06-06T00:30:00Z"));
clock.setTo(Instant.parse("2006-06-06T00:30:00Z"));
persistResource(
Cursor.createScoped(CursorType.RDE_STAGING, DateTime.parse("2006-06-06TZ"), registry));
Cursor.createScoped(
CursorType.RDE_STAGING, Instant.parse("2006-06-06T00:00:00Z"), registry));
runner.lockHandler = new FakeLockHandler(false);
ServiceUnavailableException thrown =
assertThrows(
ServiceUnavailableException.class,
() ->
runner.lockRunAndRollForward(
task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1)));
task,
registry,
Duration.ofSeconds(30),
CursorType.RDE_STAGING,
Duration.ofDays(1)));
assertThat(thrown).hasMessageThat().contains("Lock in use: " + lockName + " for TLD: lol");
}
}
@@ -25,7 +25,6 @@ import static google.registry.testing.DatabaseHelper.loadByKey;
import static google.registry.testing.DatabaseHelper.loadByKeyIfPresent;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.time.DateTimeConstants.TUESDAY;
import static org.joda.time.Duration.standardDays;
import com.google.common.collect.ImmutableSetMultimap;
import google.registry.model.common.Cursor;
@@ -34,7 +33,8 @@ import google.registry.model.tld.Tld;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import java.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -52,9 +52,9 @@ public class PendingDepositCheckerTest {
@BeforeEach
void beforeEach() {
checker.brdaDayOfWeek = TUESDAY;
checker.brdaInterval = standardDays(7);
checker.brdaInterval = Duration.ofDays(7);
checker.clock = clock;
checker.rdeInterval = standardDays(1);
checker.rdeInterval = Duration.ofDays(1);
}
@Test
@@ -66,46 +66,63 @@ public class PendingDepositCheckerTest {
@Test
void testMethod_firstDeposit_depositsRdeTodayAtMidnight() {
clock.setTo(DateTime.parse("2000-01-01T08:00Z")); // Saturday
clock.setTo(Instant.parse("2000-01-01T08:00:00Z")); // Saturday
createTldWithEscrowEnabled("lol");
clock.advanceOneMilli();
assertThat(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda()).isEqualTo(
ImmutableSetMultimap.of(
"lol", PendingDeposit.create(
"lol", DateTime.parse("2000-01-01TZ"), FULL, RDE_STAGING, standardDays(1))));
assertThat(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda())
.isEqualTo(
ImmutableSetMultimap.of(
"lol",
PendingDeposit.create(
"lol",
Instant.parse("2000-01-01T00:00:00Z"),
FULL,
RDE_STAGING,
Duration.ofDays(1))));
}
@Test
void testMethod_firstDepositOnBrdaDay_depositsBothRdeAndBrda() {
clock.setTo(DateTime.parse("2000-01-04T08:00Z")); // Tuesday
clock.setTo(Instant.parse("2000-01-04T08:00:00Z")); // Tuesday
createTldWithEscrowEnabled("lol");
clock.setAutoIncrementByOneMilli();
assertThat(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda()).isEqualTo(
ImmutableSetMultimap.of(
"lol", PendingDeposit.create(
"lol", DateTime.parse("2000-01-04TZ"), FULL, RDE_STAGING, standardDays(1)),
"lol", PendingDeposit.create(
"lol", DateTime.parse("2000-01-04TZ"), THIN, BRDA, standardDays(7))));
assertThat(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda())
.isEqualTo(
ImmutableSetMultimap.of(
"lol",
PendingDeposit.create(
"lol",
Instant.parse("2000-01-04T00:00:00Z"),
FULL,
RDE_STAGING,
Duration.ofDays(1)),
"lol",
PendingDeposit.create(
"lol",
Instant.parse("2000-01-04T00:00:00Z"),
THIN,
BRDA,
Duration.ofDays(7))));
}
@Test
void testMethod_firstRdeDeposit_initializesCursorToMidnightToday() {
clock.setTo(DateTime.parse("2000-01-01TZ")); // Saturday
clock.setTo(Instant.parse("2000-01-01T00:00:00Z")); // Saturday
createTldWithEscrowEnabled("lol");
clock.advanceOneMilli();
Tld registry = Tld.get("lol");
assertThat(loadByKeyIfPresent(Cursor.createScopedVKey(RDE_STAGING, registry))).isEmpty();
checker.getTldsAndWatermarksPendingDepositForRdeAndBrda();
assertThat(loadByKey(Cursor.createScopedVKey(RDE_STAGING, registry)).getCursorTime())
.isEqualTo(DateTime.parse("2000-01-01TZ"));
.isEqualTo(Instant.parse("2000-01-01T00:00:00Z"));
}
@Test
void testMethod_subsequentRdeDeposit_doesntMutateCursor() {
clock.setTo(DateTime.parse("2000-01-01TZ")); // Saturday
clock.setTo(Instant.parse("2000-01-01T00:00:00Z")); // Saturday
createTldWithEscrowEnabled("lol");
clock.advanceOneMilli();
DateTime yesterday = DateTime.parse("1999-12-31TZ");
Instant yesterday = Instant.parse("1999-12-31T00:00:00Z");
setCursor(Tld.get("lol"), RDE_STAGING, yesterday);
clock.advanceOneMilli();
checker.getTldsAndWatermarksPendingDepositForRdeAndBrda();
@@ -115,11 +132,12 @@ public class PendingDepositCheckerTest {
@Test
void testMethod_firstBrdaDepositButNotOnBrdaDay_doesntInitializeCursor() {
clock.setTo(DateTime.parse("2000-01-01TZ")); // Saturday
clock.setTo(Instant.parse("2000-01-01T00:00:00Z")); // Saturday
createTldWithEscrowEnabled("lol");
Tld registry = Tld.get("lol");
clock.advanceOneMilli();
setCursor(registry, RDE_STAGING, DateTime.parse("2000-01-02TZ")); // assume rde is already done
setCursor(
registry, RDE_STAGING, Instant.parse("2000-01-02T00:00:00Z")); // assume rde is already done
clock.advanceOneMilli();
assertThat(loadByKeyIfPresent(Cursor.createScopedVKey(BRDA, registry))).isEmpty();
assertThat(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda()).isEmpty();
@@ -128,20 +146,26 @@ public class PendingDepositCheckerTest {
@Test
void testMethod_backloggedTwoDays_onlyWantsLeastRecentDay() {
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
createTldWithEscrowEnabled("lol");
clock.advanceOneMilli();
setCursor(Tld.get("lol"), RDE_STAGING, DateTime.parse("1999-12-30TZ"));
setCursor(Tld.get("lol"), RDE_STAGING, Instant.parse("1999-12-30T00:00:00Z"));
clock.advanceOneMilli();
assertThat(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda()).isEqualTo(
ImmutableSetMultimap.of(
"lol", PendingDeposit.create(
"lol", DateTime.parse("1999-12-30TZ"), FULL, RDE_STAGING, standardDays(1))));
assertThat(checker.getTldsAndWatermarksPendingDepositForRdeAndBrda())
.isEqualTo(
ImmutableSetMultimap.of(
"lol",
PendingDeposit.create(
"lol",
Instant.parse("1999-12-30T00:00:00Z"),
FULL,
RDE_STAGING,
Duration.ofDays(1))));
}
@Test
void testMethod_multipleTldsWithEscrowEnabled_depositsBoth() {
clock.setTo(DateTime.parse("2000-01-01TZ")); // Saturday
clock.setTo(Instant.parse("2000-01-01T00:00:00Z")); // Saturday
createTldWithEscrowEnabled("pal");
clock.advanceOneMilli();
createTldWithEscrowEnabled("fun");
@@ -151,18 +175,21 @@ public class PendingDepositCheckerTest {
ImmutableSetMultimap.of(
"pal",
PendingDeposit.create(
"pal", DateTime.parse("2000-01-01TZ"), FULL, RDE_STAGING, standardDays(1)),
"pal",
Instant.parse("2000-01-01T00:00:00Z"),
FULL,
RDE_STAGING,
Duration.ofDays(1)),
"fun",
PendingDeposit.create(
"fun",
DateTime.parse("2000-01-01TZ"),
Instant.parse("2000-01-01T00:00:00Z"),
FULL,
RDE_STAGING,
standardDays(1))));
Duration.ofDays(1))));
}
private static void setCursor(
final Tld registry, final CursorType cursorType, final DateTime value) {
private static void setCursor(final Tld registry, final CursorType cursorType, Instant value) {
tm().transact(() -> tm().put(Cursor.createScoped(cursorType, value, registry)));
}
@@ -21,16 +21,16 @@ import static google.registry.util.SafeSerializationUtils.safeDeserialize;
import static google.registry.util.SerializeUtils.deserialize;
import static google.registry.util.SerializeUtils.serialize;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import java.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link PendingDeposit}. */
public class PendingDepositTest {
private final DateTime now = DateTime.parse("2000-01-01TZ");
private final Instant now = Instant.parse("2000-01-01T00:00:00Z");
PendingDeposit pendingDeposit =
PendingDeposit.create("soy", now, FULL, RDE_STAGING, Duration.standardDays(1));
PendingDeposit.create("soy", now, FULL, RDE_STAGING, Duration.ofDays(1));
PendingDeposit manualPendingDeposit =
PendingDeposit.createInManualOperation("soy", now, FULL, "/", null);
@@ -26,8 +26,6 @@ import static google.registry.testing.DatabaseHelper.persistResource;
import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
import static jakarta.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardSeconds;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -58,6 +56,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
@@ -104,9 +104,9 @@ public class RdeReportActionTest {
action.response = response;
action.bucket = "tub";
action.tld = "test";
action.interval = standardDays(1);
action.interval = Duration.ofDays(1);
action.reporter = reporter;
action.timeout = standardSeconds(30);
action.timeout = Duration.ofSeconds(30);
action.stagingDecryptionKey = new FakeKeyringModule().get().getRdeStagingDecryptionKey();
action.runner = runner;
action.prefix = Optional.of("job-name/");
@@ -116,10 +116,13 @@ public class RdeReportActionTest {
@BeforeEach
void beforeEach() throws Exception {
registry = createTld("test");
persistResource(Cursor.createScoped(RDE_REPORT, DateTime.parse("2006-06-06TZ"), registry));
persistResource(Cursor.createScoped(RDE_UPLOAD, DateTime.parse("2006-06-07TZ"), registry));
persistResource(
Cursor.createScoped(RDE_REPORT, Instant.parse("2006-06-06T00:00:00Z"), registry));
persistResource(
Cursor.createScoped(RDE_UPLOAD, Instant.parse("2006-06-07T00:00:00Z"), registry));
gcsUtils.createFromBytes(reportFile, Ghostryde.encode(REPORT_XML.read(), encryptKey));
tm().transact(() -> RdeRevision.saveRevision("test", DateTime.parse("2006-06-06TZ"), FULL, 0));
tm().transact(
() -> RdeRevision.saveRevision("test", Instant.parse("2006-06-06T00:00:00Z"), FULL, 0));
when(httpUrlConnection.getOutputStream()).thenReturn(connectionOutputStream);
when(httpUrlConnection.getResponseCode()).thenReturn(SC_OK);
when(httpUrlConnection.getInputStream()).thenReturn(IIRDEA_GOOD_XML.openBufferedStream());
@@ -133,7 +136,7 @@ public class RdeReportActionTest {
action.run();
verify(runner)
.lockRunAndRollForward(
action, Tld.get("lol"), standardSeconds(30), RDE_REPORT, standardDays(1));
action, Tld.get("lol"), Duration.ofSeconds(30), RDE_REPORT, Duration.ofDays(1));
verifyNoMoreInteractions(runner);
}
@@ -142,7 +145,7 @@ public class RdeReportActionTest {
createAction().runWithLock(loadRdeReportCursor());
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK test 2006-06-06T00:00:00.000Z\n");
assertThat(response.getPayload()).isEqualTo("OK test 2006-06-06T00:00:00Z\n");
// Verify the HTTP request was correct.
verify(httpUrlConnection).setRequestMethod("PUT");
@@ -164,7 +167,7 @@ public class RdeReportActionTest {
action.runWithLock(loadRdeReportCursor());
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK test 2006-06-06T00:00:00.000Z\n");
assertThat(response.getPayload()).isEqualTo("OK test 2006-06-06T00:00:00Z\n");
// Verify the HTTP request was correct.
verify(httpUrlConnection).setRequestMethod("PUT");
@@ -204,11 +207,12 @@ public class RdeReportActionTest {
Ghostryde.encode(
ByteSource.wrap("BAD DATA".getBytes(StandardCharsets.UTF_8)).read(), encryptKey));
gcsUtils.createFromBytes(otherReportFile2, Ghostryde.encode(REPORT_XML.read(), encryptKey));
tm().transact(() -> RdeRevision.saveRevision("test", DateTime.parse("2006-06-06TZ"), FULL, 1));
tm().transact(
() -> RdeRevision.saveRevision("test", Instant.parse("2006-06-06T00:00:00Z"), FULL, 1));
action.runWithLock(loadRdeReportCursor());
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK test 2006-06-06T00:00:00.000Z\n");
assertThat(response.getPayload()).isEqualTo("OK test 2006-06-06T00:00:00Z\n");
// Verify the HTTP request was correct.
verify(httpUrlConnection).setRequestMethod("PUT");
@@ -230,7 +234,8 @@ public class RdeReportActionTest {
BlobId newReport = BlobId.of("tub", "job-name/test_2006-06-06_full_S1_R1-report.xml.ghostryde");
PGPPublicKey encryptKey = new FakeKeyringModule().get().getRdeStagingEncryptionKey();
gcsUtils.createFromBytes(newReport, Ghostryde.encode(REPORT_XML.read(), encryptKey));
tm().transact(() -> RdeRevision.saveRevision("test", DateTime.parse("2006-06-06TZ"), FULL, 1));
tm().transact(
() -> RdeRevision.saveRevision("test", Instant.parse("2006-06-06T00:00:00Z"), FULL, 1));
createAction().runWithLock(loadRdeReportCursor());
assertThat(response.getStatus()).isEqualTo(200);
}
@@ -243,22 +248,22 @@ public class RdeReportActionTest {
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Waiting on RdeUploadAction for TLD test to send 2006-06-06T00:00:00.000Z report; last"
+ " upload completion was at 1970-01-01T00:00:00.000Z");
"Waiting on RdeUploadAction for TLD test to send 2006-06-06T00:00:00Z report; last"
+ " upload completion was at 1970-01-01T00:00:00Z");
}
@Test
void testRunWithLock_uploadNotFinished_throws204() {
persistResource(
Cursor.createScoped(RDE_UPLOAD, DateTime.parse("2006-06-06TZ"), Tld.get("test")));
Cursor.createScoped(RDE_UPLOAD, Instant.parse("2006-06-06T00:00:00Z"), Tld.get("test")));
NoContentException thrown =
assertThrows(
NoContentException.class, () -> createAction().runWithLock(loadRdeReportCursor()));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Waiting on RdeUploadAction for TLD test to send 2006-06-06T00:00:00.000Z report; "
+ "last upload completion was at 2006-06-06T00:00:00.000Z");
"Waiting on RdeUploadAction for TLD test to send 2006-06-06T00:00:00Z report; "
+ "last upload completion was at 2006-06-06T00:00:00Z");
}
@Test
@@ -282,7 +287,7 @@ public class RdeReportActionTest {
assertThat(thrown).hasMessageThat().contains("PUT failed");
}
private DateTime loadRdeReportCursor() {
private Instant loadRdeReportCursor() {
return loadByKey(Cursor.createScopedVKey(RDE_REPORT, registry)).getCursorTime();
}
@@ -35,10 +35,10 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.request.HttpException.BadRequestException;
import google.registry.testing.FakeClock;
import java.nio.charset.StandardCharsets;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -64,10 +64,10 @@ public class RdeStagingActionTest extends BeamActionTestBase {
action.jobRegion = "jobRegion";
action.rdeBucket = "rde-bucket";
action.pendingDepositChecker = new PendingDepositChecker();
action.pendingDepositChecker.brdaDayOfWeek = DateTimeConstants.TUESDAY;
action.pendingDepositChecker.brdaInterval = Duration.standardDays(7);
action.pendingDepositChecker.brdaDayOfWeek = DayOfWeek.TUESDAY.getValue();
action.pendingDepositChecker.brdaInterval = Duration.ofDays(7);
action.pendingDepositChecker.clock = clock;
action.pendingDepositChecker.rdeInterval = Duration.standardDays(1);
action.pendingDepositChecker.rdeInterval = Duration.ofDays(1);
action.gcsUtils = gcsUtils;
action.response = response;
action.transactionCooldown = Duration.ZERO;
@@ -84,7 +84,7 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testRun_modeInNonManualMode_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.modeStrings = ImmutableSet.of("full");
assertThrows(BadRequestException.class, action::run);
verifyNoMoreInteractions(dataflow);
@@ -93,7 +93,7 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testRun_tldInNonManualMode_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.tlds = ImmutableSet.of("tld");
assertThrows(BadRequestException.class, action::run);
verifyNoMoreInteractions(dataflow);
@@ -102,8 +102,8 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testRun_watermarkInNonManualMode_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
action.watermarks = ImmutableSet.of(clock.nowUtc());
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.watermarks = ImmutableSet.of(clock.now());
assertThrows(BadRequestException.class, action::run);
verifyNoMoreInteractions(dataflow);
}
@@ -111,7 +111,7 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testRun_revisionInNonManualMode_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.revision = Optional.of(42);
assertThrows(BadRequestException.class, action::run);
verifyNoMoreInteractions(dataflow);
@@ -128,7 +128,7 @@ public class RdeStagingActionTest extends BeamActionTestBase {
void testRun_tldWithoutEscrowEnabled_returns204() {
createTld("lol");
persistResource(Tld.get("lol").asBuilder().setEscrowEnabled(false).build());
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.run();
assertThat(response.getStatus()).isEqualTo(204);
verifyNoMoreInteractions(dataflow);
@@ -137,7 +137,7 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testRun_tldWithEscrowEnabled_launchesPipeline() throws Exception {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.run();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getPayload()).contains("Launched RDE pipeline: jobid");
@@ -148,8 +148,8 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testRun_withinTransactionCooldown_getsExcludedAndReturns204() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01T00:04:59Z"));
action.transactionCooldown = Duration.standardMinutes(5);
clock.setTo(Instant.parse("2000-01-01T00:04:59Z"));
action.transactionCooldown = Duration.ofMinutes(5);
action.run();
assertThat(response.getStatus()).isEqualTo(204);
verifyNoMoreInteractions(dataflow);
@@ -158,8 +158,8 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testRun_afterTransactionCooldown_runsPipeline() throws Exception {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01T00:05:00Z"));
action.transactionCooldown = Duration.standardMinutes(5);
clock.setTo(Instant.parse("2000-01-01T00:05:00Z"));
action.transactionCooldown = Duration.ofMinutes(5);
action.run();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getPayload()).contains("Launched RDE pipeline: jobid");
@@ -170,43 +170,43 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testManualRun_emptyMode_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.manual = true;
action.directory = Optional.of("test/");
action.modeStrings = ImmutableSet.of();
action.tlds = ImmutableSet.of("lol");
action.watermarks = ImmutableSet.of(clock.nowUtc());
action.watermarks = ImmutableSet.of(clock.now());
assertThrows(BadRequestException.class, action::run);
}
@Test
void testManualRun_invalidMode_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.manual = true;
action.directory = Optional.of("test/");
action.modeStrings = ImmutableSet.of("full", "thing");
action.tlds = ImmutableSet.of("lol");
action.watermarks = ImmutableSet.of(clock.nowUtc());
action.watermarks = ImmutableSet.of(clock.now());
assertThrows(BadRequestException.class, action::run);
}
@Test
void testManualRun_emptyTld_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.manual = true;
action.directory = Optional.of("test/");
action.modeStrings = ImmutableSet.of("full");
action.tlds = ImmutableSet.of();
action.watermarks = ImmutableSet.of(clock.nowUtc());
action.watermarks = ImmutableSet.of(clock.now());
assertThrows(BadRequestException.class, action::run);
}
@Test
void testManualRun_emptyWatermark_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.manual = true;
action.directory = Optional.of("test/");
action.modeStrings = ImmutableSet.of("full");
@@ -218,24 +218,24 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testManualRun_nonDayStartWatermark_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.manual = true;
action.directory = Optional.of("test/");
action.modeStrings = ImmutableSet.of("full");
action.tlds = ImmutableSet.of("lol");
action.watermarks = ImmutableSet.of(DateTime.parse("2001-01-01T01:36:45Z"));
action.watermarks = ImmutableSet.of(Instant.parse("2001-01-01T01:36:45Z"));
assertThrows(BadRequestException.class, action::run);
}
@Test
void testManualRun_invalidRevision_throwsException() {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.manual = true;
action.directory = Optional.of("test/");
action.modeStrings = ImmutableSet.of("full");
action.tlds = ImmutableSet.of("lol");
action.watermarks = ImmutableSet.of(DateTime.parse("2001-01-01T00:00:00Z"));
action.watermarks = ImmutableSet.of(Instant.parse("2001-01-01T00:00:00Z"));
action.revision = Optional.of(-1);
assertThrows(BadRequestException.class, action::run);
}
@@ -243,13 +243,14 @@ public class RdeStagingActionTest extends BeamActionTestBase {
@Test
void testManualRun_validParameters_runsPipeline() throws Exception {
createTldWithEscrowEnabled("lol");
clock.setTo(DateTime.parse("2000-01-01TZ"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
action.manual = true;
action.directory = Optional.of("test/");
action.modeStrings = ImmutableSet.of("full");
action.tlds = ImmutableSet.of("lol");
action.watermarks =
ImmutableSet.of(DateTime.parse("1999-12-31TZ"), DateTime.parse("2001-01-01TZ"));
ImmutableSet.of(
Instant.parse("1999-12-31T00:00:00Z"), Instant.parse("2001-01-01T00:00:00Z"));
action.run();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getPayload()).contains("Launched RDE pipeline: jobid, jobid1");
@@ -26,9 +26,6 @@ import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.GpgSystemCommandExtension.GPG_BINARY;
import static google.registry.testing.SystemInfo.hasCommand;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardHours;
import static org.joda.time.Duration.standardSeconds;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -75,9 +72,10 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.URI;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -137,7 +135,7 @@ public class RdeUploadActionTest {
new FakeKeyringModule().get().getRdeStagingEncryptionKey();
private final FakeResponse response = new FakeResponse();
private final EscrowTaskRunner runner = mock(EscrowTaskRunner.class);
private final FakeClock clock = new FakeClock(DateTime.parse("2010-10-17TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("2010-10-17T00:00:00Z"));
private RdeUploadAction createAction(URI uploadUrl) {
try (Keyring keyring = new FakeKeyringModule().get()) {
@@ -150,13 +148,13 @@ public class RdeUploadActionTest {
"user@ignored",
keyring.getRdeSshClientPrivateKey(),
keyring.getRdeSshClientPublicKey());
action.jschSshSessionFactory = new JSchSshSessionFactory(standardSeconds(3));
action.jschSshSessionFactory = new JSchSshSessionFactory(Duration.ofSeconds(3));
action.response = response;
action.bucket = "bucket";
action.interval = standardDays(1);
action.timeout = standardSeconds(23);
action.interval = Duration.ofDays(1);
action.timeout = Duration.ofSeconds(23);
action.tld = "tld";
action.sftpCooldown = standardSeconds(7);
action.sftpCooldown = Duration.ofSeconds(7);
action.uploadUrl = uploadUrl;
action.receiverKey = keyring.getRdeReceiverKey();
action.signingKey = keyring.getRdeSigningKey();
@@ -198,8 +196,8 @@ public class RdeUploadActionTest {
tm().transact(
() -> {
RdeRevision.saveRevision("lol", DateTime.parse("2010-10-17TZ"), FULL, 0);
RdeRevision.saveRevision("tld", DateTime.parse("2010-10-17TZ"), FULL, 0);
RdeRevision.saveRevision("lol", Instant.parse("2010-10-17T00:00:00Z"), FULL, 0);
RdeRevision.saveRevision("tld", Instant.parse("2010-10-17T00:00:00Z"), FULL, 0);
});
}
@@ -219,7 +217,11 @@ public class RdeUploadActionTest {
action.run();
verify(runner)
.lockRunAndRollForward(
action, Tld.get("lol"), standardSeconds(23), CursorType.RDE_UPLOAD, standardDays(1));
action,
Tld.get("lol"),
Duration.ofSeconds(23),
CursorType.RDE_UPLOAD,
Duration.ofDays(1));
cloudTasksHelper.assertTasksEnqueued(
"rde-report",
new TaskMatcher().path(RdeReportAction.PATH).param(RequestParameters.PARAM_TLD, "lol"));
@@ -235,7 +237,11 @@ public class RdeUploadActionTest {
action.run();
verify(runner)
.lockRunAndRollForward(
action, Tld.get("lol"), standardSeconds(23), CursorType.RDE_UPLOAD, standardDays(1));
action,
Tld.get("lol"),
Duration.ofSeconds(23),
CursorType.RDE_UPLOAD,
Duration.ofDays(1));
cloudTasksHelper.assertTasksEnqueued(
"rde-report",
new TaskMatcher()
@@ -249,15 +255,15 @@ public class RdeUploadActionTest {
void testRunWithLock_succeedsOnThirdTry() throws Exception {
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
RdeUploadAction action = createAction(uploadUrl);
action.lazyJsch = Lazies.of(createThrowingJSchSpy(action.lazyJsch.get(), 2));
action.runWithLock(uploadCursor);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00.000Z\n");
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00Z\n");
cloudTasksHelper.assertNoTasksEnqueued("rde-upload");
assertThat(folder.list())
.asList()
@@ -268,8 +274,8 @@ public class RdeUploadActionTest {
void testRunWithLock_failsAfterThreeAttempts() throws Exception {
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
RdeUploadAction action = createAction(uploadUrl);
action.lazyJsch = Lazies.of(createThrowingJSchSpy(action.lazyJsch.get(), 3));
@@ -282,8 +288,8 @@ public class RdeUploadActionTest {
void testRunWithLock_cannotGuessPrefix() throws Exception {
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
gcsUtils.delete(GHOSTRYDE_FILE_WITH_PREFIX);
gcsUtils.delete(LENGTH_FILE_WITH_PREFIX);
@@ -293,7 +299,7 @@ public class RdeUploadActionTest {
assertThrows(NoContentException.class, () -> action.runWithLock(uploadCursor));
assertThat(thrown)
.hasMessageThat()
.isEqualTo("RDE deposit for TLD tld on 2010-10-17T00:00:00.000Z does not exist");
.isEqualTo("RDE deposit for TLD tld on 2010-10-17T00:00:00Z does not exist");
cloudTasksHelper.assertNoTasksEnqueued("rde-upload");
assertThat(folder.list()).isEmpty();
}
@@ -302,8 +308,8 @@ public class RdeUploadActionTest {
void testRunWithLock_copiesOnGcs_withPrefix() throws Exception {
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
RdeUploadAction action = createAction(uploadUrl);
action.prefix = Optional.of(JOB_PREFIX + "-job-name/");
@@ -313,7 +319,7 @@ public class RdeUploadActionTest {
action.runWithLock(uploadCursor);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00.000Z\n");
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00Z\n");
cloudTasksHelper.assertNoTasksEnqueued("rde-upload");
// Assert that both files are written to SFTP and GCS, and that the contents are identical.
String rydeFilename = "tld_2010-10-17_full_S1_R0.ryde";
@@ -331,8 +337,8 @@ public class RdeUploadActionTest {
void testRunWithLock_copiesOnGcs_withoutPrefix() throws Exception {
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
RdeUploadAction action = createAction(uploadUrl);
gcsUtils.delete(GHOSTRYDE_FILE);
@@ -353,7 +359,7 @@ public class RdeUploadActionTest {
action.runWithLock(uploadCursor);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00.000Z\n");
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00Z\n");
cloudTasksHelper.assertNoTasksEnqueued("rde-upload");
// Assert that both files are written to SFTP and GCS, and that the contents are identical.
String rydeFilename = "tld_2010-10-17_full_S1_R0.ryde";
@@ -369,11 +375,12 @@ public class RdeUploadActionTest {
@Test
void testRunWithLock_resend() throws Exception {
tm().transact(() -> RdeRevision.saveRevision("tld", DateTime.parse("2010-10-17TZ"), FULL, 1));
tm().transact(
() -> RdeRevision.saveRevision("tld", Instant.parse("2010-10-17T00:00:00Z"), FULL, 1));
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
BlobId ghostrydeR1FileWithPrefix =
BlobId.of("bucket", JOB_PREFIX + "-job-name/tld_2010-10-17_full_S1_R1.xml.ghostryde");
@@ -391,7 +398,7 @@ public class RdeUploadActionTest {
createAction(uploadUrl).runWithLock(uploadCursor);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8);
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00.000Z\n");
assertThat(response.getPayload()).isEqualTo("OK tld 2010-10-17T00:00:00Z\n");
cloudTasksHelper.assertNoTasksEnqueued("rde-upload");
assertThat(folder.list())
.asList()
@@ -403,8 +410,8 @@ public class RdeUploadActionTest {
assumeTrue(hasCommand(GPG_BINARY + " --version"));
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
createAction(uploadUrl).runWithLock(uploadCursor);
// Only verify signature for SFTP versions, since we check elsewhere that the GCS files are
@@ -425,15 +432,15 @@ public class RdeUploadActionTest {
void testRunWithLock_nonexistentCursor_throws204() throws Exception {
int port = sftpd.serve("user", "password", folder);
URI uploadUrl = URI.create(String.format("sftp://user:password@localhost:%d/", port));
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
RdeUploadAction action = createAction(uploadUrl);
NoContentException thrown =
assertThrows(NoContentException.class, () -> action.runWithLock(uploadCursor));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Waiting on RdeStagingAction for TLD tld to send 2010-10-17T00:00:00.000Z upload; last"
+ " RDE staging completion was before 1970-01-01T00:00:00.000Z");
"Waiting on RdeStagingAction for TLD tld to send 2010-10-17T00:00:00Z upload; last"
+ " RDE staging completion was before 1970-01-01T00:00:00Z");
cloudTasksHelper.assertNoTasksEnqueued("rde-upload");
assertThat(folder.list()).isEmpty();
}
@@ -441,25 +448,26 @@ public class RdeUploadActionTest {
@Test
void testRunWithLock_stagingNotFinished_throws204() {
URI url = URI.create("sftp://user:password@localhost:32323/");
DateTime stagingCursor = DateTime.parse("2010-10-17TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
Instant stagingCursor = Instant.parse("2010-10-17T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
NoContentException thrown =
assertThrows(NoContentException.class, () -> createAction(url).runWithLock(uploadCursor));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Waiting on RdeStagingAction for TLD tld to send 2010-10-17T00:00:00.000Z upload; "
+ "last RDE staging completion was before 2010-10-17T00:00:00.000Z");
"Waiting on RdeStagingAction for TLD tld to send 2010-10-17T00:00:00Z upload; "
+ "last RDE staging completion was before 2010-10-17T00:00:00Z");
}
@Test
void testRunWithLock_sftpCooldownNotPassed_throws204() {
RdeUploadAction action = createAction(URI.create("sftp://user:password@localhost:32323/"));
action.sftpCooldown = standardHours(2);
DateTime stagingCursor = DateTime.parse("2010-10-18TZ");
DateTime uploadCursor = DateTime.parse("2010-10-17TZ");
DateTime sftpCursor = uploadCursor.minusMinutes(97); // Within the 2-hour cooldown period.
action.sftpCooldown = Duration.ofHours(2);
Instant stagingCursor = Instant.parse("2010-10-18T00:00:00Z");
Instant uploadCursor = Instant.parse("2010-10-17T00:00:00Z");
Instant sftpCursor =
uploadCursor.minus(Duration.ofMinutes(97)); // Within the 2-hour cooldown period.
persistResource(Cursor.createScoped(RDE_STAGING, stagingCursor, Tld.get("tld")));
persistResource(Cursor.createScoped(RDE_UPLOAD_SFTP, sftpCursor, Tld.get("tld")));
NoContentException thrown =
@@ -467,8 +475,8 @@ public class RdeUploadActionTest {
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Waiting on 120 minute SFTP cooldown for TLD tld to send 2010-10-17T00:00:00.000Z"
+ " upload; last upload attempt was at 2010-10-16T22:23:00.000Z (97 minutes"
"Waiting on 120 minute SFTP cooldown for TLD tld to send 2010-10-17T00:00:00Z"
+ " upload; last upload attempt was at 2010-10-16T22:23:00Z (97 minutes"
+ " ago)");
}
@@ -47,7 +47,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
*/
public class RegistrarToXjcConverterTest {
private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2013-01-01T00:00:00Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@@ -88,7 +88,7 @@ public class RegistrarToXjcConverterTest {
.build();
registrar = cloneAndSetAutoTimestamps(registrar); // Set the creation time in 2013.
registrar = registrar.asBuilder().setLastUpdateTime((Instant) null).build();
clock.setTo(DateTime.parse("2014-01-01T00:00:00Z"));
clock.setTo(Instant.parse("2014-01-01T00:00:00Z"));
registrar = cloneAndSetAutoTimestamps(registrar); // Set the update time in 2014.
}
@@ -21,7 +21,7 @@ import com.google.common.io.ByteStreams;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link RydeFileEncoding}. */
@@ -31,7 +31,7 @@ final class RydeFileEncodingTest {
void testEncodeDecode() throws Exception {
byte[] expectedContent = "Testing 1, 2, 3".getBytes(UTF_8);
String expectedFilename = "myFile.txt";
DateTime expectedModified = DateTime.parse("2015-12-25T06:30:00.000Z");
Instant expectedModified = Instant.parse("2015-12-25T06:30:00.000Z");
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (OutputStream encoder =
@@ -35,10 +35,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.time.Instant;
import java.util.stream.Stream;
import org.bouncycastle.openpgp.PGPKeyPair;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -82,7 +82,7 @@ public class RydeGpgIntegrationTest {
Keyring keyring = keyringFactory.get();
PGPKeyPair signingKey = keyring.getRdeSigningKey();
PGPPublicKey receiverKey = keyring.getRdeReceiverKey();
DateTime modified = DateTime.parse("1984-01-01T00:00:00Z");
Instant modified = Instant.parse("1984-01-01T00:00:00Z");
File home = gpg.getCwd();
File rydeFile = new File(home, filename + ".ryde");
File sigFile = new File(home, filename + ".sig");
@@ -21,7 +21,7 @@ import com.google.common.io.ByteStreams;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link RydeTar}. */
@@ -31,7 +31,7 @@ final class RydeTarTest {
void testWriteRead() throws Exception {
byte[] expectedContent = "Testing 1, 2, 3".getBytes(UTF_8);
String expectedFilename = "myFile.xml";
DateTime expectedModified = DateTime.parse("2015-12-25T06:30:00.000Z");
Instant expectedModified = Instant.parse("2015-12-25T06:30:00.000Z");
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (OutputStream writer =
@@ -23,10 +23,10 @@ import google.registry.request.HttpException.BadRequestException;
import google.registry.testing.FakeClock;
import google.registry.util.Clock;
import jakarta.servlet.http.HttpServletRequest;
import java.time.Instant;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.Optional;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.YearMonth;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -38,7 +38,7 @@ class ReportingModuleTest {
@BeforeEach
void beforeEach() {
clock = new FakeClock(DateTime.parse("2017-07-01TZ"));
clock = new FakeClock(Instant.parse("2017-07-01T00:00:00Z"));
}
@Test
@@ -50,7 +50,7 @@ class ReportingModuleTest {
@Test
void testValidYearMonthParameter_returnsThatMonth() {
when(req.getParameter("yearMonth")).thenReturn("2017-05");
assertThat(ReportingModule.provideYearMonthOptional(req)).hasValue(new YearMonth(2017, 5));
assertThat(ReportingModule.provideYearMonthOptional(req)).hasValue(YearMonth.of(2017, 5));
}
@Test
@@ -66,16 +66,16 @@ class ReportingModuleTest {
@Test
void testEmptyYearMonth_returnsLastMonth() {
assertThat(ReportingModule.provideYearMonth(Optional.empty(), new LocalDate(2017, 1, 6)))
.isEqualTo(new YearMonth(2016, 12));
assertThat(ReportingModule.provideYearMonth(Optional.empty(), LocalDate.of(2017, 1, 6)))
.isEqualTo(YearMonth.of(2016, 12));
}
@Test
void testGivenYearMonth_returnsThatMonth() {
assertThat(
ReportingModule.provideYearMonth(
Optional.of(new YearMonth(2017, 5)), new LocalDate(2017, 7, 6)))
.isEqualTo(new YearMonth(2017, 5));
Optional.of(YearMonth.of(2017, 5)), LocalDate.of(2017, 7, 6)))
.isEqualTo(YearMonth.of(2017, 5));
}
@Test
@@ -87,7 +87,7 @@ class ReportingModuleTest {
@Test
void testValidDateParameter_returnsThatDate() {
when(req.getParameter("date")).thenReturn("2017-05-13");
assertThat(ReportingModule.provideDateOptional(req)).hasValue(new LocalDate(2017, 5, 13));
assertThat(ReportingModule.provideDateOptional(req)).hasValue(LocalDate.of(2017, 5, 13));
}
@Test
@@ -103,13 +103,13 @@ class ReportingModuleTest {
@Test
void testEmptyDate_returnsToday() {
when(req.getParameter("date")).thenReturn(null);
assertThat(ReportingModule.provideDate(req, clock)).isEqualTo(new LocalDate(2017, 7, 1));
assertThat(ReportingModule.provideDate(req, clock)).isEqualTo(LocalDate.of(2017, 7, 1));
}
@Test
void testGivenDate_returnsThatDate() {
when(req.getParameter("date")).thenReturn("2017-07-02");
assertThat(ReportingModule.provideDate(req, clock)).isEqualTo(new LocalDate(2017, 7, 2));
assertThat(ReportingModule.provideDate(req, clock)).isEqualTo(LocalDate.of(2017, 7, 2));
}
@Test
@@ -28,8 +28,8 @@ import google.registry.groups.GmailClient;
import google.registry.util.EmailMessage;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress;
import java.time.YearMonth;
import java.util.Optional;
import org.joda.time.YearMonth;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -54,7 +54,7 @@ class BillingEmailUtilsTest {
throws Exception {
return new BillingEmailUtils(
gmailClient,
new YearMonth(2017, 10),
YearMonth.of(2017, 10),
new InternetAddress("my-receiver@test.com"),
ImmutableList.of(
new InternetAddress("hello@world.com"), new InternetAddress("hola@mundo.com")),
@@ -32,8 +32,7 @@ import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeClock;
import java.io.IOException;
import org.joda.time.Duration;
import org.joda.time.YearMonth;
import java.time.YearMonth;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -60,7 +59,7 @@ class GenerateInvoicesActionTest extends BeamActionTestBase {
"billing_bucket",
"REG-INV",
true,
new YearMonth(2017, 10),
YearMonth.of(2017, 10),
emailUtils,
cloudTasksUtils,
clock,
@@ -78,10 +77,7 @@ class GenerateInvoicesActionTest extends BeamActionTestBase {
.method(HttpMethod.POST)
.param("jobId", "jobid")
.param("yearMonth", "2017-10")
.scheduleTime(
clock
.nowUtc()
.plus(Duration.standardMinutes(ReportingModule.ENQUEUE_DELAY_MINUTES))));
.scheduleTime(clock.nowUtc().plusMinutes(ReportingModule.ENQUEUE_DELAY_MINUTES)));
}
@Test
@@ -94,7 +90,7 @@ class GenerateInvoicesActionTest extends BeamActionTestBase {
"billing_bucket",
"REG-INV",
false,
new YearMonth(2017, 10),
YearMonth.of(2017, 10),
emailUtils,
cloudTasksUtils,
clock,
@@ -118,7 +114,7 @@ class GenerateInvoicesActionTest extends BeamActionTestBase {
"billing_bucket",
"REG-INV",
false,
new YearMonth(2017, 10),
YearMonth.of(2017, 10),
emailUtils,
cloudTasksUtils,
clock,
@@ -36,7 +36,7 @@ import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeResponse;
import java.io.IOException;
import org.joda.time.YearMonth;
import java.time.YearMonth;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -71,7 +71,7 @@ class PublishInvoicesActionTest {
emailUtils,
dataflow,
response,
new YearMonth(2017, 10),
YearMonth.of(2017, 10),
cloudTasksUtils);
}
@@ -18,13 +18,13 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.joda.time.YearMonth;
import java.time.YearMonth;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ActivityReportingQueryBuilder}. */
class ActivityReportingQueryBuilderTest {
private final YearMonth yearMonth = new YearMonth(2017, 9);
private final YearMonth yearMonth = YearMonth.of(2017, 9);
@SuppressWarnings("NonCanonicalType")
private ActivityReportingQueryBuilder createQueryBuilder(String datasetName) {
@@ -15,7 +15,7 @@ package google.registry.reporting.icann;
import static com.google.common.truth.Truth.assertThat;
import org.joda.time.YearMonth;
import java.time.YearMonth;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
public class CloudDnsCountQueryCoordinatorTest {
public CloudDnsCountQueryCoordinatorTest() {}
private final YearMonth yearMonth = new YearMonth(2017, 9);
private final YearMonth yearMonth = YearMonth.of(2017, 9);
CloudDnsCountQueryCoordinator coordinator = new CloudDnsCountQueryCoordinator();
@BeforeEach
@@ -33,19 +33,19 @@ import google.registry.gcs.GcsUtils;
import google.registry.reporting.icann.IcannReportingModule.ReportType;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import java.time.Instant;
import java.time.YearMonth;
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 final FakeClock clock = new FakeClock(Instant.parse("2026-01-26T21:06:12.284Z"));
private BigqueryConnection bigquery = mock(BigqueryConnection.class);
FakeResponse response = new FakeResponse();
private YearMonth yearMonth = new YearMonth(2017, 6);
private YearMonth yearMonth = YearMonth.of(2017, 6);
private String subdir = "icann/monthly/2017-06";
private GcsUtils gcsUtils = new GcsUtils(LocalStorageHelper.getOptions());
@@ -37,10 +37,9 @@ import google.registry.testing.FakeSleeper;
import google.registry.util.EmailMessage;
import google.registry.util.Retrier;
import jakarta.mail.internet.InternetAddress;
import java.time.Instant;
import java.time.YearMonth;
import java.util.Optional;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.YearMonth;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -49,10 +48,10 @@ class IcannReportingStagingActionTest {
private FakeResponse response = new FakeResponse();
private IcannReportingStager stager = mock(IcannReportingStager.class);
private YearMonth yearMonth = new YearMonth(2017, 6);
private YearMonth yearMonth = YearMonth.of(2017, 6);
private String subdir = "default/dir";
private IcannReportingStagingAction action;
private FakeClock clock = new FakeClock(DateTime.parse("2021-01-02T11:00:00Z"));
private FakeClock clock = new FakeClock(Instant.parse("2021-01-02T11:00:00Z"));
private CloudTasksHelper cloudTasksHelper = new CloudTasksHelper(clock);
@BeforeEach
@@ -82,7 +81,7 @@ class IcannReportingStagingActionTest {
new TaskMatcher()
.path("/_dr/task/icannReportingUpload")
.method(HttpMethod.POST)
.scheduleTime(clock.nowUtc().plus(Duration.standardMinutes(2))));
.scheduleTime(clock.nowUtc().plusMinutes(2)));
}
@Test
@@ -187,20 +186,20 @@ class IcannReportingStagingActionTest {
@Test
void testEmptySubDir_returnsDefaultSubdir() {
action.overrideSubdir = Optional.empty();
assertThat(action.getSubdir(new YearMonth(2017, 6))).isEqualTo("icann/monthly/2017-06");
assertThat(action.getSubdir(YearMonth.of(2017, 6))).isEqualTo("icann/monthly/2017-06");
}
@Test
void testGivenSubdir_returnsManualSubdir() {
action.overrideSubdir = Optional.of("manual/dir");
assertThat(action.getSubdir(new YearMonth(2017, 6))).isEqualTo("manual/dir");
assertThat(action.getSubdir(YearMonth.of(2017, 6))).isEqualTo("manual/dir");
}
@Test
void testInvalidSubdir_throwsException() {
action.overrideSubdir = Optional.of("/whoops");
BadRequestException thrown =
assertThrows(BadRequestException.class, () -> action.getSubdir(new YearMonth(2017, 6)));
assertThrows(BadRequestException.class, () -> action.getSubdir(YearMonth.of(2017, 6)));
assertThat(thrown)
.hasMessageThat()
.contains("subdir must not start or end with a \"/\", got /whoops instead.");
@@ -46,9 +46,9 @@ import google.registry.util.EmailMessage;
import google.registry.util.Retrier;
import jakarta.mail.internet.InternetAddress;
import java.io.IOException;
import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -69,7 +69,7 @@ class IcannReportingUploadActionTest {
private final TestLogHandler logHandler = new TestLogHandler();
private final Logger loggerToIntercept =
Logger.getLogger(IcannReportingUploadAction.class.getCanonicalName());
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("2000-01-01T00:00:00Z"));
private IcannReportingUploadAction createAction() throws Exception {
IcannReportingUploadAction action = new IcannReportingUploadAction();
@@ -100,19 +100,23 @@ class IcannReportingUploadActionTest {
when(mockReporter.send(PAYLOAD_SUCCESS, "foo-transactions-200606.csv")).thenReturn(true);
when(mockReporter.send(PAYLOAD_FAIL, "tld-activity-200606.csv")).thenReturn(false);
when(mockReporter.send(PAYLOAD_SUCCESS, "foo-activity-200606.csv")).thenReturn(true);
clock.setTo(DateTime.parse("2006-07-05T00:30:00Z"));
clock.setTo(Instant.parse("2006-07-05T00:30:00Z"));
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_ACTIVITY, DateTime.parse("2006-07-01TZ"), Tld.get("tld")));
CursorType.ICANN_UPLOAD_ACTIVITY,
Instant.parse("2006-07-01T00:00:00Z"),
Tld.get("tld")));
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_TX, DateTime.parse("2006-07-01TZ"), Tld.get("tld")));
CursorType.ICANN_UPLOAD_TX, Instant.parse("2006-07-01T00:00:00Z"), Tld.get("tld")));
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_ACTIVITY, DateTime.parse("2006-07-01TZ"), Tld.get("foo")));
CursorType.ICANN_UPLOAD_ACTIVITY,
Instant.parse("2006-07-01T00:00:00Z"),
Tld.get("foo")));
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_TX, DateTime.parse("2006-07-01TZ"), Tld.get("foo")));
CursorType.ICANN_UPLOAD_TX, Instant.parse("2006-07-01T00:00:00Z"), Tld.get("foo")));
loggerToIntercept.addHandler(logHandler);
}
@@ -131,23 +135,26 @@ class IcannReportingUploadActionTest {
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
"""
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS""",
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS\
""",
new InternetAddress("recipient@example.com")));
}
@Test
void testSuccess_january() throws Exception {
clock.setTo(DateTime.parse("2006-01-22T00:30:00Z"));
clock.setTo(Instant.parse("2006-01-22T00:30:00Z"));
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_ACTIVITY, DateTime.parse("2006-01-01TZ"), Tld.get("tld")));
CursorType.ICANN_UPLOAD_ACTIVITY,
Instant.parse("2006-01-01T00:00:00Z"),
Tld.get("tld")));
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_TX, DateTime.parse("2006-01-01TZ"), Tld.get("tld")));
CursorType.ICANN_UPLOAD_TX, Instant.parse("2006-01-01T00:00:00Z"), Tld.get("tld")));
gcsUtils.createFromBytes(
BlobId.of("basin", "icann/monthly/2005-12/tld-transactions-200512.csv"), PAYLOAD_SUCCESS);
gcsUtils.createFromBytes(
@@ -166,9 +173,10 @@ class IcannReportingUploadActionTest {
EmailMessage.create(
"ICANN Monthly report upload summary: 2/2 succeeded",
"""
Report Filename - Upload status:
tld-activity-200512.csv - SUCCESS
tld-transactions-200512.csv - SUCCESS""",
Report Filename - Upload status:
tld-activity-200512.csv - SUCCESS
tld-transactions-200512.csv - SUCCESS\
""",
new InternetAddress("recipient@example.com")));
}
@@ -181,12 +189,12 @@ class IcannReportingUploadActionTest {
action.run();
Cursor cursor =
loadByKey(Cursor.createScopedVKey(CursorType.ICANN_UPLOAD_ACTIVITY, Tld.get("tld")));
assertThat(cursor.getCursorTime()).isEqualTo(DateTime.parse("2006-08-02T10:00:00Z"));
assertThat(cursor.getCursorTime()).isEqualTo(Instant.parse("2006-08-02T10:00:00Z"));
}
@Test
void testSuccess_noUploadsNeeded() throws Exception {
clock.setTo(DateTime.parse("2006-5-01T00:30:00Z"));
clock.setTo(Instant.parse("2006-05-01T00:30:00Z"));
IcannReportingUploadAction action = createAction();
action.run();
verifyNoMoreInteractions(mockReporter);
@@ -210,11 +218,12 @@ class IcannReportingUploadActionTest {
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
"""
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS""",
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS\
""",
new InternetAddress("recipient@example.com")));
}
@@ -238,17 +247,17 @@ class IcannReportingUploadActionTest {
new IOException("Your IP address 25.147.130.158 is not allowed to connect"));
Cursor cursor =
loadByKey(Cursor.createScopedVKey(CursorType.ICANN_UPLOAD_ACTIVITY, Tld.get("tld")));
assertThat(cursor.getCursorTime()).isEqualTo(DateTime.parse("2006-07-01TZ"));
assertThat(cursor.getCursorTime()).isEqualTo(Instant.parse("2006-07-01T00:00:00Z"));
}
@Test
void testNotRunIfCursorDateIsAfterToday() throws Exception {
clock.setTo(DateTime.parse("2006-05-01T00:30:00Z"));
clock.setTo(Instant.parse("2006-05-01T00:30:00Z"));
IcannReportingUploadAction action = createAction();
action.run();
Cursor cursor =
loadByKey(Cursor.createScopedVKey(CursorType.ICANN_UPLOAD_ACTIVITY, Tld.get("foo")));
assertThat(cursor.getCursorTime()).isEqualTo(DateTime.parse("2006-07-01TZ"));
assertThat(cursor.getCursorTime()).isEqualTo(Instant.parse("2006-07-01T00:00:00Z"));
verifyNoMoreInteractions(mockReporter);
}
@@ -270,20 +279,23 @@ class IcannReportingUploadActionTest {
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
"""
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS""",
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS\
""",
new InternetAddress("recipient@example.com")));
}
@Test
void testFail_fileNotFound() throws Exception {
clock.setTo(DateTime.parse("2006-01-22T00:30:00Z"));
clock.setTo(Instant.parse("2006-01-22T00:30:00Z"));
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_ACTIVITY, DateTime.parse("2006-01-01TZ"), Tld.get("tld")));
CursorType.ICANN_UPLOAD_ACTIVITY,
Instant.parse("2006-01-01T00:00:00Z"),
Tld.get("tld")));
IcannReportingUploadAction action = createAction();
action.run();
assertAboutLogs()
@@ -299,8 +311,10 @@ class IcannReportingUploadActionTest {
void testWarning_fileNotStagedYet() throws Exception {
persistResource(
Cursor.createScoped(
CursorType.ICANN_UPLOAD_ACTIVITY, DateTime.parse("2006-08-01TZ"), Tld.get("foo")));
clock.setTo(DateTime.parse("2006-08-01T00:30:00Z"));
CursorType.ICANN_UPLOAD_ACTIVITY,
Instant.parse("2006-08-01T00:00:00Z"),
Tld.get("foo")));
clock.setTo(Instant.parse("2006-08-01T00:30:00Z"));
IcannReportingUploadAction action = createAction();
action.run();
assertAboutLogs()
@@ -340,19 +354,20 @@ class IcannReportingUploadActionTest {
EmailMessage.create(
"ICANN Monthly report upload summary: 3/4 succeeded",
"""
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS""",
Report Filename - Upload status:
foo-activity-200606.csv - SUCCESS
foo-transactions-200606.csv - SUCCESS
tld-activity-200606.csv - FAILURE
tld-transactions-200606.csv - SUCCESS\
""",
new InternetAddress("recipient@example.com")));
Cursor newActivityCursor =
loadByKey(Cursor.createScopedVKey(CursorType.ICANN_UPLOAD_ACTIVITY, Tld.get("new")));
assertThat(newActivityCursor.getCursorTime()).isEqualTo(DateTime.parse("2006-08-02T10:00:00Z"));
assertThat(newActivityCursor.getCursorTime()).isEqualTo(Instant.parse("2006-08-02T10:00:00Z"));
Cursor newTransactionCursor =
loadByKey(Cursor.createScopedVKey(CursorType.ICANN_UPLOAD_TX, Tld.get("new")));
assertThat(newTransactionCursor.getCursorTime())
.isEqualTo(DateTime.parse("2006-08-02T10:00:00Z"));
.isEqualTo(Instant.parse("2006-08-02T10:00:00Z"));
}
}
@@ -19,13 +19,13 @@ import static com.google.common.truth.Truth.assertWithMessage;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.joda.time.YearMonth;
import java.time.YearMonth;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ActivityReportingQueryBuilder}. */
class TransactionsReportingQueryBuilderTest {
private final YearMonth yearMonth = new YearMonth(2017, 9);
private final YearMonth yearMonth = YearMonth.of(2017, 9);
private TransactionsReportingQueryBuilder createQueryBuilder(String datasetName) {
return new TransactionsReportingQueryBuilder("domain-registry-alpha", datasetName);
@@ -16,6 +16,7 @@ package google.registry.reporting.spec11;
import static com.google.common.truth.Truth.assertThat;
import static jakarta.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static java.time.ZoneOffset.UTC;
import static org.apache.http.HttpStatus.SC_OK;
import static org.mockito.Mockito.when;
@@ -28,14 +29,13 @@ import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeClock;
import java.io.IOException;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GenerateSpec11ReportAction}. */
class GenerateSpec11ReportActionTest extends BeamActionTestBase {
private final FakeClock clock = new FakeClock(DateTime.parse("2018-06-11T12:23:56Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2018-06-11T12:23:56Z"));
private CloudTasksHelper cloudTasksHelper = new CloudTasksHelper(clock);
private CloudTasksUtils cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils();
private GenerateSpec11ReportAction action;
@@ -49,7 +49,7 @@ class GenerateSpec11ReportActionTest extends BeamActionTestBase {
"gs://staging-project/staging-bucket/",
"gs://reporting-project/reporting-bucket/",
"api_key/a",
clock.nowUtc().toLocalDate(),
clock.now().atZone(UTC).toLocalDate(),
true,
clock,
response,
@@ -72,7 +72,7 @@ class GenerateSpec11ReportActionTest extends BeamActionTestBase {
"gs://staging-project/staging-bucket/",
"gs://reporting-project/reporting-bucket/",
"api_key/a",
clock.nowUtc().toLocalDate(),
clock.now().atZone(UTC).toLocalDate(),
true,
clock,
response,
@@ -90,10 +90,7 @@ class GenerateSpec11ReportActionTest extends BeamActionTestBase {
.method(HttpMethod.POST)
.param("jobId", "jobid")
.param("date", "2018-06-11")
.scheduleTime(
clock
.nowUtc()
.plus(Duration.standardMinutes(ReportingModule.ENQUEUE_DELAY_MINUTES))));
.scheduleTime(clock.nowUtc().plusMinutes(ReportingModule.ENQUEUE_DELAY_MINUTES)));
}
@Test
@@ -105,7 +102,7 @@ class GenerateSpec11ReportActionTest extends BeamActionTestBase {
"gs://staging-project/staging-bucket/",
"gs://reporting-project/reporting-bucket/",
"api_key/a",
clock.nowUtc().toLocalDate(),
clock.now().atZone(UTC).toLocalDate(),
false,
clock,
response,
@@ -40,15 +40,15 @@ import google.registry.beam.spec11.ThreatMatch;
import google.registry.reporting.spec11.soy.Spec11EmailSoyInfo;
import google.registry.testing.FakeResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.util.Optional;
import org.joda.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link PublishSpec11ReportAction}. */
class PublishSpec11ReportActionTest {
private final LocalDate date = new LocalDate(2018, 6, 5);
private final LocalDate date = LocalDate.of(2018, 6, 5);
private Dataflow dataflow;
private Projects projects;
@@ -27,7 +27,6 @@ import static google.registry.testing.DatabaseHelper.persistActiveHost;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -46,11 +45,11 @@ import google.registry.util.EmailMessage;
import google.registry.util.Sleeper;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress;
import java.time.Duration;
import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import org.joda.time.Duration;
import org.joda.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -106,10 +105,10 @@ class Spec11EmailUtilsTest {
@Mock private GmailClient gmailClient;
@Mock private Sleeper sleeper;
private Duration emailThrottleDuration = Duration.millis(1);
private Duration emailThrottleDuration = Duration.ofMillis(1);
private Spec11EmailUtils emailUtils;
private ArgumentCaptor<EmailMessage> contentCaptor;
private final LocalDate date = new LocalDate(2018, 7, 15);
private final LocalDate date = LocalDate.of(2018, 7, 15);
private Domain aDomain;
private Domain bDomain;
@@ -146,7 +145,7 @@ class Spec11EmailUtilsTest {
// We inspect individual parameters because Message doesn't implement equals().
verify(gmailClient, times(3)).sendEmail(any(EmailMessage.class));
// Sleep once between two reports sent in a tight loop. No sleep before the final alert message.
verify(sleeper, times(1)).sleep(same(emailThrottleDuration));
verify(sleeper, times(1)).sleepInterruptibly(emailThrottleDuration);
}
@Test
@@ -27,7 +27,7 @@ import google.registry.gcs.GcsUtils;
import google.registry.testing.TestDataHelper;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import org.joda.time.LocalDate;
import java.time.LocalDate;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -22,20 +22,20 @@ import static org.mockito.Mockito.verify;
import google.registry.model.server.Lock;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link LockHandler}. */
final class LockHandlerImplTest {
private static final Duration ONE_DAY = Duration.standardDays(1);
private static final Duration ONE_DAY = Duration.ofDays(1);
private final FakeClock clock = new FakeClock(DateTime.parse("2001-08-29T12:20:00Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2001-08-29T12:20:00Z"));
private static class CountingCallable implements Callable<Void> {
int numCalled;
@@ -58,7 +58,7 @@ final class LockHandlerImplTest {
@Override
public Void call() throws Exception {
clock.advanceBy(Duration.standardSeconds(77));
clock.advanceBy(Duration.ofSeconds(77));
throw exception;
}
}
@@ -102,7 +102,7 @@ final class LockHandlerImplTest {
.hasMessageThat()
.isEqualTo(
"Execution on locks 'resourceName' for TLD 'tld'"
+ " timed out after PT77S; started at 2001-08-29T12:20:00.000Z");
+ " timed out after PT1M17S; started at 2001-08-29T12:20:00Z");
verify(lock, times(1)).release();
}
@@ -53,6 +53,7 @@ import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -356,6 +357,10 @@ public class CloudTasksHelper implements Serializable {
return this;
}
public TaskMatcher scheduleTime(Instant scheduleTime) {
return scheduleTime(Timestamps.fromMillis(scheduleTime.toEpochMilli()));
}
public TaskMatcher scheduleTime(DateTime scheduleTime) {
return scheduleTime(Timestamps.fromMillis(scheduleTime.getMillis()));
}
@@ -47,6 +47,7 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static google.registry.util.ResourceUtils.readResourceUtf8;
import static java.util.Arrays.asList;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Ascii;
import com.google.common.base.Splitter;
@@ -117,7 +118,6 @@ import javax.annotation.Nullable;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
/** Static utils for setting up test resources. */
@@ -321,7 +321,7 @@ public final class DatabaseHelper {
new ReservedList.Builder()
.setName(listName)
.setReservedListMapFromLines(ImmutableList.copyOf(lines))
.setCreationTimestamp(DateTime.now(DateTimeZone.UTC))
.setCreationTimestamp(DateTime.now(UTC))
.build();
return persistReservedList(reservedList);
}
@@ -342,7 +342,7 @@ public final class DatabaseHelper {
PremiumList premiumList =
partialPremiumList
.asBuilder()
.setCreationTimestamp(DateTime.now(DateTimeZone.UTC))
.setCreationTimestamp(DateTime.now(UTC))
.setCurrency(currencyUnit)
.setLabelsToPrices(
entries.entrySet().stream()
@@ -1299,8 +1299,7 @@ public final class DatabaseHelper {
assertNoDnsRequestsExcept();
}
public static void assertDomainDnsRequestWithRequestTime(
String domainName, DateTime requestTime) {
public static void assertDomainDnsRequestWithRequestTime(String domainName, Instant requestTime) {
assertThat(
tm().transact(
() ->
@@ -1312,7 +1311,7 @@ public final class DatabaseHelper {
.isEqualTo(1);
}
public static void assertDnsRequestsWithRequestTime(DateTime requestTime, int numOfDomains) {
public static void assertDnsRequestsWithRequestTime(Instant requestTime, int numOfDomains) {
assertThat(
tm().transact(
() ->
@@ -17,9 +17,9 @@ package google.registry.testing;
import static com.google.common.base.Throwables.throwIfUnchecked;
import google.registry.request.lock.LockHandler;
import java.time.Duration;
import java.util.concurrent.Callable;
import javax.annotation.Nullable;
import org.joda.time.Duration;
/** A fake {@link LockHandler} where user can control if lock acquisition succeeds. */
public class FakeLockHandler implements LockHandler {
@@ -19,8 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
import google.registry.tmch.LordnLog.Result;
import java.time.Instant;
import java.util.Map.Entry;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link LordnLog}. */
@@ -28,16 +28,20 @@ class LordnLogTest {
private static final ImmutableList<String> EXAMPLE_FROM_RFC =
ImmutableList.of(
"1,2012-08-16T02:15:00.0Z,2012-08-16T00:00:00.0Z,"
+ "0000000000000478Nzs+3VMkR8ckuUynOLmyeqTmZQSbzDuf/R50n2n5QX4=,"
+ "accepted,no-warnings,1",
"""
1,2012-08-16T02:15:00.0Z,2012-08-16T00:00:00.0Z,\
0000000000000478Nzs+3VMkR8ckuUynOLmyeqTmZQSbzDuf/R50n2n5QX4=,\
accepted,no-warnings,1\
""",
"roid,result-code",
"SH8013-REP,2000");
private static final ImmutableList<String> EXAMPLE_WITH_WARNINGS =
ImmutableList.of(
"1,2014-03-21T15:40:08.4Z,2014-03-21T15:35:28.0Z,"
+ "0000000000000004799,accepted,warnings-present,2",
"""
1,2014-03-21T15:40:08.4Z,2014-03-21T15:35:28.0Z,\
0000000000000004799,accepted,warnings-present,2\
""",
"roid,result-code",
"19dc9b4-roid,3610",
"1580e26-roid,3610");
@@ -46,8 +50,8 @@ class LordnLogTest {
void testSuccess_parseFirstLine() {
LordnLog log = LordnLog.parse(EXAMPLE_FROM_RFC);
assertThat(log.getStatus()).isEqualTo(LordnLog.Status.ACCEPTED);
assertThat(log.getLogCreation()).isEqualTo(DateTime.parse("2012-08-16T02:15:00.0Z"));
assertThat(log.getLordnCreation()).isEqualTo(DateTime.parse("2012-08-16T00:00:00.0Z"));
assertThat(log.getLogCreation()).isEqualTo(Instant.parse("2012-08-16T02:15:00.0Z"));
assertThat(log.getLordnCreation()).isEqualTo(Instant.parse("2012-08-16T00:00:00.0Z"));
assertThat(log.getLogId())
.isEqualTo("0000000000000478Nzs+3VMkR8ckuUynOLmyeqTmZQSbzDuf/R50n2n5QX4=");
assertThat(log.hasWarnings()).isFalse();
@@ -113,19 +117,16 @@ class LordnLogTest {
@Test
void testSuccess_toString() {
assertThat(LordnLog.parse(EXAMPLE_WITH_WARNINGS).toString()).isEqualTo(
"LordnLog{"
+ "logId=0000000000000004799, "
+ "status=ACCEPTED, "
+ "logCreation=2014-03-21T15:40:08.400Z, "
+ "lordnCreation=2014-03-21T15:35:28.000Z, "
+ "hasWarnings=true, "
+ "results={"
+ "19dc9b4-roid=Result{code=3610, outcome=WARNING, "
+ "description=DN reported outside of the time window}, "
+ "1580e26-roid=Result{code=3610, outcome=WARNING, "
+ "description=DN reported outside of the time window}"
+ "}}");
assertThat(LordnLog.parse(EXAMPLE_WITH_WARNINGS).toString())
.isEqualTo(
"""
LordnLog{logId=0000000000000004799, status=ACCEPTED, \
logCreation=2014-03-21T15:40:08.400Z, lordnCreation=2014-03-21T15:35:28Z, \
hasWarnings=true, results={19dc9b4-roid=Result{code=3610, outcome=WARNING, \
description=DN reported outside of the time window}, \
1580e26-roid=Result{code=3610, outcome=WARNING, \
description=DN reported outside of the time window}}}\
""");
}
@Test
@@ -139,8 +140,8 @@ class LordnLogTest {
void testSuccess_withWarnings() {
LordnLog log = LordnLog.parse(EXAMPLE_WITH_WARNINGS);
assertThat(log.getStatus()).isEqualTo(LordnLog.Status.ACCEPTED);
assertThat(log.getLogCreation()).isEqualTo(DateTime.parse("2014-03-21T15:40:08.4Z"));
assertThat(log.getLordnCreation()).isEqualTo(DateTime.parse("2014-03-21T15:35:28.0Z"));
assertThat(log.getLogCreation()).isEqualTo(Instant.parse("2014-03-21T15:40:08.4Z"));
assertThat(log.getLordnCreation()).isEqualTo(Instant.parse("2014-03-21T15:35:28.0Z"));
assertThat(log.getLogId()).isEqualTo("0000000000000004799");
assertThat(log.hasWarnings()).isTrue();
@@ -59,9 +59,9 @@ import java.io.ByteArrayOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.SecureRandom;
import java.time.Duration;
import java.time.Instant;
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.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -87,7 +87,7 @@ class NordnUploadActionTest {
private static final String LOCATION_URL = "http://trololol";
private final FakeClock clock = new FakeClock(DateTime.parse("2010-05-01T10:11:12.000Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2010-05-01T10:11:12.000Z"));
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper(clock);
private final CloudTasksUtils cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils();
@@ -118,7 +118,7 @@ class NordnUploadActionTest {
createTld("tld");
persistResource(Tld.get("tld").asBuilder().setLordnUsername("lolcat").build());
persistSunriseModeDomain();
clock.advanceBy(Duration.standardDays(1));
clock.advanceBy(Duration.ofDays(1));
persistClaimsModeDomain();
action.clock = clock;
action.cloudTasksUtils = cloudTasksUtils;
@@ -141,13 +141,13 @@ class NordnUploadActionTest {
@Test
void testSuccess_nothingScheduled() {
persistResource(
ForeignKeyUtils.loadResource(Domain.class, "claims-landrush1.tld", clock.nowUtc())
ForeignKeyUtils.loadResource(Domain.class, "claims-landrush1.tld", clock.now())
.get()
.asBuilder()
.setLordnPhase(LordnPhase.NONE)
.build());
persistResource(
ForeignKeyUtils.loadResource(Domain.class, "claims-landrush2.tld", clock.nowUtc())
ForeignKeyUtils.loadResource(Domain.class, "claims-landrush2.tld", clock.now())
.get()
.asBuilder()
.setLordnPhase(LordnPhase.NONE)
@@ -203,7 +203,7 @@ class NordnUploadActionTest {
LaunchNotice.create("landrush2tcn", null, null, minusHours(clock.now(), 2)))
.setLordnPhase(LordnPhase.CLAIMS)
.build());
clock.advanceBy(Duration.standardDays(1));
clock.advanceBy(Duration.ofDays(1));
persistResource(
newDomain("claims-landrush1.tld")
.asBuilder()
@@ -223,7 +223,7 @@ class NordnUploadActionTest {
.setSmdId("new-smdid")
.setLordnPhase(LordnPhase.SUNRISE)
.build());
clock.advanceBy(Duration.standardDays(1));
clock.advanceBy(Duration.ofDays(1));
persistResource(
newDomain("sunrise1.tld")
.asBuilder()
@@ -234,7 +234,7 @@ class NordnUploadActionTest {
}
private void verifyColumnCleared(String domainName) {
Domain domain = ForeignKeyUtils.loadResource(Domain.class, domainName, clock.nowUtc()).get();
Domain domain = ForeignKeyUtils.loadResource(Domain.class, domainName, clock.now()).get();
assertThat(domain.getLordnPhase()).isEqualTo(LordnPhase.NONE);
}
@@ -30,7 +30,7 @@ import java.security.SignatureException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.CertificateRevokedException;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -51,13 +51,13 @@ class TmchCertificateAuthorityTest {
public final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
private final FakeClock clock = new FakeClock(DateTime.parse("2022-11-20T00:00:00Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2022-11-20T00:00:00Z"));
@Test
void testFailure_prodRootExpired() {
TmchCertificateAuthority tmchCertificateAuthority =
new TmchCertificateAuthority(PRODUCTION, clock);
clock.setTo(DateTime.parse("2500-01-01T00:00:00Z"));
clock.setTo(Instant.parse("2500-01-01T00:00:00Z"));
CertificateExpiredException e =
assertThrows(
CertificateExpiredException.class, tmchCertificateAuthority::getAndValidateRoot);
@@ -68,7 +68,7 @@ class TmchCertificateAuthorityTest {
void testFailure_prodRootNotYetValid() {
TmchCertificateAuthority tmchCertificateAuthority =
new TmchCertificateAuthority(PRODUCTION, clock);
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
clock.setTo(Instant.parse("2000-01-01T00:00:00Z"));
CertificateNotYetValidException e =
assertThrows(
CertificateNotYetValidException.class, tmchCertificateAuthority::getAndValidateRoot);
@@ -28,7 +28,7 @@ import java.net.URL;
import java.security.SignatureException;
import java.security.cert.CRLException;
import java.security.cert.CertificateNotYetValidException;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -45,7 +45,7 @@ class TmchCrlActionTest extends TmchActionTestCase {
@BeforeEach
void before() {
clock.setTo(DateTime.parse("2023-03-24TZ"));
clock.setTo(Instant.parse("2023-03-24T00:00:00Z"));
}
@Test
@@ -86,7 +86,7 @@ class TmchCrlActionTest extends TmchActionTestCase {
@Test
void testFailure_crlNotYetValid() throws Exception {
clock.setTo(DateTime.parse("1984-01-01TZ"));
clock.setTo(Instant.parse("1984-01-01T00:00:00Z"));
when(httpUrlConnection.getInputStream())
.thenReturn(
new ByteArrayInputStream(
@@ -26,8 +26,8 @@ import google.registry.tmch.TmchXmlSignature.CertificateSignatureException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.CertificateRevokedException;
import java.time.Instant;
import javax.xml.crypto.dsig.XMLSignatureException;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
@@ -59,7 +59,7 @@ class TmchXmlSignatureTest {
//
// When updating this date, also update the "time travel" dates in two tests below, which test to
// make sure that dates before and after the validity window result in rejection.
private final FakeClock clock = new FakeClock(DateTime.parse("2023-01-15T23:15:37.4Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2023-01-15T23:15:37.4Z"));
private byte[] smdData;
private TmchXmlSignature tmchXmlSignature =
@@ -104,14 +104,14 @@ class TmchXmlSignatureTest {
@Test
void testTimeTravelBeforeCertificateWasCreated() {
smdData = loadSmd("smd/active.smd");
clock.setTo(DateTime.parse("2021-05-01T00:00:00Z"));
clock.setTo(Instant.parse("2021-05-01T00:00:00Z"));
assertThrows(CertificateNotYetValidException.class, () -> tmchXmlSignature.verify(smdData));
}
@Test
void testTimeTravelAfterCertificateHasExpired() {
smdData = loadSmd("smd/active.smd");
clock.setTo(DateTime.parse("2028-06-01T00:00:00Z"));
clock.setTo(Instant.parse("2028-06-01T00:00:00Z"));
assertThrows(CertificateExpiredException.class, () -> tmchXmlSignature.verify(smdData));
}
@@ -24,7 +24,7 @@ import com.beust.jcommander.ParameterException;
import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.tld.Tld;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -39,7 +39,7 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
@BeforeEach
void beforeEach() {
fakeClock.setTo(DateTime.parse("1984-12-21T06:07:08.789Z"));
fakeClock.setTo(Instant.parse("1984-12-21T06:07:08.789Z"));
}
@Test
@@ -58,13 +58,14 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
void testListCursors_twoTldsOneAbsent_printsAbsentAndTimestampSorted() throws Exception {
createTlds("foo", "bar");
persistResource(
Cursor.createScoped(CursorType.BRDA, DateTime.parse("1984-12-18TZ"), Tld.get("bar")));
Cursor.createScoped(
CursorType.BRDA, Instant.parse("1984-12-18T00:00:00Z"), Tld.get("bar")));
runCommand("--type=BRDA");
assertThat(getStdoutAsLines())
.containsExactly(
HEADER_ONE,
HEADER_TWO,
"bar 1984-12-18T00:00:00.000Z 1984-12-21T06:07:08.789Z",
"bar 1984-12-18T00:00:00Z 1984-12-21T06:07:08.789Z",
"foo (absent) (absent)")
.inOrder();
}
@@ -73,7 +74,7 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
void testListCursors_badCursor_throwsIae() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> runCommand("--type=love"));
assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter.");
assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter");
}
@Test
@@ -26,7 +26,7 @@ import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType;
import google.registry.model.tld.Tld;
import google.registry.model.tld.Tld.TldNotFoundException;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -43,21 +43,21 @@ class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsCommand> {
void doUpdateTest() throws Exception {
runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "foo");
assertThat(loadByKey(Cursor.createScopedVKey(CursorType.BRDA, registry)).getCursorTime())
.isEqualTo(DateTime.parse("1984-12-18TZ"));
.isEqualTo(Instant.parse("1984-12-18T00:00:00Z"));
String changes = command.prompt();
assertThat(changes)
.isEqualTo("Change cursorTime of BRDA for Scope:foo to 1984-12-18T00:00:00.000Z\n");
.isEqualTo("Change cursorTime of BRDA for Scope:foo to 1984-12-18T00:00:00Z\n");
}
void doGlobalUpdateTest() throws Exception {
runCommandForced("--type=recurring_billing", "--timestamp=1984-12-18T00:00:00Z");
assertThat(loadByKey(Cursor.createGlobalVKey(CursorType.RECURRING_BILLING)).getCursorTime())
.isEqualTo(DateTime.parse("1984-12-18TZ"));
.isEqualTo(Instant.parse("1984-12-18T00:00:00Z"));
String changes = command.prompt();
assertThat(changes)
.isEqualTo(
"Change cursorTime of RECURRING_BILLING for Scope:GLOBAL to"
+ " 1984-12-18T00:00:00.000Z\n");
+ " 1984-12-18T00:00:00Z\n");
}
@Test
@@ -68,14 +68,15 @@ class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsCommand> {
@Test
void testSuccess_hasOldValue() throws Exception {
persistResource(Cursor.createScoped(CursorType.BRDA, DateTime.parse("1950-12-18TZ"), registry));
persistResource(
Cursor.createScoped(CursorType.BRDA, Instant.parse("1950-12-18T00:00:00Z"), registry));
doUpdateTest();
}
@Test
void testSuccess_global_hasOldValue() throws Exception {
persistResource(
Cursor.createGlobal(CursorType.RECURRING_BILLING, DateTime.parse("1950-12-18TZ")));
Cursor.createGlobal(CursorType.RECURRING_BILLING, Instant.parse("1950-12-18T00:00:00Z")));
doGlobalUpdateTest();
}
@@ -89,21 +90,22 @@ class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsCommand> {
void testSuccess_multipleTlds_hasOldValue() throws Exception {
Tld barRegistry = createTld("bar");
Tld registry2 = Tld.get("bar");
persistResource(Cursor.createScoped(CursorType.BRDA, DateTime.parse("1950-12-18TZ"), registry));
persistResource(
Cursor.createScoped(CursorType.BRDA, DateTime.parse("1950-12-18TZ"), registry2));
Cursor.createScoped(CursorType.BRDA, Instant.parse("1950-12-18T00:00:00Z"), registry));
persistResource(
Cursor.createScoped(CursorType.BRDA, Instant.parse("1950-12-18T00:00:00Z"), registry2));
runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "foo", "bar");
assertThat(loadByKey(Cursor.createScopedVKey(CursorType.BRDA, registry)).getCursorTime())
.isEqualTo(DateTime.parse("1984-12-18TZ"));
.isEqualTo(Instant.parse("1984-12-18T00:00:00Z"));
assertThat(loadByKey(Cursor.createScopedVKey(CursorType.BRDA, barRegistry)).getCursorTime())
.isEqualTo(DateTime.parse("1984-12-18TZ"));
.isEqualTo(Instant.parse("1984-12-18T00:00:00Z"));
String changes = command.prompt();
assertThat(changes)
.isEqualTo(
"""
Change cursorTime of BRDA for Scope:foo to 1984-12-18T00:00:00.000Z
Change cursorTime of BRDA for Scope:bar to 1984-12-18T00:00:00.000Z
""");
Change cursorTime of BRDA for Scope:foo to 1984-12-18T00:00:00Z
Change cursorTime of BRDA for Scope:bar to 1984-12-18T00:00:00Z
""");
}
@Test
@@ -113,16 +115,16 @@ class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsCommand> {
assertThat(loadByKeyIfPresent(Cursor.createScopedVKey(CursorType.BRDA, barRegistry))).isEmpty();
runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "foo", "bar");
assertThat(loadByKey(Cursor.createScopedVKey(CursorType.BRDA, registry)).getCursorTime())
.isEqualTo(DateTime.parse("1984-12-18TZ"));
.isEqualTo(Instant.parse("1984-12-18T00:00:00Z"));
assertThat(loadByKey(Cursor.createScopedVKey(CursorType.BRDA, barRegistry)).getCursorTime())
.isEqualTo(DateTime.parse("1984-12-18TZ"));
.isEqualTo(Instant.parse("1984-12-18T00:00:00Z"));
String changes = command.prompt();
assertThat(changes)
.isEqualTo(
"""
Change cursorTime of BRDA for Scope:foo to 1984-12-18T00:00:00.000Z
Change cursorTime of BRDA for Scope:bar to 1984-12-18T00:00:00.000Z
""");
Change cursorTime of BRDA for Scope:foo to 1984-12-18T00:00:00Z
Change cursorTime of BRDA for Scope:bar to 1984-12-18T00:00:00Z
""");
}
@Test
@@ -23,7 +23,7 @@ import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.TestDataHelper.loadFile;
import static google.registry.util.DateTimeUtils.toInstant;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.DateTimeZone.UTC;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
@@ -42,10 +42,9 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import java.net.InetAddress;
import java.time.Duration;
import java.util.Map;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -70,16 +69,16 @@ class GenerateZoneFilesActionTest {
persistResource(
Tld.get("tld")
.asBuilder()
.setDnsAPlusAaaaTtl(Duration.standardSeconds(300))
.setDnsNsTtl(Duration.standardSeconds(400))
.setDnsDsTtl(Duration.standardSeconds(500))
.setDnsAPlusAaaaTtl(org.joda.time.Duration.standardSeconds(300))
.setDnsNsTtl(org.joda.time.Duration.standardSeconds(400))
.setDnsDsTtl(org.joda.time.Duration.standardSeconds(500))
.build());
testGenerate("tldCustomTtl.zone");
}
@SuppressWarnings("AddressSelection")
void testGenerate(String goldenFileName) throws Exception {
DateTime now = DateTime.now(DateTimeZone.UTC).withTimeAtStartOfDay();
DateTime now = DateTime.now(UTC).withTimeAtStartOfDay();
ImmutableSet<InetAddress> ips =
ImmutableSet.of(InetAddress.getByName("127.0.0.1"), InetAddress.getByName("::1"));
@@ -145,10 +144,10 @@ class GenerateZoneFilesActionTest {
GenerateZoneFilesAction action = new GenerateZoneFilesAction();
action.bucket = "zonefiles-bucket";
action.gcsUtils = gcsUtils;
action.databaseRetention = standardDays(29);
action.dnsDefaultATtl = Duration.standardSeconds(11);
action.dnsDefaultNsTtl = Duration.standardSeconds(222);
action.dnsDefaultDsTtl = Duration.standardSeconds(3333);
action.databaseRetention = Duration.ofDays(29);
action.dnsDefaultATtl = Duration.ofSeconds(11);
action.dnsDefaultNsTtl = Duration.ofSeconds(222);
action.dnsDefaultDsTtl = Duration.ofSeconds(3333);
action.clock = new FakeClock(now.plusMinutes(2)); // Move past the actions' 2 minute check.
Map<String, Object> response =
@@ -32,10 +32,10 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import java.time.Duration;
import java.util.Optional;
import java.util.Random;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -69,8 +69,8 @@ public class RefreshDnsForAllDomainsActionTest {
persistActiveDomain("foo.bar");
persistActiveDomain("low.bar");
action.run();
assertDomainDnsRequestWithRequestTime("foo.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("low.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("foo.bar", clock.now());
assertDomainDnsRequestWithRequestTime("low.bar", clock.now());
}
@Test
@@ -86,8 +86,8 @@ public class RefreshDnsForAllDomainsActionTest {
Optional.of(7),
Optional.empty(),
new Random());
tm().transact(() -> action.refreshBatch(Optional.empty(), Duration.standardMinutes(1000)));
tm().transact(() -> action.refreshBatch(Optional.empty(), Duration.standardMinutes(1000)));
tm().transact(() -> action.refreshBatch(Optional.empty(), Duration.ofMinutes(1000)));
tm().transact(() -> action.refreshBatch(Optional.empty(), Duration.ofMinutes(1000)));
ImmutableList<DnsRefreshRequest> refreshRequests =
tm().transact(
() ->
@@ -104,7 +104,7 @@ public class RefreshDnsForAllDomainsActionTest {
persistActiveDomain("foo.bar");
persistDeletedDomain("deleted.bar", clock.nowUtc().minusYears(1));
action.run();
assertDomainDnsRequestWithRequestTime("foo.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("foo.bar", clock.now());
assertNoDnsRequestsExcept("foo.bar");
}
@@ -123,9 +123,9 @@ public class RefreshDnsForAllDomainsActionTest {
persistDeletedDomain("deleted3.bar", clock.nowUtc().minusYears(3));
persistDeletedDomain("deleted5.bar", clock.nowUtc().minusYears(5));
action.run();
assertDomainDnsRequestWithRequestTime("foo.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("deleted1.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("deleted3.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("foo.bar", clock.now());
assertDomainDnsRequestWithRequestTime("deleted1.bar", clock.now());
assertDomainDnsRequestWithRequestTime("deleted3.bar", clock.now());
assertNoDnsRequestsExcept("foo.bar", "deleted1.bar", "deleted3.bar");
}
@@ -137,8 +137,8 @@ public class RefreshDnsForAllDomainsActionTest {
persistActiveDomain("low.bar");
persistActiveDomain("ignore.baz");
action.run();
assertDomainDnsRequestWithRequestTime("foo.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("low.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("foo.bar", clock.now());
assertDomainDnsRequestWithRequestTime("low.bar", clock.now());
assertNoDnsRequestsExcept("foo.bar", "low.bar");
}
@@ -148,6 +148,6 @@ public class RefreshDnsForAllDomainsActionTest {
persistActiveDomain(String.format("test%s.bar", i));
}
action.run();
assertDnsRequestsWithRequestTime(clock.nowUtc(), 11);
assertDnsRequestsWithRequestTime(clock.now(), 11);
}
}
@@ -17,6 +17,7 @@ package google.registry.webdriver;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.server.Fixture.BASIC;
import static google.registry.testing.DatabaseHelper.persistResource;
import static java.time.temporal.ChronoUnit.MILLIS;
import com.google.common.collect.ImmutableMap;
import google.registry.model.console.GlobalRole;
@@ -24,7 +25,6 @@ import google.registry.model.console.RegistrarRole;
import google.registry.model.registrar.Registrar;
import google.registry.server.RegistryTestServer;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Timeout;
@@ -80,10 +80,7 @@ public class ConsoleScreenshotTest {
server.setRegistrarRoles(ImmutableMap.of("TheRegistrar", RegistrarRole.ACCOUNT_MANAGER));
Registrar registrar = Registrar.loadByRegistrarId("TheRegistrar").get();
registrar =
registrar
.asBuilder()
.setLastPocVerificationDate(Instant.now().truncatedTo(ChronoUnit.MILLIS))
.build();
registrar.asBuilder().setLastPocVerificationDate(Instant.now().truncatedTo(MILLIS)).build();
persistResource(registrar);
loadHomePage();
}