From c367937bab48a3ee1f6962f143d739f9a11845aa Mon Sep 17 00:00:00 2001 From: Seungho Date: Sun, 7 Jul 2024 10:06:02 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B3=B4=EA=B0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hakdang/cassdio/common/BaseException.java | 20 ------ .../cassdio/common/error/BaseException.java | 38 ++++++++++++ .../cassdio/common/{ => error}/ErrorCode.java | 5 +- .../cassdio/common/{ => utils}/Jsons.java | 2 +- .../core/domain/cluster/ClusterException.java | 23 +++++++ .../cluster/ClusterNodeGetCommander.java | 3 +- .../core/domain/cluster/ClusterUtils.java | 7 +-- .../cluster/info/ClusterInfoManager.java | 2 +- .../cluster/info/ClusterInfoProvider.java | 2 +- .../keyspace/CassandraSystemKeyspace.java | 17 +++++- .../keyspace/ClusterKeyspaceException.java | 23 +++++++ .../keyspace/table/ClusterTableException.java | 22 +++++++ .../table/ClusterTableGetCommander.java | 8 ++- .../table/ClusterTableGetResult2.java | 4 +- .../table/ClusterTablePureSelectArgs.java | 8 --- .../cluster/ClusterNodeGetCommanderTest.java | 3 +- .../ClusterQueryCommanderArgsTest.java | 61 +++++++++++++++++++ .../keyspace/CassandraSystemKeyspaceTest.java | 8 +++ .../table/ClusterTableGetCommanderTest.java | 34 +++++++++++ cassdio-web/http/cluster/table/table.http | 4 +- .../web/common/dto/request/CursorRequest.java | 4 ++ .../web/common/dto/response/ApiResponse.java | 2 +- .../web/config/ControllerExceptionAdvice.java | 6 +- .../cassdio/web/config/JsonConfig.java | 2 +- 24 files changed, 253 insertions(+), 55 deletions(-) delete mode 100644 cassdio-core/src/main/java/kr/hakdang/cassdio/common/BaseException.java create mode 100644 cassdio-core/src/main/java/kr/hakdang/cassdio/common/error/BaseException.java rename cassdio-core/src/main/java/kr/hakdang/cassdio/common/{ => error}/ErrorCode.java (64%) rename cassdio-core/src/main/java/kr/hakdang/cassdio/common/{ => utils}/Jsons.java (96%) create mode 100644 cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterException.java create mode 100644 cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/ClusterKeyspaceException.java create mode 100644 cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableException.java delete mode 100644 cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTablePureSelectArgs.java create mode 100644 cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterQueryCommanderArgsTest.java diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/common/BaseException.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/common/BaseException.java deleted file mode 100644 index 10deb0e5..00000000 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/common/BaseException.java +++ /dev/null @@ -1,20 +0,0 @@ -package kr.hakdang.cassdio.common; - -import lombok.Getter; - -@Getter -public abstract class BaseException extends RuntimeException { - - private final ErrorCode errorCode; - - protected BaseException(String message, ErrorCode errorCode) { - super(message); - this.errorCode = errorCode; - } - - protected BaseException(String message, ErrorCode errorCode, Throwable cause) { - super(message, cause); - this.errorCode = errorCode; - } - -} diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/common/error/BaseException.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/common/error/BaseException.java new file mode 100644 index 00000000..2aea16f7 --- /dev/null +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/common/error/BaseException.java @@ -0,0 +1,38 @@ +package kr.hakdang.cassdio.common.error; + +import lombok.Getter; + +import java.util.Collections; +import java.util.List; + +@Getter +public abstract class BaseException extends RuntimeException { + + private final ErrorCode errorCode; + private final List reasons; + + protected BaseException(String message, ErrorCode errorCode) { + super(message); + this.errorCode = errorCode; + this.reasons = Collections.emptyList(); + } + + protected BaseException(String message, ErrorCode errorCode, Throwable cause) { + super(message, cause); + this.errorCode = errorCode; + this.reasons = Collections.emptyList(); + } + + protected BaseException(String message, ErrorCode errorCode, List reasons) { + super(message); + this.errorCode = errorCode; + this.reasons = reasons; + } + + protected BaseException(String message, ErrorCode errorCode, Throwable cause, List reasons) { + super(message, cause); + this.errorCode = errorCode; + this.reasons = reasons; + } + +} diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/common/ErrorCode.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/common/error/ErrorCode.java similarity index 64% rename from cassdio-core/src/main/java/kr/hakdang/cassdio/common/ErrorCode.java rename to cassdio-core/src/main/java/kr/hakdang/cassdio/common/error/ErrorCode.java index b44fd445..3d2a5b96 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/common/ErrorCode.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/common/error/ErrorCode.java @@ -1,4 +1,4 @@ -package kr.hakdang.cassdio.common; +package kr.hakdang.cassdio.common.error; import lombok.Getter; @@ -6,6 +6,9 @@ public enum ErrorCode { E400_INVALID_PARAMETER(400, "invalid_parameter"), + E404_NOT_FOUND_CLUSTER_NODE(404, "not_exists_node"), + E404_NOT_FOUND_KEYSPACE(404, "not_exists_keyspace"), + E404_NOT_FOUND_TABLE(404, "not_exists_table"), E500_INTERNAL_SERVER_ERROR(500, "internal_server_error"), ; diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/common/Jsons.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/common/utils/Jsons.java similarity index 96% rename from cassdio-core/src/main/java/kr/hakdang/cassdio/common/Jsons.java rename to cassdio-core/src/main/java/kr/hakdang/cassdio/common/utils/Jsons.java index f3e2a5d7..f743570b 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/common/Jsons.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/common/utils/Jsons.java @@ -1,4 +1,4 @@ -package kr.hakdang.cassdio.common; +package kr.hakdang.cassdio.common.utils; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterException.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterException.java new file mode 100644 index 00000000..c80f80eb --- /dev/null +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterException.java @@ -0,0 +1,23 @@ +package kr.hakdang.cassdio.core.domain.cluster; + +import kr.hakdang.cassdio.common.error.BaseException; +import kr.hakdang.cassdio.common.error.ErrorCode; + +/** + * ClusterException + * + * @author Seungho Kang (will.seungho@webtoonscorp.com) + * @version 1.0.0 + * @since 2024. 07. 07. + */ +public class ClusterException { + + public static class ClusterNodeNotFoundException extends BaseException { + + protected ClusterNodeNotFoundException(String message) { + super(message, ErrorCode.E404_NOT_FOUND_CLUSTER_NODE); + } + + } + +} diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommander.java index 134c0b52..4de79f3b 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommander.java @@ -2,6 +2,7 @@ import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.metadata.Node; +import kr.hakdang.cassdio.core.domain.cluster.ClusterException.ClusterNodeNotFoundException; import org.springframework.stereotype.Service; import java.util.Map; @@ -21,7 +22,7 @@ public ClusterNode getNode(CqlSession session, UUID nodeId) { Node node = nodes.get(nodeId); if (node == null) { - throw new IllegalArgumentException(String.format("not exists node(%s)", nodeId)); + throw new ClusterNodeNotFoundException(String.format("not exists node(%s)", nodeId)); } return ClusterNode.from(node); diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java index ad1268a2..21eb8960 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/ClusterUtils.java @@ -13,7 +13,6 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -49,11 +48,7 @@ public static KeyspaceFilter makeKeyspaceFilter(DriverContext context) { } public static boolean isVirtualKeyspace(DriverContext context, String keyspace) { - return !makeKeyspaceFilter(context).includes(keyspace) - && Arrays.asList( - CassandraSystemKeyspace.SYSTEM_VIRTUAL_SCHEMA.getKeyspaceName(), - CassandraSystemKeyspace.SYSTEM_VIEWS.getKeyspaceName() - ).contains(keyspace); + return !makeKeyspaceFilter(context).includes(keyspace) && CassandraSystemKeyspace.isVirtualSystemKeyspace(keyspace); } public static String generateClusterId() { diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoManager.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoManager.java index 4f05e8e1..eb9ae91d 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoManager.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoManager.java @@ -1,7 +1,7 @@ package kr.hakdang.cassdio.core.domain.cluster.info; import com.fasterxml.jackson.databind.ObjectMapper; -import kr.hakdang.cassdio.common.Jsons; +import kr.hakdang.cassdio.common.utils.Jsons; import kr.hakdang.cassdio.core.domain.cluster.ClusterUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoProvider.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoProvider.java index 1d142704..4c423698 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoProvider.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/info/ClusterInfoProvider.java @@ -1,7 +1,7 @@ package kr.hakdang.cassdio.core.domain.cluster.info; import com.fasterxml.jackson.databind.ObjectMapper; -import kr.hakdang.cassdio.common.Jsons; +import kr.hakdang.cassdio.common.utils.Jsons; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspace.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspace.java index 7c4109bb..e7631b5f 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspace.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspace.java @@ -18,14 +18,21 @@ public enum CassandraSystemKeyspace { SYSTEM_AUTH("system_auth"), SYSTEM_DISTRIBUTED("system_distributed"), SYSTEM_TRACES("system_traces"), - SYSTEM_VIEWS("system_views"), - SYSTEM_VIRTUAL_SCHEMA("system_virtual_schema"), + SYSTEM_VIEWS("system_views", true), + SYSTEM_VIRTUAL_SCHEMA("system_virtual_schema", true), ; private final String keyspaceName; + private final boolean isVirtualKeyspace; + + CassandraSystemKeyspace(String keyspaceName, boolean isVirtualKeyspace) { + this.keyspaceName = keyspaceName; + this.isVirtualKeyspace = isVirtualKeyspace; + } CassandraSystemKeyspace(String keyspaceName) { this.keyspaceName = keyspaceName; + this.isVirtualKeyspace = false; } public static boolean isSystemKeyspace(String keyspaceName) { @@ -33,4 +40,10 @@ public static boolean isSystemKeyspace(String keyspaceName) { .anyMatch(keyspace -> keyspace.getKeyspaceName().equals(keyspaceName)); } + public static boolean isVirtualSystemKeyspace(String keyspaceName) { + return Arrays.stream(CassandraSystemKeyspace.values()) + .filter(keyspace -> keyspace.isVirtualKeyspace) + .anyMatch(keyspace -> keyspace.getKeyspaceName().equals(keyspaceName)); + } + } diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/ClusterKeyspaceException.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/ClusterKeyspaceException.java new file mode 100644 index 00000000..9a0a0a0f --- /dev/null +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/ClusterKeyspaceException.java @@ -0,0 +1,23 @@ +package kr.hakdang.cassdio.core.domain.cluster.keyspace; + +import kr.hakdang.cassdio.common.error.BaseException; +import kr.hakdang.cassdio.common.error.ErrorCode; + +/** + * ClusterKeyspaceException + * + * @author Seungho Kang (will.seungho@webtoonscorp.com) + * @version 1.0.0 + * @since 2024. 07. 07. + */ +public class ClusterKeyspaceException { + + public static class ClusterKeyspaceNotFoundException extends BaseException { + + public ClusterKeyspaceNotFoundException(String message) { + super(message, ErrorCode.E404_NOT_FOUND_KEYSPACE); + } + + } + +} diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableException.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableException.java new file mode 100644 index 00000000..77069452 --- /dev/null +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableException.java @@ -0,0 +1,22 @@ +package kr.hakdang.cassdio.core.domain.cluster.keyspace.table; + +import kr.hakdang.cassdio.common.error.BaseException; +import kr.hakdang.cassdio.common.error.ErrorCode; + +/** + * ClusterTableException + * + * @author Seungho Kang (will.seungho@webtoonscorp.com) + * @version 1.0.0 + * @since 2024. 07. 07. + */ +public class ClusterTableException { + + public static class CLusterTableNotFoundException extends BaseException { + + protected CLusterTableNotFoundException(String message) { + super(message, ErrorCode.E404_NOT_FOUND_CLUSTER_NODE); + } + } + +} diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommander.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommander.java index ab817734..a432a31a 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommander.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetCommander.java @@ -7,7 +7,9 @@ import com.datastax.oss.driver.api.querybuilder.QueryBuilder; 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.ClusterKeyspaceException.ClusterKeyspaceNotFoundException; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.ClusterTableArgs.ClusterTableGetArgs; +import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.ClusterTableException.CLusterTableNotFoundException; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.CassandraSystemTablesColumn; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.Column; import org.springframework.stereotype.Service; @@ -42,15 +44,15 @@ public ClusterTableGetResult getTable(CqlSession session, ClusterTableGetArgs ar Row tableRow = session.execute(statement).one(); if (tableRow == null) { - throw new IllegalArgumentException(String.format("not found table(%s) in keyspace(%s)", args.getTable(), args.getKeyspace())); + throw new CLusterTableNotFoundException(String.format("not found table(%s) in keyspace(%s)", args.getTable(), args.getKeyspace())); } String tableDescribe = ""; if (!CassandraSystemKeyspace.isSystemKeyspace(args.getKeyspace()) && args.isWithTableDescribe()) { TableMetadata tableMetadata = session.getMetadata().getKeyspace(args.getKeyspace()) - .orElseThrow(() -> new RuntimeException("not found keyspace")) + .orElseThrow(() -> new ClusterKeyspaceNotFoundException(String.format("not found keyspace (%s)", args.getKeyspace()))) .getTable(args.getTable()) - .orElseThrow(() -> new RuntimeException("not found table")); + .orElseThrow(() -> new CLusterTableNotFoundException(String.format("not found table(%s)", args.getTable()))); tableDescribe = tableMetadata.describe(true); } diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetResult2.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetResult2.java index ad0ec420..1114a931 100644 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetResult2.java +++ b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTableGetResult2.java @@ -1,13 +1,11 @@ package kr.hakdang.cassdio.core.domain.cluster.keyspace.table; -import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.Column; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; -import java.util.List; import java.util.Map; /** @@ -25,7 +23,7 @@ public class ClusterTableGetResult2 { private Map describe; @Builder - private ClusterTableGetResult2(Map table, Map describe, List columns) { + private ClusterTableGetResult2(Map table, Map describe) { this.table = table; this.describe = describe; } diff --git a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTablePureSelectArgs.java b/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTablePureSelectArgs.java deleted file mode 100644 index f8969c9a..00000000 --- a/cassdio-core/src/main/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/table/ClusterTablePureSelectArgs.java +++ /dev/null @@ -1,8 +0,0 @@ -package kr.hakdang.cassdio.core.domain.cluster.keyspace.table; - -/** - * ClusterTablePureSelectArgs - * - * @author akageun - * @since 2024-06-30 - */ diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommanderTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommanderTest.java index bfba21ce..a5d4003a 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommanderTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterNodeGetCommanderTest.java @@ -3,6 +3,7 @@ import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.metadata.Node; import kr.hakdang.cassdio.IntegrationTest; +import kr.hakdang.cassdio.core.domain.cluster.ClusterException.ClusterNodeNotFoundException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +28,7 @@ class ClusterNodeGetCommanderTest extends IntegrationTest { void not_exists_node_in_cluster() { // when & then assertThatThrownBy(() -> clusterNodeGetCommander.getNode(makeSession(), UUID.randomUUID())) - .isInstanceOf(IllegalArgumentException.class); + .isInstanceOf(ClusterNodeNotFoundException.class); } @Test diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterQueryCommanderArgsTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterQueryCommanderArgsTest.java new file mode 100644 index 00000000..e6f2dc60 --- /dev/null +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/ClusterQueryCommanderArgsTest.java @@ -0,0 +1,61 @@ +package kr.hakdang.cassdio.core.domain.cluster; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * ClusterQueryCommanderArgsTest + * + * @author Seungho Kang (will.seungho@webtoonscorp.com) + * @version 1.0.0 + * @since 2024. 07. 07. + */ +class ClusterQueryCommanderArgsTest { + + @Test + void default_pageSize_is_50() { + // given + ClusterQueryCommanderArgs args = ClusterQueryCommanderArgs.builder().build(); + + // when + int sut = args.getPageSize(); + + // then + assertThat(sut).isEqualTo(50); + } + + @Test + void when_pageSize_is_over_500_throw_exception() { + // when & then + assertThatThrownBy(() -> + ClusterQueryCommanderArgs.builder() + .pageSize(501) + .build() + ).isInstanceOf(RuntimeException.class); + } + + @Test + void default_timeout_is_3s() { + // given + ClusterQueryCommanderArgs args = ClusterQueryCommanderArgs.builder().build(); + + // when + int sut = args.getTimeoutSeconds(); + + // then + assertThat(sut).isEqualTo(3); + } + + @Test + void when_timeout_is_over_1m_throw_exception() { + // when & then + assertThatThrownBy(() -> + ClusterQueryCommanderArgs.builder() + .timeoutSeconds(61) + .build() + ).isInstanceOf(RuntimeException.class); + } + +} diff --git a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspaceTest.java b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspaceTest.java index d57e99e7..00bb3441 100644 --- a/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspaceTest.java +++ b/cassdio-core/src/test/java/kr/hakdang/cassdio/core/domain/cluster/keyspace/CassandraSystemKeyspaceTest.java @@ -24,4 +24,12 @@ void not_system_keyspace() { assertThat(CassandraSystemKeyspace.isSystemKeyspace("demo")).isFalse(); } + @Test + void isVirtualKeyspace() { + assertThat(CassandraSystemKeyspace.isVirtualSystemKeyspace("system_virtual_schema")).isTrue(); + assertThat(CassandraSystemKeyspace.isVirtualSystemKeyspace("system_views")).isTrue(); + assertThat(CassandraSystemKeyspace.isVirtualSystemKeyspace("system_traces")).isFalse(); + assertThat(CassandraSystemKeyspace.isVirtualSystemKeyspace("demo")).isFalse(); + } + } 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 27f32a84..7e1460b5 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 @@ -2,6 +2,7 @@ import kr.hakdang.cassdio.IntegrationTest; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.ClusterTableArgs.ClusterTableGetArgs; +import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.ClusterTableException.CLusterTableNotFoundException; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.ColumnClusteringOrder; import kr.hakdang.cassdio.core.domain.cluster.keyspace.table.column.ColumnKind; import lombok.extern.slf4j.Slf4j; @@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * ClusterTableGetCommanderTest @@ -28,12 +30,15 @@ void getTable() { ClusterTableGetArgs args = ClusterTableGetArgs.builder() .keyspace(keyspaceName) .table("test_table_1") + .withTableDescribe(true) .build(); // when ClusterTableGetResult sut = clusterTableGetCommander.getTable(makeSession(), args); // then + assertThat(sut.getTableDescribe()).isNotBlank(); + assertThat(sut.getTable().getTableName()).isEqualTo("test_table_1"); assertThat(sut.getTable().getComment()).isEqualTo("test_table_one"); assertThat(sut.getTable().getOptions()).containsEntry("bloom_filter_fp_chance", 0.01); @@ -65,4 +70,33 @@ void getTable() { assertThat(sut.getColumns().get(4).getKind()).isEqualTo(ColumnKind.REGULAR); } + @Test + void not_exists_table() { + // given + ClusterTableGetArgs args = ClusterTableGetArgs.builder() + .keyspace(keyspaceName) + .table("not_exists_table") + .build(); + + // when & then + assertThatThrownBy(() -> clusterTableGetCommander.getTable(makeSession(), args)).isInstanceOf(CLusterTableNotFoundException.class); + } + + @Test + void get_system_table() { + // given + ClusterTableGetArgs args = ClusterTableGetArgs.builder() + .keyspace("system_schema") + .table("tables") + .withTableDescribe(true) + .build(); + + // when + ClusterTableGetResult sut = clusterTableGetCommander.getTable(makeSession(), args); + + // then + assertThat(sut.getTableDescribe()).isBlank(); + assertThat(sut.getTable().getTableName()).isEqualTo("tables"); + } + } diff --git a/cassdio-web/http/cluster/table/table.http b/cassdio-web/http/cluster/table/table.http index 01c3f276..b4311382 100644 --- a/cassdio-web/http/cluster/table/table.http +++ b/cassdio-web/http/cluster/table/table.http @@ -1,6 +1,6 @@ ### List Tables -GET {{api}}/api/cassandra/cluster/123/keyspaces/demodb/table?size=1 +GET {{api}}/api/cassandra/cluster/123/keyspace/demodb/table?size=100 ### Get Table -GET {{api}}/api/cassandra/cluster/123/keyspaces/demodb/table/event_history_v1 +GET {{api}}/api/cassandra/cluster/123/keyspace/demodb/table/event_history_v1 diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/request/CursorRequest.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/request/CursorRequest.java index 26de52b9..ceb636bf 100644 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/request/CursorRequest.java +++ b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/request/CursorRequest.java @@ -1,5 +1,6 @@ package kr.hakdang.cassdio.web.common.dto.request; +import jakarta.validation.constraints.Max; import kr.hakdang.cassdio.common.model.Direction; import lombok.AccessLevel; import lombok.Builder; @@ -21,7 +22,10 @@ public class CursorRequest { private String cursor = null; + + @Max(value = 100, message = "size is less than 100") private int size = 30; + private Direction direction = Direction.NEXT; @Builder diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/response/ApiResponse.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/response/ApiResponse.java index 0f60bdd0..3c44ffd5 100644 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/response/ApiResponse.java +++ b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/common/dto/response/ApiResponse.java @@ -1,7 +1,7 @@ package kr.hakdang.cassdio.web.common.dto.response; import com.fasterxml.jackson.annotation.JsonInclude; -import kr.hakdang.cassdio.common.ErrorCode; +import kr.hakdang.cassdio.common.error.ErrorCode; import lombok.AccessLevel; import lombok.EqualsAndHashCode; import lombok.Getter; diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/ControllerExceptionAdvice.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/ControllerExceptionAdvice.java index e0ffa3cf..e7f20b6c 100644 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/ControllerExceptionAdvice.java +++ b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/ControllerExceptionAdvice.java @@ -1,7 +1,7 @@ package kr.hakdang.cassdio.web.config; -import kr.hakdang.cassdio.common.BaseException; -import kr.hakdang.cassdio.common.ErrorCode; +import kr.hakdang.cassdio.common.error.BaseException; +import kr.hakdang.cassdio.common.error.ErrorCode; import kr.hakdang.cassdio.web.common.dto.response.ApiResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.context.support.DefaultMessageSourceResolvable; @@ -14,7 +14,7 @@ import java.util.List; -import static kr.hakdang.cassdio.common.ErrorCode.E400_INVALID_PARAMETER; +import static kr.hakdang.cassdio.common.error.ErrorCode.E400_INVALID_PARAMETER; @Slf4j @RestControllerAdvice diff --git a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/JsonConfig.java b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/JsonConfig.java index 38508403..537bae40 100644 --- a/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/JsonConfig.java +++ b/cassdio-web/src/main/java/kr/hakdang/cassdio/web/config/JsonConfig.java @@ -1,7 +1,7 @@ package kr.hakdang.cassdio.web.config; import com.fasterxml.jackson.databind.ObjectMapper; -import kr.hakdang.cassdio.common.Jsons; +import kr.hakdang.cassdio.common.utils.Jsons; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;