Rename BackupGroupRoot (#1829)

Also removed the ability to disable update timestamp auto update as it
was only needed during the migration.

Lastly, rectified the use of raw Coder in RegistryJpaIO.
This commit is contained in:
Lai Jiang
2022-10-28 12:22:53 -04:00
committed by GitHub
parent 9c6c210e21
commit 3f68ad5ea3
26 changed files with 152 additions and 436 deletions
@@ -30,6 +30,7 @@ import google.registry.persistence.transaction.TransactionManagerFactory;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import javax.persistence.Persistence;
import org.apache.beam.sdk.coders.SerializableCoder;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.values.PCollection;
import org.hibernate.cfg.Environment;
@@ -161,6 +162,7 @@ public class DatabaseSnapshotTest {
Read<Registry, Registry> read =
RegistryJpaIO.read(() -> CriteriaQueryBuilder.create(Registry.class).build(), x -> x)
.withCoder(SerializableCoder.of(Registry.class))
.withSnapshot(databaseSnapshot.getSnapshotId());
PCollection<Registry> registries = testPipeline.apply(read);
@@ -45,6 +45,7 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.testing.AppEngineExtension;
import google.registry.testing.DatastoreEntityExtension;
import google.registry.testing.FakeClock;
import org.apache.beam.sdk.coders.StringUtf8Coder;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.values.PCollection;
import org.joda.time.DateTime;
@@ -97,7 +98,8 @@ public class RegistryJpaReadTest {
void readWithCriteriaQuery() {
Read<Contact, String> read =
RegistryJpaIO.read(
() -> CriteriaQueryBuilder.create(Contact.class).build(), ContactBase::getContactId);
() -> CriteriaQueryBuilder.create(Contact.class).build(), ContactBase::getContactId)
.withCoder(StringUtf8Coder.of());
PCollection<String> repoIds = testPipeline.apply(read);
PAssert.that(repoIds).containsInAnyOrder("contact_0", "contact_1", "contact_2");
@@ -109,16 +111,17 @@ public class RegistryJpaReadTest {
setupForJoinQuery();
Read<Object[], String> read =
RegistryJpaIO.read(
"select d, r.emailAddress from Domain d join Registrar r on"
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
+ " and d.deletionTime > now()",
ImmutableMap.of("type", Registrar.Type.REAL),
false,
(Object[] row) -> {
Domain domain = (Domain) row[0];
String emailAddress = (String) row[1];
return domain.getRepoId() + "-" + emailAddress;
});
"select d, r.emailAddress from Domain d join Registrar r on"
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
+ " and d.deletionTime > now()",
ImmutableMap.of("type", Registrar.Type.REAL),
false,
(Object[] row) -> {
Domain domain = (Domain) row[0];
String emailAddress = (String) row[1];
return domain.getRepoId() + "-" + emailAddress;
})
.withCoder(StringUtf8Coder.of());
PCollection<String> joinedStrings = testPipeline.apply(read);
PAssert.that(joinedStrings).containsInAnyOrder("4-COM-me@google.com");
@@ -130,16 +133,17 @@ public class RegistryJpaReadTest {
setupForJoinQuery();
Read<Object[], String> read =
RegistryJpaIO.read(
"select d.repo_id, r.email_address from \"Domain\" d join \"Registrar\" r on"
+ " d.current_sponsor_registrar_id = r.registrar_id where r.type = :type"
+ " and d.deletion_time > now()",
ImmutableMap.of("type", "REAL"),
true,
(Object[] row) -> {
String repoId = (String) row[0];
String emailAddress = (String) row[1];
return repoId + "-" + emailAddress;
});
"select d.repo_id, r.email_address from \"Domain\" d join \"Registrar\" r on"
+ " d.current_sponsor_registrar_id = r.registrar_id where r.type = :type"
+ " and d.deletion_time > now()",
ImmutableMap.of("type", "REAL"),
true,
(Object[] row) -> {
String repoId = (String) row[0];
String emailAddress = (String) row[1];
return repoId + "-" + emailAddress;
})
.withCoder(StringUtf8Coder.of());
PCollection<String> joinedStrings = testPipeline.apply(read);
PAssert.that(joinedStrings).containsInAnyOrder("4-COM-me@google.com");
@@ -151,12 +155,13 @@ public class RegistryJpaReadTest {
setupForJoinQuery();
Read<Domain, String> read =
RegistryJpaIO.read(
"select d from Domain d join Registrar r on"
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
+ " and d.deletionTime > now()",
ImmutableMap.of("type", Registrar.Type.REAL),
Domain.class,
Domain::getRepoId);
"select d from Domain d join Registrar r on"
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
+ " and d.deletionTime > now()",
ImmutableMap.of("type", Registrar.Type.REAL),
Domain.class,
Domain::getRepoId)
.withCoder(StringUtf8Coder.of());
PCollection<String> repoIds = testPipeline.apply(read);
PAssert.that(repoIds).containsInAnyOrder("4-COM");
@@ -68,32 +68,6 @@ public class UpdateAutoTimestampTest {
assertThat(reload().updateTime.getTimestamp()).isEqualTo(transactionTime);
}
@Test
void testDisabledUpdates() throws Exception {
DateTime initialTime =
tm().transact(
() -> {
clock.advanceOneMilli();
tm().insert(new UpdateAutoTimestampTestObject());
return tm().getTransactionTime();
});
UpdateAutoTimestampTestObject object = reload();
clock.advanceOneMilli();
try (UpdateAutoTimestamp.DisableAutoUpdateResource ignoredDisabler =
new UpdateAutoTimestamp.DisableAutoUpdateResource()) {
DateTime secondTransactionTime =
tm().transact(
() -> {
tm().put(object);
return tm().getTransactionTime();
});
assertThat(secondTransactionTime).isGreaterThan(initialTime);
}
assertThat(reload().updateTime.getTimestamp()).isEqualTo(initialTime);
}
@Test
void testResavingOverwritesOriginalTime() {
DateTime transactionTime =
@@ -57,7 +57,7 @@ class VKeyTest {
void testCreateById_failsWhenParentIsNullButShouldntBe() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> VKey.create(OneTime.class, 134L));
assertThat(thrown).hasMessageThat().contains("BackupGroupRoot");
assertThat(thrown).hasMessageThat().contains("UpdateAutoTimestampEntity");
}
@Test
@@ -66,7 +66,7 @@ class VKeyTest {
assertThrows(
IllegalArgumentException.class,
() -> VKey.create(RegistrarPoc.class, "fake@example.com"));
assertThat(thrown).hasMessageThat().contains("BackupGroupRoot");
assertThat(thrown).hasMessageThat().contains("UpdateAutoTimestampEntity");
}
@Test
@@ -1,41 +0,0 @@
// Copyright 2017 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.tools;
import static com.google.common.truth.Truth.assertWithMessage;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import google.registry.model.EntityClasses;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GetSchemaTreeCommand}. */
class GetSchemaTreeCommandTest extends CommandTestCase<GetSchemaTreeCommand> {
@Test
void testAllClassesPrintedExactlyOnce() throws Exception {
runCommand();
String stdout = getStdoutAsString();
for (Class<?> clazz : EntityClasses.ALL_CLASSES) {
String printableName = GetSchemaTreeCommand.getPrintableName(clazz);
int count = 0;
Matcher matcher = Pattern.compile("(^|\\s)" + printableName + "\\s").matcher(stdout);
while (matcher.find()) {
count++;
}
assertWithMessage(printableName + " occurences").that(count).isEqualTo(1);
}
}
}
@@ -289,7 +289,7 @@ class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase {
assertAboutImmutableObjects()
.that(updatedRegistrar)
.isEqualExceptFields(
setter.apply(registrar.asBuilder(), newValue).build(), "lastUpdateTime");
setter.apply(registrar.asBuilder(), newValue).build(), "updateTimestamp");
// We increased the correct metric
assertMetric(CLIENT_ID, "update", String.format("[%s]", role), "SUCCESS");
}
@@ -61,7 +61,7 @@ class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
assertThat(response).containsEntry("results", ImmutableList.of(modifiedJsonMap));
assertAboutImmutableObjects()
.that(loadRegistrar(CLIENT_ID))
.isEqualExceptFields(modified, "lastUpdateTime");
.isEqualExceptFields(modified, "updateTimestamp");
assertMetric(CLIENT_ID, "update", "[OWNER]", "SUCCESS");
verifyNotificationEmailsSent();
}