mirror of
https://github.com/google/nomulus.git
synced 2025-07-07 03:33:28 +02:00
Embed a ZonedDateTime as the UpdateAutoTimestamp in SQL (#1033)
* Embed a ZonedDateTime as the UpdateAutoTimestamp in SQL This means we can get rid of the converter and more importantly, means that reading the object from SQL does not affect the last-read time (the test added to UpdateAutoTimestampTest failed prior to the production code change). For now we keep both time fields in UpdateAutoTimestamp however post-migration, we can remove the joda-time field if we wish. Note: I'm not sure why <now> is the time that we started getting LazyInitializationExceptions in the LegacyHistoryObject and ReplayExtension tests but we can solve that by just examining / initializing the object within the transaction.
This commit is contained in:
parent
1e650bd0a1
commit
a4e078305d
28 changed files with 2875 additions and 2932 deletions
|
@ -148,9 +148,9 @@ public class AsyncTaskEnqueuerTest {
|
|||
RegistryLock lock =
|
||||
saveRegistryLock(
|
||||
new RegistryLock.Builder()
|
||||
.setLockCompletionTimestamp(clock.nowUtc())
|
||||
.setUnlockRequestTimestamp(clock.nowUtc())
|
||||
.setUnlockCompletionTimestamp(clock.nowUtc())
|
||||
.setLockCompletionTime(clock.nowUtc())
|
||||
.setUnlockRequestTime(clock.nowUtc())
|
||||
.setUnlockCompletionTime(clock.nowUtc())
|
||||
.isSuperuser(false)
|
||||
.setDomainName("example.tld")
|
||||
.setRepoId("repoId")
|
||||
|
|
|
@ -22,13 +22,16 @@ import com.googlecode.objectify.Key;
|
|||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Ignore;
|
||||
import google.registry.model.common.CrossTldSingleton;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.schema.replay.EntityTest.EntityForTesting;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.InjectExtension;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link UpdateAutoTimestamp}. */
|
||||
|
@ -46,6 +49,13 @@ public class UpdateAutoTimestampTest {
|
|||
.withClock(clock)
|
||||
.build();
|
||||
|
||||
@RegisterExtension public final InjectExtension inject = new InjectExtension();
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
}
|
||||
|
||||
/** Timestamped class. */
|
||||
@Entity(name = "UatTestEntity")
|
||||
@javax.persistence.Entity
|
||||
|
@ -70,6 +80,7 @@ public class UpdateAutoTimestampTest {
|
|||
DateTime transactionTime =
|
||||
tm().transact(
|
||||
() -> {
|
||||
clock.advanceOneMilli();
|
||||
UpdateAutoTimestampTestObject object = new UpdateAutoTimestampTestObject();
|
||||
assertThat(object.updateTime.timestamp).isNull();
|
||||
tm().insert(object);
|
||||
|
@ -84,6 +95,7 @@ public class UpdateAutoTimestampTest {
|
|||
DateTime initialTime =
|
||||
tm().transact(
|
||||
() -> {
|
||||
clock.advanceOneMilli();
|
||||
tm().insert(new UpdateAutoTimestampTestObject());
|
||||
return tm().getTransactionTime();
|
||||
});
|
||||
|
@ -109,6 +121,7 @@ public class UpdateAutoTimestampTest {
|
|||
DateTime transactionTime =
|
||||
tm().transact(
|
||||
() -> {
|
||||
clock.advanceOneMilli();
|
||||
UpdateAutoTimestampTestObject object = new UpdateAutoTimestampTestObject();
|
||||
object.updateTime = UpdateAutoTimestamp.create(DateTime.now(UTC).minusDays(1));
|
||||
tm().insert(object);
|
||||
|
@ -117,4 +130,17 @@ public class UpdateAutoTimestampTest {
|
|||
tm().clearSessionCache();
|
||||
assertThat(reload().updateTime.timestamp).isEqualTo(transactionTime);
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testReadingTwiceDoesNotModify() {
|
||||
DateTime originalTime = DateTime.parse("1999-01-01T00:00:00Z");
|
||||
clock.setTo(originalTime);
|
||||
tm().transact(() -> tm().insert(new UpdateAutoTimestampTestObject()));
|
||||
clock.advanceOneMilli();
|
||||
UpdateAutoTimestampTestObject firstRead = reload();
|
||||
assertThat(firstRead.updateTime.getTimestamp()).isEqualTo(originalTime);
|
||||
clock.advanceOneMilli();
|
||||
UpdateAutoTimestampTestObject secondRead = reload();
|
||||
assertThat(secondRead.updateTime.getTimestamp()).isEqualTo(originalTime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,22 +129,26 @@ public class LegacyHistoryObjectTest extends EntityTestCase {
|
|||
|
||||
// Next, save that from-Datastore object in SQL and verify we can load it back in
|
||||
jpaTm().transact(() -> jpaTm().insert(legacyDomainHistory));
|
||||
DomainHistory legacyHistoryFromSql =
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(legacyDomainHistory.createVKey()));
|
||||
// Don't compare nsHosts directly because one is null and the other is empty
|
||||
assertAboutImmutableObjects()
|
||||
.that(legacyDomainHistory)
|
||||
.isEqualExceptFields(
|
||||
// NB: period, transaction records, and other client ID are added in #794
|
||||
legacyHistoryFromSql,
|
||||
"period",
|
||||
"domainTransactionRecords",
|
||||
"otherClientId",
|
||||
"nsHosts",
|
||||
"dsDataHistories",
|
||||
"gracePeriodHistories");
|
||||
assertThat(nullToEmpty(legacyDomainHistory.getNsHosts()))
|
||||
.isEqualTo(nullToEmpty(legacyHistoryFromSql.getNsHosts()));
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
DomainHistory legacyHistoryFromSql =
|
||||
jpaTm().loadByKey(legacyDomainHistory.createVKey());
|
||||
// Don't compare nsHosts directly because one is null and the other is empty
|
||||
assertAboutImmutableObjects()
|
||||
.that(legacyDomainHistory)
|
||||
.isEqualExceptFields(
|
||||
// NB: period, transaction records, and other client ID are added in #794
|
||||
legacyHistoryFromSql,
|
||||
"period",
|
||||
"domainTransactionRecords",
|
||||
"otherClientId",
|
||||
"nsHosts",
|
||||
"dsDataHistories",
|
||||
"gracePeriodHistories");
|
||||
assertThat(nullToEmpty(legacyDomainHistory.getNsHosts()))
|
||||
.isEqualTo(nullToEmpty(legacyHistoryFromSql.getNsHosts()));
|
||||
});
|
||||
}
|
||||
|
||||
@TestSqlOnly
|
||||
|
|
|
@ -46,7 +46,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
RegistryLock fromDatabase = getRegistryLockByVerificationCode(lock.getVerificationCode()).get();
|
||||
assertThat(fromDatabase.getDomainName()).isEqualTo(lock.getDomainName());
|
||||
assertThat(fromDatabase.getVerificationCode()).isEqualTo(lock.getVerificationCode());
|
||||
assertThat(fromDatabase.getLastUpdateTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(fromDatabase.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -60,16 +60,15 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
RegistryLock updatedLock =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get();
|
||||
RegistryLockDao.save(
|
||||
updatedLock.asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build());
|
||||
updatedLock.asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build());
|
||||
});
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
RegistryLock fromDatabase =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get();
|
||||
assertThat(fromDatabase.getLockCompletionTimestamp().get())
|
||||
.isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(fromDatabase.getLastUpdateTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(fromDatabase.getLockCompletionTime().get()).isEqualTo(fakeClock.nowUtc());
|
||||
assertThat(fromDatabase.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -79,15 +78,14 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTime(fakeClock.nowUtc())
|
||||
.setRelockDuration(Duration.standardHours(6))
|
||||
.build());
|
||||
RegistryLock fromDatabase = getRegistryLockByVerificationCode(lock.getVerificationCode()).get();
|
||||
assertThat(fromDatabase.getUnlockRequestTimestamp()).isEqualTo(Optional.of(fakeClock.nowUtc()));
|
||||
assertThat(fromDatabase.getUnlockCompletionTimestamp())
|
||||
.isEqualTo(Optional.of(fakeClock.nowUtc()));
|
||||
assertThat(fromDatabase.getUnlockRequestTime()).isEqualTo(Optional.of(fakeClock.nowUtc()));
|
||||
assertThat(fromDatabase.getUnlockCompletionTime()).isEqualTo(Optional.of(fakeClock.nowUtc()));
|
||||
assertThat(fromDatabase.isLocked()).isFalse();
|
||||
assertThat(fromDatabase.getRelockDuration().get()).isEqualTo(Duration.standardHours(6));
|
||||
}
|
||||
|
@ -96,15 +94,14 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
void testUpdateLock_usingSamePrimaryKey() {
|
||||
RegistryLock lock = saveRegistryLock(createLock());
|
||||
fakeClock.advanceOneMilli();
|
||||
RegistryLock updatedLock =
|
||||
lock.asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
||||
RegistryLock updatedLock = lock.asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build();
|
||||
saveRegistryLock(updatedLock);
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
RegistryLock fromDatabase =
|
||||
RegistryLockDao.getByVerificationCode(lock.getVerificationCode()).get();
|
||||
assertThat(fromDatabase.getLockCompletionTimestamp())
|
||||
assertThat(fromDatabase.getLockCompletionTime())
|
||||
.isEqualTo(Optional.of(fakeClock.nowUtc()));
|
||||
});
|
||||
}
|
||||
|
@ -140,15 +137,15 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
createLock()
|
||||
.asBuilder()
|
||||
.setDomainName("otherexample.test")
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.build();
|
||||
RegistryLock unlockedLock =
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setDomainName("unlocked.test")
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTime(fakeClock.nowUtc())
|
||||
.build();
|
||||
saveRegistryLock(lock);
|
||||
saveRegistryLock(secondLock);
|
||||
|
@ -165,7 +162,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
@Test
|
||||
void testLoad_byRepoId() {
|
||||
RegistryLock completedLock =
|
||||
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
||||
createLock().asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build();
|
||||
saveRegistryLock(completedLock);
|
||||
|
||||
fakeClock.advanceOneMilli();
|
||||
|
@ -185,7 +182,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
@Test
|
||||
void testLoad_verified_byRepoId() {
|
||||
RegistryLock completedLock =
|
||||
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
||||
createLock().asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build();
|
||||
saveRegistryLock(completedLock);
|
||||
|
||||
fakeClock.advanceOneMilli();
|
||||
|
@ -210,9 +207,9 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
|
||||
Optional<RegistryLock> mostRecent = getMostRecentUnlockedRegistryLockByRepoId(lock.getRepoId());
|
||||
|
@ -222,7 +219,7 @@ public final class RegistryLockDaoTest extends EntityTestCase {
|
|||
@Test
|
||||
void testLoad_verifiedUnlock_empty() {
|
||||
RegistryLock completedLock =
|
||||
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build();
|
||||
createLock().asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build();
|
||||
saveRegistryLock(completedLock);
|
||||
assertThat(getMostRecentUnlockedRegistryLockByRepoId(completedLock.getRepoId()).isPresent())
|
||||
.isFalse();
|
||||
|
|
|
@ -142,6 +142,7 @@ class EntityCallbacksListenerTest {
|
|||
assertThat(testEntity.entityEmbedded.entityEmbeddedParentPostLoad).isEqualTo(expectedLoad);
|
||||
|
||||
assertThat(testEntity.parentPostLoad).isEqualTo(expectedLoad);
|
||||
assertThat(testEntity.parentPrePersist).isEqualTo(expectedPersist);
|
||||
assertThat(testEntity.parentEmbedded.parentEmbeddedPostLoad).isEqualTo(expectedLoad);
|
||||
assertThat(testEntity.parentEmbedded.parentEmbeddedNested.parentEmbeddedNestedPostLoad)
|
||||
.isEqualTo(expectedLoad);
|
||||
|
@ -241,6 +242,7 @@ class EntityCallbacksListenerTest {
|
|||
private static class ParentEntity {
|
||||
@Embedded ParentEmbedded parentEmbedded = new ParentEmbedded();
|
||||
@Transient int parentPostLoad = 0;
|
||||
@Transient int parentPrePersist = 0;
|
||||
|
||||
String parentEntity = "placeholder";
|
||||
|
||||
|
@ -248,6 +250,11 @@ class EntityCallbacksListenerTest {
|
|||
void parentPostLoad() {
|
||||
parentPostLoad++;
|
||||
}
|
||||
|
||||
@PrePersist
|
||||
void parentPrePersist() {
|
||||
parentPrePersist++;
|
||||
}
|
||||
}
|
||||
|
||||
@Embeddable
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
// Copyright 2019 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package google.registry.persistence.converter;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.UpdateAutoTimestamp;
|
||||
import google.registry.persistence.transaction.JpaTestRules;
|
||||
import google.registry.persistence.transaction.JpaTestRules.JpaUnitTestExtension;
|
||||
import google.registry.schema.replay.EntityTest.EntityForTesting;
|
||||
import google.registry.testing.FakeClock;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link UpdateAutoTimestampConverter}. */
|
||||
public class UpdateAutoTimestampConverterTest {
|
||||
|
||||
private final FakeClock fakeClock = new FakeClock();
|
||||
|
||||
@RegisterExtension
|
||||
public final JpaUnitTestExtension jpaExtension =
|
||||
new JpaTestRules.Builder()
|
||||
.withClock(fakeClock)
|
||||
.withEntityClass(TestEntity.class)
|
||||
.buildUnitTestRule();
|
||||
|
||||
@Test
|
||||
void testTypeConversion() {
|
||||
TestEntity ent = new TestEntity("myinst", null);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().insert(ent));
|
||||
|
||||
TestEntity result =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst"));
|
||||
|
||||
assertThat(result.name).isEqualTo("myinst");
|
||||
assertThat(result.uat.getTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTimeChangesOnSubsequentTransactions() {
|
||||
TestEntity ent1 = new TestEntity("myinst1", null);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().insert(ent1));
|
||||
|
||||
TestEntity result1 =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst1"));
|
||||
|
||||
fakeClock.advanceOneMilli();
|
||||
|
||||
TestEntity ent2 = new TestEntity("myinst2", result1.uat);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().insert(ent2));
|
||||
|
||||
TestEntity result2 =
|
||||
jpaTm().transact(() -> jpaTm().getEntityManager().find(TestEntity.class, "myinst2"));
|
||||
|
||||
assertThat(result1.uat.getTimestamp()).isNotEqualTo(result2.uat.getTimestamp());
|
||||
assertThat(result2.uat.getTimestamp()).isEqualTo(fakeClock.nowUtc());
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.
|
||||
@EntityForTesting
|
||||
public static class TestEntity extends ImmutableObject {
|
||||
|
||||
@Id String name;
|
||||
|
||||
UpdateAutoTimestamp uat;
|
||||
|
||||
public TestEntity() {}
|
||||
|
||||
TestEntity(String name, UpdateAutoTimestamp uat) {
|
||||
this.name = name;
|
||||
this.uat = uat;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -110,17 +110,22 @@ public class ReplayExtension implements BeforeEachCallback, AfterEachCallback {
|
|||
// have to compare the current value in SQL (which we just mutated) against the value that
|
||||
// we originally would have persisted (that being the object in the entry).
|
||||
VKey<?> vkey = VKey.from(entry.getKey());
|
||||
Optional<?> jpaValue = jpaTm().transact(() -> jpaTm().loadByKeyIfPresent(vkey));
|
||||
if (entry.getValue().equals(TransactionInfo.Delete.SENTINEL)) {
|
||||
assertThat(jpaValue.isPresent()).isFalse();
|
||||
} else {
|
||||
ImmutableObject immutJpaObject = (ImmutableObject) jpaValue.get();
|
||||
assertAboutImmutableObjects().that(immutJpaObject).hasCorrectHashValue();
|
||||
assertAboutImmutableObjects()
|
||||
.that(immutJpaObject)
|
||||
.isEqualAcrossDatabases(
|
||||
(ImmutableObject) ((DatastoreEntity) entry.getValue()).toSqlEntity().get());
|
||||
}
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
Optional<?> jpaValue = jpaTm().loadByKeyIfPresent(vkey);
|
||||
if (entry.getValue().equals(TransactionInfo.Delete.SENTINEL)) {
|
||||
assertThat(jpaValue.isPresent()).isFalse();
|
||||
} else {
|
||||
ImmutableObject immutJpaObject = (ImmutableObject) jpaValue.get();
|
||||
assertAboutImmutableObjects().that(immutJpaObject).hasCorrectHashValue();
|
||||
assertAboutImmutableObjects()
|
||||
.that(immutJpaObject)
|
||||
.isEqualAcrossDatabases(
|
||||
(ImmutableObject)
|
||||
((DatastoreEntity) entry.getValue()).toSqlEntity().get());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public final class DomainLockUtilsTest {
|
|||
RegistryLock lock =
|
||||
domainLockUtils.saveNewRegistryLockRequest(DOMAIN_NAME, "TheRegistrar", POC_ID, false);
|
||||
assertNoDomainChanges();
|
||||
assertThat(lock.getLockCompletionTimestamp().isPresent()).isFalse();
|
||||
assertThat(lock.getLockCompletionTime().isPresent()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -113,7 +113,7 @@ public final class DomainLockUtilsTest {
|
|||
RegistryLock lock =
|
||||
domainLockUtils.saveNewRegistryUnlockRequest(
|
||||
DOMAIN_NAME, "TheRegistrar", false, Optional.empty());
|
||||
assertThat(lock.getUnlockCompletionTimestamp().isPresent()).isFalse();
|
||||
assertThat(lock.getUnlockCompletionTime().isPresent()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -122,7 +122,7 @@ public final class DomainLockUtilsTest {
|
|||
RegistryLock lock =
|
||||
domainLockUtils.saveNewRegistryUnlockRequest(
|
||||
DOMAIN_NAME, "TheRegistrar", true, Optional.empty());
|
||||
assertThat(lock.getUnlockCompletionTimestamp().isPresent()).isFalse();
|
||||
assertThat(lock.getUnlockCompletionTime().isPresent()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -285,7 +285,7 @@ public final class DomainLockUtilsTest {
|
|||
RegistryLock resultLock =
|
||||
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, true);
|
||||
verifyProperlyLockedDomain(true);
|
||||
assertThat(resultLock.getLockCompletionTimestamp()).isEqualTo(Optional.of(clock.nowUtc()));
|
||||
assertThat(resultLock.getLockCompletionTime()).isEqualTo(Optional.of(clock.nowUtc()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -294,7 +294,7 @@ public final class DomainLockUtilsTest {
|
|||
// what the RegistryLock table says
|
||||
SqlHelper.saveRegistryLock(
|
||||
new RegistryLock.Builder()
|
||||
.setLockCompletionTimestamp(clock.nowUtc())
|
||||
.setLockCompletionTime(clock.nowUtc())
|
||||
.setDomainName(DOMAIN_NAME)
|
||||
.setVerificationCode("hi")
|
||||
.setRegistrarId("TheRegistrar")
|
||||
|
@ -306,7 +306,7 @@ public final class DomainLockUtilsTest {
|
|||
RegistryLock resultLock =
|
||||
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, "TheRegistrar", POC_ID, true);
|
||||
verifyProperlyLockedDomain(true);
|
||||
assertThat(resultLock.getLockCompletionTimestamp()).isEqualTo(Optional.of(clock.nowUtc()));
|
||||
assertThat(resultLock.getLockCompletionTime()).isEqualTo(Optional.of(clock.nowUtc()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -68,7 +68,7 @@ class BackfillRegistryLocksCommandTest extends CommandTestCase<BackfillRegistryL
|
|||
|
||||
Optional<RegistryLock> lockOptional = getMostRecentRegistryLockByRepoId(domain.getRepoId());
|
||||
Truth8.assertThat(lockOptional).isPresent();
|
||||
Truth8.assertThat(lockOptional.get().getLockCompletionTimestamp()).isPresent();
|
||||
Truth8.assertThat(lockOptional.get().getLockCompletionTime()).isPresent();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
|
@ -111,18 +111,15 @@ class BackfillRegistryLocksCommandTest extends CommandTestCase<BackfillRegistryL
|
|||
.setRegistrarId("adminreg")
|
||||
.setRepoId(domain.getRepoId())
|
||||
.setDomainName(domain.getDomainName())
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setVerificationCode(command.stringGenerator.createString(32))
|
||||
.build());
|
||||
|
||||
fakeClock.advanceBy(Duration.standardDays(1));
|
||||
runCommandForced("--domain_roids", domain.getRepoId());
|
||||
|
||||
assertThat(
|
||||
getMostRecentRegistryLockByRepoId(domain.getRepoId())
|
||||
.get()
|
||||
.getLockCompletionTimestamp())
|
||||
.isEqualTo(previousLock.getLockCompletionTimestamp());
|
||||
assertThat(getMostRecentRegistryLockByRepoId(domain.getRepoId()).get().getLockCompletionTime())
|
||||
.isEqualTo(previousLock.getLockCompletionTime());
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
|
@ -147,10 +144,10 @@ class BackfillRegistryLocksCommandTest extends CommandTestCase<BackfillRegistryL
|
|||
"--domain_roids", String.format("%s,%s", ursDomain.getRepoId(), nonUrsDomain.getRepoId()));
|
||||
|
||||
RegistryLock ursLock = getMostRecentVerifiedRegistryLockByRepoId(ursDomain.getRepoId()).get();
|
||||
assertThat(ursLock.getLockCompletionTimestamp()).hasValue(ursTime);
|
||||
assertThat(ursLock.getLockCompletionTime()).hasValue(ursTime);
|
||||
RegistryLock nonUrsLock =
|
||||
getMostRecentVerifiedRegistryLockByRepoId(nonUrsDomain.getRepoId()).get();
|
||||
assertThat(nonUrsLock.getLockCompletionTimestamp()).hasValue(fakeClock.nowUtc());
|
||||
assertThat(nonUrsLock.getLockCompletionTime()).hasValue(fakeClock.nowUtc());
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
|
|
|
@ -101,8 +101,8 @@ final class RegistryLockGetActionTest {
|
|||
.setRegistrarId("TheRegistrar")
|
||||
.setVerificationCode("123456789ABCDEFGHJKLMNPQRSTUVWXY")
|
||||
.setRegistrarPocId("johndoe@theregistrar.com")
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.build();
|
||||
saveRegistryLock(expiredUnlock);
|
||||
fakeClock.advanceBy(Duration.standardDays(1));
|
||||
|
@ -114,7 +114,7 @@ final class RegistryLockGetActionTest {
|
|||
.setRegistrarId("TheRegistrar")
|
||||
.setVerificationCode("123456789ABCDEFGHJKLMNPQRSTUVWXY")
|
||||
.setRegistrarPocId("johndoe@theregistrar.com")
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.build();
|
||||
fakeClock.advanceOneMilli();
|
||||
RegistryLock adminLock =
|
||||
|
@ -124,7 +124,7 @@ final class RegistryLockGetActionTest {
|
|||
.setRegistrarId("TheRegistrar")
|
||||
.setVerificationCode("122222222ABCDEFGHJKLMNPQRSTUVWXY")
|
||||
.isSuperuser(true)
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.build();
|
||||
RegistryLock incompleteLock =
|
||||
new RegistryLock.Builder()
|
||||
|
@ -142,8 +142,8 @@ final class RegistryLockGetActionTest {
|
|||
.setRegistrarId("TheRegistrar")
|
||||
.setVerificationCode("123456789ABCDEFGHJKLMNPQRSTUVWXY")
|
||||
.setRegistrarPocId("johndoe@theregistrar.com")
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.build();
|
||||
|
||||
RegistryLock unlockedLock =
|
||||
|
@ -153,9 +153,9 @@ final class RegistryLockGetActionTest {
|
|||
.setRegistrarId("TheRegistrar")
|
||||
.setRegistrarPocId("johndoe@theregistrar.com")
|
||||
.setVerificationCode("123456789ABCDEFGHJKLMNPQRSTUUUUU")
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTime(fakeClock.nowUtc())
|
||||
.build();
|
||||
|
||||
saveRegistryLock(regularLock);
|
||||
|
|
|
@ -123,7 +123,7 @@ final class RegistryLockPostActionTest {
|
|||
|
||||
@Test
|
||||
void testSuccess_unlock() throws Exception {
|
||||
saveRegistryLock(createLock().asBuilder().setLockCompletionTimestamp(clock.nowUtc()).build());
|
||||
saveRegistryLock(createLock().asBuilder().setLockCompletionTime(clock.nowUtc()).build());
|
||||
persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
||||
Map<String, ?> response = action.handleJsonRequest(unlockRequest());
|
||||
assertSuccess(response, "unlock", "Marla.Singer.RegistryLock@crr.com");
|
||||
|
@ -131,7 +131,7 @@ final class RegistryLockPostActionTest {
|
|||
|
||||
@Test
|
||||
void testSuccess_unlock_relockDurationSet() throws Exception {
|
||||
saveRegistryLock(createLock().asBuilder().setLockCompletionTimestamp(clock.nowUtc()).build());
|
||||
saveRegistryLock(createLock().asBuilder().setLockCompletionTime(clock.nowUtc()).build());
|
||||
persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
||||
ImmutableMap<String, Object> request =
|
||||
new ImmutableMap.Builder<String, Object>()
|
||||
|
@ -148,11 +148,7 @@ final class RegistryLockPostActionTest {
|
|||
@Test
|
||||
void testSuccess_unlock_adminUnlockingAdmin() throws Exception {
|
||||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.isSuperuser(true)
|
||||
.setLockCompletionTimestamp(clock.nowUtc())
|
||||
.build());
|
||||
createLock().asBuilder().isSuperuser(true).setLockCompletionTime(clock.nowUtc()).build());
|
||||
persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
||||
action =
|
||||
createAction(
|
||||
|
@ -187,8 +183,8 @@ final class RegistryLockPostActionTest {
|
|||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(clock.nowUtc())
|
||||
.setUnlockRequestTimestamp(clock.nowUtc())
|
||||
.setLockCompletionTime(clock.nowUtc())
|
||||
.setUnlockRequestTime(clock.nowUtc())
|
||||
.build());
|
||||
Map<String, ?> response = action.handleJsonRequest(unlockRequest());
|
||||
assertFailureWithMessage(response, "A pending unlock action already exists for example.tld");
|
||||
|
@ -197,11 +193,7 @@ final class RegistryLockPostActionTest {
|
|||
@Test
|
||||
void testFailure_unlock_nonAdminUnlockingAdmin() {
|
||||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.isSuperuser(true)
|
||||
.setLockCompletionTimestamp(clock.nowUtc())
|
||||
.build());
|
||||
createLock().asBuilder().isSuperuser(true).setLockCompletionTime(clock.nowUtc()).build());
|
||||
persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
||||
Map<String, ?> response = action.handleJsonRequest(unlockRequest());
|
||||
assertFailureWithMessage(
|
||||
|
@ -366,9 +358,9 @@ final class RegistryLockPostActionTest {
|
|||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(clock.nowUtc().minusMinutes(1))
|
||||
.setUnlockRequestTimestamp(clock.nowUtc().minusMinutes(1))
|
||||
.setUnlockCompletionTimestamp(clock.nowUtc().minusMinutes(1))
|
||||
.setLockCompletionTime(clock.nowUtc().minusMinutes(1))
|
||||
.setUnlockRequestTime(clock.nowUtc().minusMinutes(1))
|
||||
.setUnlockCompletionTime(clock.nowUtc().minusMinutes(1))
|
||||
.build());
|
||||
|
||||
Map<String, ?> response = action.handleJsonRequest(lockRequest());
|
||||
|
@ -380,7 +372,7 @@ final class RegistryLockPostActionTest {
|
|||
RegistryLock previousLock = saveRegistryLock(createLock());
|
||||
String verificationCode = previousLock.getVerificationCode();
|
||||
previousLock = getRegistryLockByVerificationCode(verificationCode).get();
|
||||
clock.setTo(previousLock.getLockRequestTimestamp().plusHours(2));
|
||||
clock.setTo(previousLock.getLockRequestTime().plusHours(2));
|
||||
Map<String, ?> response = action.handleJsonRequest(lockRequest());
|
||||
assertSuccess(response, "lock", "Marla.Singer.RegistryLock@crr.com");
|
||||
}
|
||||
|
|
|
@ -114,8 +114,7 @@ final class RegistryLockVerifyActionTest {
|
|||
void testSuccess_unlockDomain() {
|
||||
action = createAction(lockId, false);
|
||||
domain = persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
||||
saveRegistryLock(
|
||||
createLock().asBuilder().setUnlockRequestTimestamp(fakeClock.nowUtc()).build());
|
||||
saveRegistryLock(createLock().asBuilder().setUnlockRequestTime(fakeClock.nowUtc()).build());
|
||||
action.run();
|
||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||
assertThat(response.getPayload()).contains("Success: unlock has been applied to example.tld");
|
||||
|
@ -151,8 +150,7 @@ final class RegistryLockVerifyActionTest {
|
|||
|
||||
@Test
|
||||
void testFailure_alreadyVerified() {
|
||||
saveRegistryLock(
|
||||
createLock().asBuilder().setLockCompletionTimestamp(fakeClock.nowUtc()).build());
|
||||
saveRegistryLock(createLock().asBuilder().setLockCompletionTime(fakeClock.nowUtc()).build());
|
||||
action.run();
|
||||
assertThat(response.getPayload()).contains("Failed: Domain example.tld is already locked");
|
||||
assertNoDomainChanges();
|
||||
|
@ -182,9 +180,9 @@ final class RegistryLockVerifyActionTest {
|
|||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.setUnlockCompletionTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
action.run();
|
||||
assertThat(response.getPayload()).contains("Failed: Domain example.tld is already unlocked");
|
||||
|
@ -234,8 +232,8 @@ final class RegistryLockVerifyActionTest {
|
|||
saveRegistryLock(
|
||||
createLock()
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setLockCompletionTime(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
action.run();
|
||||
assertThat(response.getPayload()).contains("Failed: Domain example.tld is already locked");
|
||||
|
@ -258,7 +256,7 @@ final class RegistryLockVerifyActionTest {
|
|||
saveRegistryLock(
|
||||
lock.asBuilder()
|
||||
.setVerificationCode(unlockVerificationCode)
|
||||
.setUnlockRequestTimestamp(fakeClock.nowUtc())
|
||||
.setUnlockRequestTime(fakeClock.nowUtc())
|
||||
.build());
|
||||
action = createAction(unlockVerificationCode, false);
|
||||
action.run();
|
||||
|
@ -282,8 +280,7 @@ final class RegistryLockVerifyActionTest {
|
|||
void testFailure_unlock_unlockAgain() {
|
||||
action = createAction(lockId, false);
|
||||
domain = persistResource(domain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
||||
saveRegistryLock(
|
||||
createLock().asBuilder().setUnlockRequestTimestamp(fakeClock.nowUtc()).build());
|
||||
saveRegistryLock(createLock().asBuilder().setUnlockRequestTime(fakeClock.nowUtc()).build());
|
||||
action.run();
|
||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||
assertThat(response.getPayload()).contains("Success: unlock has been applied to example.tld");
|
||||
|
|
|
@ -465,8 +465,8 @@ class RegistrarConsoleScreenshotTest extends WebDriverTestCase {
|
|||
saveRegistryLock(
|
||||
createRegistryLock(expiredUnlockRequestDomain)
|
||||
.asBuilder()
|
||||
.setLockCompletionTimestamp(START_OF_TIME.minusDays(1))
|
||||
.setUnlockRequestTimestamp(START_OF_TIME.minusDays(1))
|
||||
.setLockCompletionTime(START_OF_TIME.minusDays(1))
|
||||
.setUnlockRequestTime(START_OF_TIME.minusDays(1))
|
||||
.build());
|
||||
DomainBase domain = persistActiveDomain("example.tld");
|
||||
saveRegistryLock(createRegistryLock(domain).asBuilder().isSuperuser(true).build());
|
||||
|
@ -498,8 +498,8 @@ class RegistrarConsoleScreenshotTest extends WebDriverTestCase {
|
|||
.setRegistrarPocId("Marla.Singer@crr.com")
|
||||
.setDomainName(pendingUnlockDomain.getDomainName())
|
||||
.setRepoId(pendingUnlockDomain.getRepoId())
|
||||
.setLockCompletionTimestamp(START_OF_TIME)
|
||||
.setUnlockRequestTimestamp(START_OF_TIME)
|
||||
.setLockCompletionTime(START_OF_TIME)
|
||||
.setUnlockRequestTime(START_OF_TIME)
|
||||
.build());
|
||||
return null;
|
||||
});
|
||||
|
@ -568,7 +568,7 @@ class RegistrarConsoleScreenshotTest extends WebDriverTestCase {
|
|||
.isSuperuser(false)
|
||||
.setRegistrarId("TheRegistrar")
|
||||
.setRegistrarPocId("Marla.Singer@crr.com")
|
||||
.setLockCompletionTimestamp(START_OF_TIME)
|
||||
.setLockCompletionTime(START_OF_TIME)
|
||||
.setDomainName(domainBase.getDomainName())
|
||||
.setRepoId(domainBase.getRepoId())
|
||||
.build();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue