Add non-SQL removal code for Transaction and SqlReplayCheckpoint (#1700)

This commit is contained in:
gbrodman
2022-07-07 14:36:01 -04:00
committed by GitHub
parent 9a2fb6f8b4
commit 2a5b427a80
19 changed files with 10 additions and 438 deletions
@@ -34,8 +34,6 @@ import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex;
import google.registry.model.poll.PollMessage;
import google.registry.model.rde.RdeRevision;
import google.registry.model.registrar.Registrar;
import google.registry.model.replay.LastSqlTransaction;
import google.registry.model.replay.ReplayGap;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.server.Lock;
import google.registry.model.server.ServerSecret;
@@ -64,10 +62,8 @@ public class ClassPathManagerTest {
assertThat(ClassPathManager.getClass("HostResource")).isEqualTo(HostResource.class);
assertThat(ClassPathManager.getClass("Recurring")).isEqualTo(Recurring.class);
assertThat(ClassPathManager.getClass("Registrar")).isEqualTo(Registrar.class);
assertThat(ClassPathManager.getClass("ReplayGap")).isEqualTo(ReplayGap.class);
assertThat(ClassPathManager.getClass("ContactResource")).isEqualTo(ContactResource.class);
assertThat(ClassPathManager.getClass("Cancellation")).isEqualTo(Cancellation.class);
assertThat(ClassPathManager.getClass("LastSqlTransaction")).isEqualTo(LastSqlTransaction.class);
assertThat(ClassPathManager.getClass("GaeUserIdConverter")).isEqualTo(GaeUserIdConverter.class);
assertThat(ClassPathManager.getClass("EppResourceIndexBucket"))
.isEqualTo(EppResourceIndexBucket.class);
@@ -121,11 +117,8 @@ public class ClassPathManagerTest {
assertThat(ClassPathManager.getClassName(HostResource.class)).isEqualTo("HostResource");
assertThat(ClassPathManager.getClassName(Recurring.class)).isEqualTo("Recurring");
assertThat(ClassPathManager.getClassName(Registrar.class)).isEqualTo("Registrar");
assertThat(ClassPathManager.getClassName(ReplayGap.class)).isEqualTo("ReplayGap");
assertThat(ClassPathManager.getClassName(ContactResource.class)).isEqualTo("ContactResource");
assertThat(ClassPathManager.getClassName(Cancellation.class)).isEqualTo("Cancellation");
assertThat(ClassPathManager.getClassName(LastSqlTransaction.class))
.isEqualTo("LastSqlTransaction");
assertThat(ClassPathManager.getClassName(GaeUserIdConverter.class))
.isEqualTo("GaeUserIdConverter");
assertThat(ClassPathManager.getClassName(EppResourceIndexBucket.class))
@@ -1,60 +0,0 @@
// Copyright 2020 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.model.replay;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import google.registry.model.EntityTestCase;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
/** Tests for {@link SqlReplayCheckpoint}. */
public class SqlReplayCheckpointTest extends EntityTestCase {
SqlReplayCheckpointTest() {
super(JpaEntityCoverageCheck.ENABLED);
}
@Test
void testEmpty_startOfTime() {
assertThat(jpaTm().transact(SqlReplayCheckpoint::get)).isEqualTo(START_OF_TIME);
}
@Test
void testSuccess_writes() {
DateTime dateTime = DateTime.parse("2012-02-29T00:00:00Z");
jpaTm().transact(() -> SqlReplayCheckpoint.set(dateTime));
assertThat(jpaTm().transact(SqlReplayCheckpoint::get)).isEqualTo(dateTime);
}
@Test
void testSuccess_multipleWrites() {
DateTime firstTime = DateTime.parse("2012-02-29T00:00:00Z");
jpaTm().transact(() -> SqlReplayCheckpoint.set(firstTime));
DateTime secondTime = DateTime.parse("2013-02-28T00:00:00Z");
jpaTm().transact(() -> SqlReplayCheckpoint.set(secondTime));
assertThat(jpaTm().transact(SqlReplayCheckpoint::get)).isEqualTo(secondTime);
jpaTm()
.transact(
() ->
assertThat(
jpaTm()
.query("SELECT COUNT(*) FROM SqlReplayCheckpoint", Long.class)
.getSingleResult())
.isEqualTo(1L));
}
}
@@ -45,9 +45,7 @@ public class JpaEntityCoverageExtension implements BeforeEachCallback, AfterEach
// needs to remove it in order to avoid affecting any other tests running in the same JVM.
// TODO(gbrodman): remove this when we implement proper read-only modes for the
// transaction managers.
"DatabaseMigrationStateSchedule",
// TransactionEntity is trivial; its persistence is tested in TransactionTest.
"TransactionEntity");
"DatabaseMigrationStateSchedule");
public static final ImmutableSet<Class<?>> ALL_JPA_ENTITIES =
PersistenceXmlUtility.getManagedClasses().stream()
@@ -26,7 +26,6 @@ import google.registry.model.history.DomainHistoryTest;
import google.registry.model.history.HostHistoryTest;
import google.registry.model.poll.PollMessageTest;
import google.registry.model.rde.RdeRevisionTest;
import google.registry.model.replay.SqlReplayCheckpointTest;
import google.registry.model.reporting.Spec11ThreatMatchTest;
import google.registry.model.server.LockTest;
import google.registry.model.server.ServerSecretTest;
@@ -99,7 +98,6 @@ import org.junit.runner.RunWith;
ServerSecretTest.class,
SignedMarkRevocationListDaoTest.class,
Spec11ThreatMatchTest.class,
SqlReplayCheckpointTest.class,
TmchCrlTest.class,
// AfterSuiteTest must be the last entry. See class javadoc for details.
AfterSuiteTest.class
@@ -1,42 +0,0 @@
// Copyright 2020 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.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.junit.Assert.assertThrows;
import google.registry.model.replay.SqlReplayCheckpoint;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
class SetSqlReplayCheckpointCommandTest extends CommandTestCase<SetSqlReplayCheckpointCommand> {
@Test
void testSuccess() throws Exception {
assertThat(jpaTm().transact(SqlReplayCheckpoint::get)).isEqualTo(START_OF_TIME);
DateTime timeToSet = DateTime.parse("2000-06-06T22:00:00.0Z");
runCommandForced(timeToSet.toString());
assertThat(jpaTm().transact(SqlReplayCheckpoint::get)).isEqualTo(timeToSet);
}
@Test
void testFailure_multipleParams() {
DateTime one = DateTime.parse("2000-06-06T22:00:00.0Z");
DateTime two = DateTime.parse("2001-06-06T22:00:00.0Z");
assertThrows(IllegalArgumentException.class, () -> runCommand(one.toString(), two.toString()));
}
}
@@ -9,7 +9,6 @@ ForeignKeyDomainIndex
ForeignKeyHostIndex
HistoryEntry
HostResource
LastSqlTransaction
Modification
OneTime
PollMessage
@@ -553,14 +553,6 @@ class google.registry.model.registrar.RegistrarAddress {
java.lang.String zip;
java.util.List<java.lang.String> street;
}
class google.registry.model.replay.LastSqlTransaction {
@Id long id;
long transactionId;
}
class google.registry.model.replay.ReplayGap {
@Id long transactionId;
org.joda.time.DateTime timestamp;
}
class google.registry.model.reporting.DomainTransactionRecord {
google.registry.model.reporting.DomainTransactionRecord$TransactionReportField reportField;
java.lang.Integer reportAmount;