Add logging to CursorDao.saveCursor (#486)

* Add log messages

* small fix

* add null check

* change to checkArgumentNotNull
This commit is contained in:
sarahcaseybot 2020-02-21 15:49:45 -05:00 committed by GitHub
parent 1be0ad885c
commit cbe216ced2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 23 deletions

View file

@ -19,6 +19,7 @@ import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -95,11 +96,14 @@ public class CursorDao {
public static void saveCursor(google.registry.model.common.Cursor cursor, String scope) { public static void saveCursor(google.registry.model.common.Cursor cursor, String scope) {
tm().transact(() -> ofy().save().entity(cursor)); tm().transact(() -> ofy().save().entity(cursor));
CursorType type = cursor.getType(); CursorType type = cursor.getType();
try { checkArgumentNotNull(scope, "The scope of the cursor cannot be null");
Cursor cloudSqlCursor = Cursor.create(type, scope, cursor.getCursorTime()); Cursor cloudSqlCursor = Cursor.create(type, scope, cursor.getCursorTime());
try {
save(cloudSqlCursor); save(cloudSqlCursor);
logger.atInfo().log(
"Rolled forward CloudSQL cursor for %s to %s.", scope, cursor.getCursorTime());
} catch (Exception e) { } catch (Exception e) {
logger.atSevere().withCause(e).log("Error saving cursor to Cloud SQL."); logger.atSevere().withCause(e).log("Error saving cursor to Cloud SQL: %s.", cloudSqlCursor);
} }
} }

View file

@ -190,27 +190,6 @@ public class CursorDaoTest {
assertThat(cursor).isEqualTo(dataStoreCursor); assertThat(cursor).isEqualTo(dataStoreCursor);
} }
@Test
public void saveCursor_logsErrorWhenSaveToCloudSqlFails() {
loggerToIntercept.addHandler(logHandler);
createTld("tld");
google.registry.model.common.Cursor cursor =
google.registry.model.common.Cursor.create(
CursorType.ICANN_UPLOAD_ACTIVITY, fakeClock.nowUtc(), Registry.get("tld"));
CursorDao.saveCursor(cursor, null);
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.SEVERE, "Error saving cursor to Cloud SQL.");
google.registry.model.common.Cursor dataStoreCursor =
ofy()
.load()
.key(
google.registry.model.common.Cursor.createKey(
CursorType.ICANN_UPLOAD_ACTIVITY, Registry.get("tld")))
.now();
assertThat(cursor).isEqualTo(dataStoreCursor);
}
@Test @Test
public void saveCursors_worksSuccessfully() { public void saveCursors_worksSuccessfully() {
createTlds("tld", "foo"); createTlds("tld", "foo");