Specify explicit ofyTm usage in SetDatabaseTransitionScheduleCommand (#1081)

* Specify explicit ofyTm usage in SetDatabaseTransitionScheduleCommand

We cannot use the standard MutatingCommand because the DB schedule is
explicitly always stored in Datastore, and once we transition to
SQL-as-primary, MutatingCommand will stage the entity changes to SQL.

In addition, we remove the raw ofy() call from the test.
This commit is contained in:
gbrodman 2021-04-15 11:59:04 -04:00 committed by GitHub
parent fbef643488
commit 1cc8af4acd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 15 deletions

View file

@ -16,7 +16,6 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.ofyTm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -24,12 +23,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.truth.Truth8;
import com.googlecode.objectify.Key;
import google.registry.model.common.DatabaseTransitionSchedule;
import google.registry.model.common.DatabaseTransitionSchedule.PrimaryDatabase;
import google.registry.model.common.DatabaseTransitionSchedule.PrimaryDatabaseTransition;
import google.registry.model.common.DatabaseTransitionSchedule.TransitionId;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.persistence.VKey;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
@ -39,11 +40,8 @@ import org.junit.jupiter.api.Test;
public class SetDatabaseTransitionScheduleCommandTest
extends CommandTestCase<SetDatabaseTransitionScheduleCommand> {
Key<DatabaseTransitionSchedule> key;
@BeforeEach
void setup() {
key = Key.create(getCrossTldKey(), DatabaseTransitionSchedule.class, "test");
fakeClock.setTo(DateTime.parse("2020-12-01T00:00:00Z"));
}
@ -58,7 +56,13 @@ public class SetDatabaseTransitionScheduleCommandTest
@Test
void testSuccess_currentScheduleIsEmpty() throws Exception {
assertThat(ofy().load().key(key).now()).isNull();
Truth8.assertThat(
ofyTm()
.loadByKeyIfPresent(
VKey.createOfy(
DatabaseTransitionSchedule.class,
Key.create(getCrossTldKey(), DatabaseTransitionSchedule.class, "test"))))
.isEmpty();
runCommandForced(
"--transition_id=SIGNED_MARK_REVOCATION_LIST",
"--transition_schedule=1970-01-01T00:00:00.000Z=DATASTORE");
@ -70,7 +74,10 @@ public class SetDatabaseTransitionScheduleCommandTest
.get()
.getPrimaryDatabase()))
.isEqualTo(PrimaryDatabase.DATASTORE);
assertThat(command.prompt()).contains("Create DatabaseTransitionSchedule");
assertThat(command.prompt())
.isEqualTo(
"Insert new schedule {1970-01-01T00:00:00.000Z=DATASTORE} "
+ "for transition ID SIGNED_MARK_REVOCATION_LIST?");
}
@Test
@ -92,7 +99,8 @@ public class SetDatabaseTransitionScheduleCommandTest
.isEqualTo(transitionMap);
runCommandForced(
"--transition_id=SIGNED_MARK_REVOCATION_LIST",
"--transition_schedule=1970-01-01T00:00:00.000Z=DATASTORE,2020-11-30T00:00:00.000Z=CLOUD_SQL,2020-12-06T00:00:00.000Z=DATASTORE");
"--transition_schedule=1970-01-01T00:00:00.000Z=DATASTORE,"
+ "2020-11-30T00:00:00.000Z=CLOUD_SQL,2020-12-06T00:00:00.000Z=DATASTORE");
ImmutableSortedMap<DateTime, PrimaryDatabase> retrievedTransitionMap =
ofyTm()
.transact(
@ -117,6 +125,10 @@ public class SetDatabaseTransitionScheduleCommandTest
.get()
.getPrimaryDatabase()))
.isEqualTo(PrimaryDatabase.DATASTORE);
assertThat(command.prompt()).contains("Update DatabaseTransitionSchedule");
assertThat(command.prompt())
.isEqualTo(
"Insert new schedule {1970-01-01T00:00:00.000Z=DATASTORE, "
+ "2020-11-30T00:00:00.000Z=CLOUD_SQL, 2020-12-06T00:00:00.000Z=DATASTORE} "
+ "for transition ID SIGNED_MARK_REVOCATION_LIST?");
}
}