diff --git a/build.gradle b/build.gradle index 85f27bd7..4c2552d7 100644 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ subprojects { } } - tasks.named('test') { + tasks.withType(Test).configureEach { useJUnitPlatform() testLogging { showExceptions = true diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableArgs.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableArgs.java index c534b579..dd3fd3ff 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableArgs.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableArgs.java @@ -38,13 +38,13 @@ private ClusterTableGetArgs(String keyspace, String table, boolean withTableDesc public static class ClusterTableListArgs { private String keyspace; - private int limit = 50; + private int pageSize = 50; private String nextPageState; @Builder - private ClusterTableListArgs(String keyspace, int limit, String nextPageState) { + private ClusterTableListArgs(String keyspace, int pageSize, String nextPageState) { this.keyspace = keyspace; - this.limit = limit; + this.pageSize = pageSize; this.nextPageState = nextPageState; } diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommander.java index 0f0a8537..2a5a9197 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommander.java @@ -7,16 +7,18 @@ import com.datastax.oss.protocol.internal.util.Bytes; import io.micrometer.common.util.StringUtils; import kr.hakdang.cassdio.core.domain.cluster.BaseClusterCommander; -import kr.hakdang.cassdio.core.domain.cluster.keyspace.CassandraSystemKeyspace; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.ClusterTableArgs.ClusterTableListArgs; -import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.CassandraSystemTablesColumn; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; +import static kr.hakdang.cassdio.core.domain.cluster.keyspace.CassandraSystemKeyspace.SYSTEM_SCHEMA; +import static kr.hakdang.cassdio.core.domain.cluster.keyspace.table.CassandraSystemTable.SYSTEM_SCHEMA_TABLES; +import static kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.CassandraSystemTablesColumn.TABLES_KEYSPACE_NAME; /** * ClusterTableListCommander @@ -30,16 +32,17 @@ public class ClusterTableListCommander extends BaseClusterCommander { public ClusterTableListResult listTables(CqlSession session, ClusterTableListArgs args) { SimpleStatement statement = QueryBuilder - .selectFrom(CassandraSystemKeyspace.SYSTEM_SCHEMA.getKeyspaceName(), CassandraSystemTable.SYSTEM_SCHEMA_TABLES.getTableName()) + .selectFrom(SYSTEM_SCHEMA.getKeyspaceName(), SYSTEM_SCHEMA_TABLES.getTableName()) .all() - .whereColumn(CassandraSystemTablesColumn.TABLES_KEYSPACE_NAME.getColumnName()).isEqualTo(bindMarker()) - .limit(args.getLimit()) + .whereColumn(TABLES_KEYSPACE_NAME.getColumnName()).isEqualTo(bindMarker()) .build(args.getKeyspace()) + .setPageSize(args.getPageSize()) .setPagingState(StringUtils.isBlank(args.getNextPageState()) ? null : Bytes.fromHexString(args.getNextPageState())); ResultSet rs = session.execute(statement); - List tables = rs.all().stream() + List tables = StreamSupport.stream(rs.spliterator(), false) + .limit(rs.getAvailableWithoutFetching()) .map(ClusterTable::from) .collect(Collectors.toList()); diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommanderTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommanderTest.java index 7e1460b5..51317e5c 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommanderTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommanderTest.java @@ -25,7 +25,7 @@ class ClusterTableGetCommanderTest extends IntegrationTest { private ClusterTableGetCommander clusterTableGetCommander; @Test - void getTable() { + void get_table_in_keyspace() { // given ClusterTableGetArgs args = ClusterTableGetArgs.builder() .keyspace(keyspaceName) @@ -71,7 +71,7 @@ void getTable() { } @Test - void not_exists_table() { + void when_get_not_exists_table_throw_not_exists_exception() { // given ClusterTableGetArgs args = ClusterTableGetArgs.builder() .keyspace(keyspaceName) diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java index 631bfd1b..d810a6a4 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableListCommanderTest.java @@ -20,11 +20,11 @@ public class ClusterTableListCommanderTest extends IntegrationTest { private ClusterTableListCommander clusterTableListCommander; @Test - void listTables() { + void list_tables() { // given ClusterTableArgs.ClusterTableListArgs args = ClusterTableArgs.ClusterTableListArgs.builder() .keyspace(keyspaceName) - .limit(50) + .pageSize(50) .build(); // when @@ -46,7 +46,7 @@ void listTables_with_limit() { // given ClusterTableArgs.ClusterTableListArgs args = ClusterTableArgs.ClusterTableListArgs.builder() .keyspace(keyspaceName) - .limit(1) + .pageSize(1) .build(); // when @@ -57,6 +57,22 @@ void listTables_with_limit() { assertThat(sut.getTables().getFirst().getTableName()).isEqualTo("test_table_1"); assertThat(sut.getTables().getFirst().getComment()).isEqualTo("test_table_one"); assertThat(sut.getTables().getFirst().getOptions()).containsEntry("bloom_filter_fp_chance", 0.01); + assertThat(sut.getNextPageState()).isNotBlank(); + } + + @Test + void when_empty_table_in_keyspace_result_empty() { + // given + ClusterTableArgs.ClusterTableListArgs args = ClusterTableArgs.ClusterTableListArgs.builder() + .keyspace("empty_table_keyspace") + .build(); + + // when + ClusterTableListResult sut = clusterTableListCommander.listTables(makeSession(), args); + + // then + assertThat(sut.getTables()).isEmpty(); + assertThat(sut.getNextPageState()).isNull(); } } diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableOptionTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableOptionTest.java index 0a2e2edd..447ff4ec 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableOptionTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableOptionTest.java @@ -20,7 +20,7 @@ class ClusterTableOptionTest extends IntegrationTest { @Test - void extra_table_options() { + void extract_table_option() { // given SimpleStatement statement = QueryBuilder .selectFrom(CassandraSystemKeyspace.SYSTEM_SCHEMA.getKeyspaceName(), CassandraSystemTable.SYSTEM_SCHEMA_TABLES.getTableName()) diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/keyspace/table/ClusterTableReader.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/keyspace/table/ClusterTableReader.java index 17246cdf..acf0f1cb 100644 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/keyspace/table/ClusterTableReader.java +++ b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/route/cluster/keyspace/table/ClusterTableReader.java @@ -41,7 +41,7 @@ public ItemListWithCursorResponse listTables(String cluste try (CqlSession session = tempClusterConnector.makeSession(clusterId, keyspace)) { ClusterTableListResult result = clusterTableListCommander.listTables(session, ClusterTableListArgs.builder() .keyspace(keyspace) - .limit(cursorRequest.getSize()) + .pageSize(cursorRequest.getSize()) .nextPageState(cursorRequest.getCursor()) .build());