mirror of
https://github.com/google/nomulus.git
synced 2025-05-03 21:47:51 +02:00
Fix TimestampInversionException (#1065)
* Fix TimestampInversionException * Add autoIncrement * unset auto increment mode
This commit is contained in:
parent
5caab67cd2
commit
162791ccaa
2 changed files with 24 additions and 2 deletions
|
@ -35,6 +35,8 @@ public final class FakeClock implements Clock {
|
||||||
// threads should see a consistent flow.
|
// threads should see a consistent flow.
|
||||||
private final AtomicLong currentTimeMillis = new AtomicLong();
|
private final AtomicLong currentTimeMillis = new AtomicLong();
|
||||||
|
|
||||||
|
private volatile long autoIncrementStepMs;
|
||||||
|
|
||||||
/** Creates a FakeClock that starts at START_OF_TIME. */
|
/** Creates a FakeClock that starts at START_OF_TIME. */
|
||||||
public FakeClock() {
|
public FakeClock() {
|
||||||
this(START_OF_TIME);
|
this(START_OF_TIME);
|
||||||
|
@ -48,7 +50,21 @@ public final class FakeClock implements Clock {
|
||||||
/** Returns the current time. */
|
/** Returns the current time. */
|
||||||
@Override
|
@Override
|
||||||
public DateTime nowUtc() {
|
public DateTime nowUtc() {
|
||||||
return new DateTime(currentTimeMillis.get(), UTC);
|
return new DateTime(currentTimeMillis.addAndGet(autoIncrementStepMs), UTC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the increment applied to the clock whenever it is queried. The increment is zero by
|
||||||
|
* default: the clock is left unchanged when queried.
|
||||||
|
*
|
||||||
|
* <p>Passing a duration of zero to this method effectively unsets the auto increment mode.
|
||||||
|
*
|
||||||
|
* @param autoIncrementStep the new auto increment duration
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public FakeClock setAutoIncrementStep(ReadableDuration autoIncrementStep) {
|
||||||
|
this.autoIncrementStepMs = autoIncrementStep.getMillis();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Advances clock by one millisecond. */
|
/** Advances clock by one millisecond. */
|
||||||
|
|
|
@ -43,6 +43,7 @@ import google.registry.testing.TestCacheExtension;
|
||||||
import google.registry.testing.TestOfyAndSql;
|
import google.registry.testing.TestOfyAndSql;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ public class PremiumListDualDaoTest extends EntityTestCase {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void before() {
|
void before() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
|
fakeClock.setAutoIncrementStep(Duration.millis(1));
|
||||||
fakeClock.setTo(DateTime.parse("1984-12-21T00:00:00.000Z"));
|
fakeClock.setTo(DateTime.parse("1984-12-21T00:00:00.000Z"));
|
||||||
DatabaseTransitionSchedule schedule =
|
DatabaseTransitionSchedule schedule =
|
||||||
DatabaseTransitionSchedule.create(
|
DatabaseTransitionSchedule.create(
|
||||||
|
@ -77,6 +78,11 @@ public class PremiumListDualDaoTest extends EntityTestCase {
|
||||||
tm().transactNew(() -> ofyTm().putWithoutBackup(schedule));
|
tm().transactNew(() -> ofyTm().putWithoutBackup(schedule));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void after() {
|
||||||
|
fakeClock.setAutoIncrementStep(Duration.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void testGetPremiumPrice_secondaryLoadMissingSql() {
|
void testGetPremiumPrice_secondaryLoadMissingSql() {
|
||||||
PremiumListSqlDao.delete(PremiumListSqlDao.getLatestRevision("tld").get());
|
PremiumListSqlDao.delete(PremiumListSqlDao.getLatestRevision("tld").get());
|
||||||
|
|
Loading…
Add table
Reference in a new issue