diff --git a/core/src/main/java/google/registry/tools/ListCursorsCommand.java b/core/src/main/java/google/registry/tools/ListCursorsCommand.java index 1b0ea6154..a36080ff8 100644 --- a/core/src/main/java/google/registry/tools/ListCursorsCommand.java +++ b/core/src/main/java/google/registry/tools/ListCursorsCommand.java @@ -51,31 +51,31 @@ final class ListCursorsCommand implements CommandWithRemoteApi { @Override public void run() { - Map> registries = - Registries.getTlds().stream() - .map(Registry::get) - .filter(r -> r.getTldType() == filterTldType) - .filter(r -> !filterEscrowEnabled || r.getEscrowEnabled()) - .collect(toImmutableMap(r -> r, r -> Cursor.createScopedVKey(cursorType, r))); + Map> cursorKeys = + cursorType.isScoped() + ? Registries.getTlds().stream() + .map(Registry::get) + .filter(r -> r.getTldType() == filterTldType) + .filter(r -> !filterEscrowEnabled || r.getEscrowEnabled()) + .collect( + toImmutableMap(r -> r.getTldStr(), r -> Cursor.createScopedVKey(cursorType, r))) + : ImmutableMap.of(cursorType.name(), Cursor.createGlobalVKey(cursorType)); ImmutableMap, Cursor> cursors = - tm().transact(() -> tm().loadByKeysIfPresent(registries.values())); - if (!registries.isEmpty()) { + tm().transact(() -> tm().loadByKeysIfPresent(cursorKeys.values())); + if (!cursorKeys.isEmpty()) { String header = String.format(OUTPUT_FMT, "TLD", "Cursor Time", "Last Update Time"); System.out.printf("%s\n%s\n", header, Strings.repeat("-", header.length())); - registries.entrySet().stream() - .map( - e -> - renderLine( - e.getKey().getTldStr(), Optional.ofNullable(cursors.get(e.getValue())))) + cursorKeys.entrySet().stream() + .map(e -> renderLine(e.getKey(), Optional.ofNullable(cursors.get(e.getValue())))) .sorted() .forEach(System.out::println); } } - private static String renderLine(String tld, Optional cursor) { + private static String renderLine(String name, Optional cursor) { return String.format( OUTPUT_FMT, - tld, + name, cursor.map(c -> c.getCursorTime().toString()).orElse("(absent)"), cursor.map(c -> c.getLastUpdateTime().toString()).orElse("(absent)")); } diff --git a/core/src/test/java/google/registry/tools/ListCursorsCommandTest.java b/core/src/test/java/google/registry/tools/ListCursorsCommandTest.java index 102dcb17e..c43bb9756 100644 --- a/core/src/test/java/google/registry/tools/ListCursorsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListCursorsCommandTest.java @@ -15,6 +15,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTlds; import static google.registry.testing.DatabaseHelper.persistResource; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -41,6 +42,12 @@ public class ListCursorsCommandTest extends CommandTestCase fakeClock.setTo(DateTime.parse("1984-12-21T06:07:08.789Z")); } + @Test + void testlistCursors_globalScoped() throws Exception { + createTld("com"); + runCommand("--type=RECURRING_BILLING"); + } + @Test void testListCursors_noTlds_printsNothing() throws Exception { runCommand("--type=BRDA");