Relax reserved list existence check to allow Cloud SQL migration (#429)

This commit is contained in:
Shicong Huang 2020-01-15 13:10:50 -05:00 committed by GitHub
parent 9f9acb9980
commit d28debf149
2 changed files with 15 additions and 8 deletions

View file

@ -62,10 +62,16 @@ final class UpdateReservedListCommand extends CreateOrUpdateReservedListCommand
jpaTm()
.transact(
() -> {
checkArgument(
ReservedListDao.checkExists(cloudSqlReservedList.getName()),
"A reserved list of this name doesn't exist: %s.",
cloudSqlReservedList.getName());
// This check is currently disabled because, during the Cloud SQL migration, we need
// to be able to update reserved lists in Datastore while simultaneously creating
// their first revision in Cloud SQL (i.e. if they haven't been migrated over yet).
// TODO(shicong): Re-instate this once all reserved lists are migrated to Cloud SQL,
// and add a unit test to verity that an exception will be thrown if
// the reserved list doesn't exist.
// checkArgument(
// ReservedListDao.checkExists(cloudSqlReservedList.getName()),
// "A reserved list of this name doesn't exist: %s.",
// cloudSqlReservedList.getName());
ReservedListDao.save(cloudSqlReservedList);
});
}

View file

@ -123,13 +123,14 @@ public class UpdateReservedListCommandTest extends
}
@Test
public void testSaveToCloudSql_noExceptionThrownWhenSaveFail() throws Exception {
// Note that, during the dual-write phase, we want to make sure that no exception will be
// thrown if saving reserved list to Cloud SQL fails.
public void testSaveToCloudSql_succeedsEvenPreviousListNotExist() throws Exception {
// Note that, during the dual-write phase, we just always save the revered list to
// Cloud SQL (if --also_cloud_sql is set) without checking if there is a list with
// same name. This is to backfill the existing list in Datastore when we update it.
populateInitialReservedListInDatastore(true);
runCommandForced(
"--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath, "--also_cloud_sql");
verifyXnq9jyb4cInDatastore();
assertThat(ReservedListDao.checkExists("xn--q9jyb4c_common-reserved")).isFalse();
assertThat(ReservedListDao.checkExists("xn--q9jyb4c_common-reserved")).isTrue();
}
}