mirror of
https://github.com/google/nomulus
synced 2026-02-10 06:50:30 +00:00
Unwrap the return value of loadAtPointInTime (#1205)
In SQL we do not need to wrap it in a Result. Unfortunately we cannot overload a function based on its return value so we renamed the existing one and created a new one with the old name that returns the resource directly. Once we no longer have use of Datastore we can delete the now renamed function that returns a Result<? extends EppResource> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/google/nomulus/1205) <!-- Reviewable:end -->
This commit is contained in:
@@ -138,13 +138,13 @@ class EppPointInTimeTest {
|
||||
|
||||
// Creation time has millisecond granularity due to isActive() check.
|
||||
tm().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.minusMillis(1)).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusMillis(1)).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.minusMillis(1))).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate)).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusMillis(1))).isNotNull();
|
||||
|
||||
tm().clearSessionCache();
|
||||
assertAboutImmutableObjects()
|
||||
.that(loadAtPointInTime(latest, timeAtCreate.plusDays(1)).now())
|
||||
.that(loadAtPointInTime(latest, timeAtCreate.plusDays(1)))
|
||||
.hasFieldsEqualTo(domainAfterCreate);
|
||||
|
||||
tm().clearSessionCache();
|
||||
@@ -152,30 +152,30 @@ class EppPointInTimeTest {
|
||||
// Both updates happened on the same day. Since the revisions field has day granularity in
|
||||
// Datastore, the key to the first update should have been overwritten by the second, and its
|
||||
// timestamp rolled forward. So we have to fall back to the last revision before midnight.
|
||||
assertThat(loadAtPointInTime(latest, timeAtFirstUpdate).now()).isEqualTo(domainAfterCreate);
|
||||
assertThat(loadAtPointInTime(latest, timeAtFirstUpdate)).isEqualTo(domainAfterCreate);
|
||||
} else {
|
||||
// In SQL, however, we are not limited by the day granularity, so when we request the object
|
||||
// at timeAtFirstUpdate we should receive the object at that first update, even though the
|
||||
// second update occurred one millisecond later.
|
||||
assertAboutImmutableObjects()
|
||||
.that(loadAtPointInTime(latest, timeAtFirstUpdate).now())
|
||||
.that(loadAtPointInTime(latest, timeAtFirstUpdate))
|
||||
.hasFieldsEqualTo(domainAfterFirstUpdate);
|
||||
}
|
||||
|
||||
tm().clearSessionCache();
|
||||
assertAboutImmutableObjects()
|
||||
.that(loadAtPointInTime(latest, timeAtSecondUpdate).now())
|
||||
.that(loadAtPointInTime(latest, timeAtSecondUpdate))
|
||||
.hasFieldsEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
tm().clearSessionCache();
|
||||
assertAboutImmutableObjects()
|
||||
.that(loadAtPointInTime(latest, timeAtSecondUpdate.plusDays(1)).now())
|
||||
.that(loadAtPointInTime(latest, timeAtSecondUpdate.plusDays(1)))
|
||||
.hasFieldsEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
// Deletion time has millisecond granularity due to isActive() check.
|
||||
tm().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.minusMillis(1)).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.plusMillis(1)).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.minusMillis(1))).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete)).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.plusMillis(1))).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class EppResourceUtilsTest {
|
||||
newHostResource("ns1.cat.tld").asBuilder()
|
||||
.setCreationTimeForTest(clock.nowUtc())
|
||||
.build());
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc().minus(Duration.millis(1))).now()).isNull();
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc().minus(Duration.millis(1)))).isNull();
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
@@ -78,7 +78,7 @@ class EppResourceUtilsTest {
|
||||
newHostResource("ns1.cat.tld").asBuilder()
|
||||
.setCreationTimeForTest(START_OF_TIME)
|
||||
.build());
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc()).now()).isEqualTo(host);
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc())).isEqualTo(host);
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
@@ -99,8 +99,7 @@ class EppResourceUtilsTest {
|
||||
.build());
|
||||
// Load at the point in time just before the latest update; the floor entry of the revisions
|
||||
// map should point to the manifest for the first save, so we should get the old host.
|
||||
assertThat(loadAtPointInTime(currentHost, clock.nowUtc().minusMillis(1)).now())
|
||||
.isEqualTo(oldHost);
|
||||
assertThat(loadAtPointInTime(currentHost, clock.nowUtc().minusMillis(1))).isEqualTo(oldHost);
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
@@ -120,7 +119,7 @@ class EppResourceUtilsTest {
|
||||
// Load at the point in time just before the latest update; the old host is not recoverable
|
||||
// (revisions map link is broken, and guessing using the oldest revision map entry finds the
|
||||
// same broken link), so just returns the current host.
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc().minusMillis(1)).now()).isEqualTo(host);
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc().minusMillis(1))).isEqualTo(host);
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
@@ -141,8 +140,7 @@ class EppResourceUtilsTest {
|
||||
// Load at the point in time before the first update; there will be no floor entry for the
|
||||
// revisions map, so give up and return the oldest revision entry's mutation value (the old host
|
||||
// data).
|
||||
assertThat(loadAtPointInTime(currentHost, clock.nowUtc().minusDays(2)).now())
|
||||
.isEqualTo(oldHost);
|
||||
assertThat(loadAtPointInTime(currentHost, clock.nowUtc().minusDays(2))).isEqualTo(oldHost);
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
@@ -157,7 +155,7 @@ class EppResourceUtilsTest {
|
||||
// Load at the point in time before the first save; there will be no floor entry for the
|
||||
// revisions map. Since the oldest revision entry is the only (i.e. current) revision, return
|
||||
// the resource.
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc().minusMillis(1)).now()).isEqualTo(host);
|
||||
assertThat(loadAtPointInTime(host, clock.nowUtc().minusMillis(1))).isEqualTo(host);
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
@@ -175,7 +173,7 @@ class EppResourceUtilsTest {
|
||||
// Even though there is no revision, make a best effort guess to use the oldest revision.
|
||||
assertThat(
|
||||
loadAtPointInTime(host, clock.nowUtc().minus(Duration.standardDays(32)))
|
||||
.now()
|
||||
|
||||
.getUpdateTimestamp()
|
||||
.getTimestamp())
|
||||
.isEqualTo(host.getRevisions().firstKey());
|
||||
|
||||
Reference in New Issue
Block a user