You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/06/02 02:02:54 UTC
[shardingsphere] branch master updated: Fix sonar issue on Replace tests with a single Parameterized one (#26000)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b81bf2ac9ee Fix sonar issue on Replace tests with a single Parameterized one (#26000)
b81bf2ac9ee is described below
commit b81bf2ac9ee75055559634be556ca9cf17ba5b8c
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jun 2 10:02:37 2023 +0800
Fix sonar issue on Replace tests with a single Parameterized one (#26000)
* Fix sonar issue on Replace tests with a single Parameterized one
* Fix sonar issue on HeterogeneousUpdateStatementCheckerTest
* Fix sonar issue on HeterogeneousSelectStatementCheckerTest
* Fix sonar issue on HeterogeneousInsertStatementCheckerTest
* Fix sonar issue on HeterogeneousDeleteStatementCheckerTest
* Fix sonar issue on ProxyBackendHandlerFactoryTest
---
.../handler/ProxyBackendHandlerFactoryTest.java | 63 +++---
.../HeterogeneousInsertStatementChecker.java | 8 +-
.../HeterogeneousUpdateStatementChecker.java | 2 +-
.../HeterogeneousDeleteStatementCheckerTest.java | 77 +++----
.../HeterogeneousInsertStatementCheckerTest.java | 89 ++++----
.../HeterogeneousSelectStatementCheckerTest.java | 233 ++++++---------------
.../HeterogeneousUpdateStatementCheckerTest.java | 86 +++-----
.../authenticator/MySQLAuthenticatorTypeTest.java | 55 ++---
.../OpenGaussAuthenticatorTypeTest.java | 55 ++---
.../PostgreSQLAuthenticatorTypeTest.java | 55 ++---
10 files changed, 262 insertions(+), 461 deletions(-)
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
index fc4f42371ac..c70509fed78 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
@@ -53,6 +53,11 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
@@ -63,6 +68,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
+import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -129,44 +135,9 @@ class ProxyBackendHandlerFactoryTest {
assertThat(actual, instanceOf(QueryableRALBackendHandler.class));
}
- @Test
- void assertNewInstanceWithBegin() throws SQLException {
- String sql = "BEGIN";
- ProxyBackendHandler actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
- assertThat(actual, instanceOf(TransactionBackendHandler.class));
- }
-
- @Test
- void assertNewInstanceWithStartTransaction() throws SQLException {
- String sql = "START TRANSACTION";
- ProxyBackendHandler actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
- assertThat(actual, instanceOf(TransactionBackendHandler.class));
- }
-
- @Test
- void assertNewInstanceWithSetAutoCommitToOff() throws SQLException {
- String sql = "SET AUTOCOMMIT=0";
- ProxyBackendHandler actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
- assertThat(actual, instanceOf(TransactionBackendHandler.class));
- }
-
- @Test
- void assertNewInstanceWithScopeSetAutoCommitToOff() throws SQLException {
- String sql = "SET @@SESSION.AUTOCOMMIT = OFF";
- ProxyBackendHandler actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
- assertThat(actual, instanceOf(TransactionBackendHandler.class));
- }
-
- @Test
- void assertNewInstanceWithSetAutoCommitToOn() throws SQLException {
- String sql = "SET AUTOCOMMIT=1";
- ProxyBackendHandler actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
- assertThat(actual, instanceOf(TransactionBackendHandler.class));
- }
-
- @Test
- void assertNewInstanceWithScopeSetAutoCommitToOnForInTransaction() throws SQLException {
- String sql = "SET @@SESSION.AUTOCOMMIT = ON";
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TCLTestCaseArgumentsProvider.class)
+ void assertNewInstanceWithTCL(final String sql) throws SQLException {
ProxyBackendHandler actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
assertThat(actual, instanceOf(TransactionBackendHandler.class));
}
@@ -188,7 +159,7 @@ class ProxyBackendHandlerFactoryTest {
}
// TODO
- @Disabled("FIX ME")
+ @Disabled("FIXME")
@Test
void assertNewInstanceWithQuery() throws SQLException {
String sql = "SELECT * FROM t_order limit 1";
@@ -251,4 +222,18 @@ class ProxyBackendHandlerFactoryTest {
ProxyBackendHandler actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
assertThat(actual, instanceOf(SQLRULBackendHandler.class));
}
+
+ private static class TCLTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("BEGIN"),
+ Arguments.of("START TRANSACTION"),
+ Arguments.of("SET AUTOCOMMIT=0"),
+ Arguments.of("SET @@SESSION.AUTOCOMMIT = OFF"),
+ Arguments.of("SET AUTOCOMMIT=1"),
+ Arguments.of("SET @@SESSION.AUTOCOMMIT = ON"));
+ }
+ }
}
diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementChecker.java
index a89f56a3ac2..998e82b4890 100644
--- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementChecker.java
+++ b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementChecker.java
@@ -44,10 +44,10 @@ public class HeterogeneousInsertStatementChecker extends CommonHeterogeneousSQLS
private void checkIsExistsRowKeyInInsertColumns() {
List<String> columns = getSqlStatement().getColumns().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toList());
- Preconditions.checkArgument(!columns.isEmpty(), "The inserted column must be explicitly specified");
- Preconditions.checkArgument(ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(columns.get(0))), "First column must be rowKey");
+ Preconditions.checkArgument(!columns.isEmpty(), "The inserted column must be explicitly specified.");
+ Preconditions.checkArgument(ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(columns.get(0))), "First column must be rowKey.");
boolean isExists = columns.subList(1, columns.size()).stream().anyMatch(ALLOW_KEYS::contains);
- Preconditions.checkArgument(!isExists, "Cannot contain multiple rowKey");
+ Preconditions.checkArgument(!isExists, "Cannot contain multiple rowKeys.");
}
private void checkIsExistsSubQuery() {
@@ -58,7 +58,7 @@ public class HeterogeneousInsertStatementChecker extends CommonHeterogeneousSQLS
Collection<InsertValuesSegment> values = getSqlStatement().getValues();
for (InsertValuesSegment insertValuesSegment : values) {
boolean isAllMatch = insertValuesSegment.getValues().stream().allMatch(this::isAllowExpressionSegment);
- Preconditions.checkArgument(isAllMatch, "Value must is literal or parameter marker");
+ Preconditions.checkArgument(isAllMatch, "Value must is literal or parameter marker.");
}
}
diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementChecker.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementChecker.java
index 8dd361d48f7..746c47df0a5 100644
--- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementChecker.java
+++ b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementChecker.java
@@ -49,7 +49,7 @@ public class HeterogeneousUpdateStatementChecker extends CommonHeterogeneousSQLS
private void checkAssignmentIsOk() {
Collection<AssignmentSegment> assignmentSegments = getSqlStatement().getSetAssignment().getAssignments();
for (AssignmentSegment assignmentSegment : assignmentSegments) {
- Preconditions.checkArgument(isAllowExpressionSegment(assignmentSegment.getValue()), "Assigment must is literal or parameter marker");
+ Preconditions.checkArgument(isAllowExpressionSegment(assignmentSegment.getValue()), "Assignment must is literal or parameter marker.");
boolean isRowKey = ALLOW_KEYS.stream().anyMatch(each -> each.equalsIgnoreCase(assignmentSegment.getColumns().iterator().next().getIdentifier().getValue()));
Preconditions.checkArgument(!isRowKey, "Do not allow update rowKey");
}
diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementCheckerTest.java
index c2cb3768546..fcd7d86f058 100644
--- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementCheckerTest.java
+++ b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousDeleteStatementCheckerTest.java
@@ -19,7 +19,13 @@ package org.apache.shardingsphere.proxy.backend.hbase.checker;
import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -28,57 +34,40 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class HeterogeneousDeleteStatementCheckerTest {
- @Test
- void assertExecuteDeleteStatement() {
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getDeleteStatement());
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertOperatorIsNotEqual() {
- String sql = "delete /*+ hbase */ from t_test_order where rowKey > 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only Supported `=` operator."));
- }
-
- @Test
- void assertColumnIsNotRowKey() {
- String sql = "delete /*+ hbase */ from t_test_order where age = 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("age is not a allowed key."));
- }
-
- @Test
- void assertLeftIsNotColumn() {
- String sql = "delete /*+ hbase */ from t_test_order where 1 = 1";
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(SupportedTestCaseArgumentsProvider.class)
+ void assertExecuteSuccess(final String name, final String sql) {
SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Left segment must column segment."));
+ assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
}
- @Test
- void assertMultiExpression() {
- String sql = "DELETE /*+ hbase */ FROM t_order WHERE order_id = ? AND user_id = ? AND status=?";
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class)
+ void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) {
SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported multiple expressions."));
+ assertThat(ex.getMessage(), is(expectedErrorMessage));
}
- @Test
- void assertWithBetweenExpression() {
- String sql = "DELETE /*+ hbase */ FROM t_order WHERE rowKey between 1 and 5";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only support binary operation expression."));
+ private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(Arguments.of("standard", HBaseSupportedSQLStatement.getDeleteStatement()));
+ }
}
- @Test
- void assertNotWhereSegment() {
- String sql = "DELETE /*+ hbase */ FROM t_order";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Must contain where segment."));
+ private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("operatorIsNotEqual", "delete /*+ hbase */ from t_test_order where rowKey > 1", "Only Supported `=` operator."),
+ Arguments.of("columnIsNotRowKey", "delete /*+ hbase */ from t_test_order where age = 1", "age is not a allowed key."),
+ Arguments.of("leftIsNotColumn", "delete /*+ hbase */ from t_test_order where 1 = 1", "Left segment must column segment."),
+ Arguments.of("MultipleExpressions", "DELETE /*+ hbase */ FROM t_order WHERE order_id = ? AND user_id = ? AND status=?", "Do not supported multiple expressions."),
+ Arguments.of("between", "DELETE /*+ hbase */ FROM t_order WHERE rowKey between 1 and 5", "Only support binary operation expression."),
+ Arguments.of("withoutWhere", "DELETE /*+ hbase */ FROM t_order", "Must contain where segment."));
+ }
}
}
diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementCheckerTest.java
index 60671f0817b..b6b04a28b4d 100644
--- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementCheckerTest.java
+++ b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousInsertStatementCheckerTest.java
@@ -19,7 +19,13 @@ package org.apache.shardingsphere.proxy.backend.hbase.checker;
import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -28,64 +34,45 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class HeterogeneousInsertStatementCheckerTest {
- @Test
- void assertExecuteInsertStatement() {
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getInsertStatement());
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertInsertWithoutRowKey() {
- String sql = "INSERT /*+ HBase */ INTO t_order (order_id, user_id, status) VALUES (?, ?, ?)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("First column must be rowKey"));
- }
-
- @Test
- void assertInsertWithoutColumns() {
- String sql = "INSERT /*+ HBase */ INTO t_order VALUES (?, ?, ?)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("The inserted column must be explicitly specified"));
- }
-
- @Test
- void assertInsertWithMultipleRowKey() {
- String sql = "INSERT /*+ HBase */ INTO t_order (rowKey, id, status) VALUES (?, ?, ?)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Cannot contain multiple rowKey"));
- }
-
- @Test
- void assertInsertWithOnDuplicateKey() {
- String sql = "INSERT /*+ HBase */ INTO t_order (rowKey, user_id, status) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE status = ?";
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(SupportedTestCaseArgumentsProvider.class)
+ void assertExecuteSuccess(final String name, final String sql) {
SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported ON DUPLICATE KEY UPDATE"));
+ assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
}
- @Test
- void assertInsertWithFunction() {
- String sql = "INSERT /*+ HBase */ INTO t_order_item (rowKey, order_id, user_id, status, creation_date) VALUES (?, ?, ?, 'insert', now())";
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class)
+ void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) {
SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Value must is literal or parameter marker"));
+ assertThat(ex.getMessage(), is(expectedErrorMessage));
}
- @Test
- void assertInsertWithLiteralAndParameterMarker() {
- String sql = "INSERT /*+ HBase */ INTO t_order_item(rowKey, order_id, user_id, status, creation_date) VALUES (?, ?, ?, 'insert', '2017-08-08')";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
+ private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(Arguments.of(
+ "standard", HBaseSupportedSQLStatement.getInsertStatement(),
+ "literalAndParameterMarker", "INSERT /*+ HBase */ INTO t_order_item(rowKey, order_id, user_id, status, creation_date) VALUES (?, ?, ?, 'insert', '2017-08-08')"));
+ }
}
- @Test
- void assertInsertWithSubQuery() {
- String sql = "INSERT /*+ HBase */ INTO t_order_item(rowKey, order_id, user_id) select rowKey, order_id, user_id from t_order";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported `insert into...select...`"));
+ private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("withoutRowKey", "INSERT /*+ HBase */ INTO t_order (order_id, user_id, status) VALUES (?, ?, ?)", "First column must be rowKey."),
+ Arguments.of("withoutColumns", "INSERT /*+ HBase */ INTO t_order VALUES (?, ?, ?)", "The inserted column must be explicitly specified."),
+ Arguments.of("withMultipleRowKey", "INSERT /*+ HBase */ INTO t_order (rowKey, id, status) VALUES (?, ?, ?)", "Cannot contain multiple rowKeys."),
+ Arguments.of("onDuplicateKey",
+ "INSERT /*+ HBase */ INTO t_order (rowKey, user_id, status) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE status = ?", "Do not supported ON DUPLICATE KEY UPDATE"),
+ Arguments.of("function",
+ "INSERT /*+ HBase */ INTO t_order_item (rowKey, order_id, user_id, status, creation_date) VALUES (?, ?, ?, 'insert', now())", "Value must is literal or parameter marker."),
+ Arguments.of("subQuery",
+ "INSERT /*+ HBase */ INTO t_order_item(rowKey, order_id, user_id) select rowKey, order_id, user_id from t_order", "Do not supported `insert into...select...`"));
+ }
}
}
diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementCheckerTest.java
index 771e44959b2..496f8644784 100644
--- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementCheckerTest.java
+++ b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousSelectStatementCheckerTest.java
@@ -23,7 +23,13 @@ import org.apache.shardingsphere.proxy.backend.hbase.props.HBasePropertyKey;
import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -41,178 +47,57 @@ class HeterogeneousSelectStatementCheckerTest {
HBaseContext.getInstance().setProps(props);
}
- @Test
- void assertSelectStatement() {
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getSelectStatement());
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertSelectStatementWithLargeRowCount() {
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement("SELECT /*+ hbase */ * FROM t_order WHERE id = 1 LIMIT 5001");
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Row count must less than 5000."));
- }
-
- @Test
- void assertSelectStatementWithLimitSegment() {
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement("SELECT /*+ hbase */ * FROM t_order WHERE id = 1 LIMIT 5 OFFSET 3");
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported offset segment."));
- }
-
- @Test
- void assertSelectStatementWithLockSegment() {
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement("SELECT /*+ hbase */ * FROM t_order WHERE id = 1 lock in share mode");
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported lock segment."));
- }
-
- @Test
- void assertSelectStatementWithFunction() {
- String sql = "SELECT /*+ HBase */ sum(score) FROM person";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only supported shorthand, column and crc32 expression projections."));
- }
-
- @Test
- void assertSelectStatementWithJoinStatement() {
- String sql = "SELECT /*+ HBase */ * FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only supported simple table segment."));
- }
-
- @Test
- void assertSelectStatementWithMultipleInExpression() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (?, ?) AND id IN (?, ?)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Left segment must column segment."));
- }
-
- @Test
- void assertSelectStatementWithInExpression() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (1, 2, 3)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertSelectStatementWithErrorKey() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE age IN (1, 2, 3)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("age is not a allowed key."));
- }
-
- @Test
- void assertExecuteSelectWithNotIn() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey NOT IN (1, 2, 3)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported `not in`."));
- }
-
- @Test
- void assertExecuteSelectWithParameterMarker() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (?, ?, ?)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertSelectStatementUseCrc32() {
- String sql = "SELECT /*+ HBase */ crc32(concat_ws('#',rowKey)) FROM t_order WHERE rowKey IN (1, 2, 3)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertExecuteSelectWithErrorInExpression() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (SELECT rowKey FROM t_order_item)";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only supported list expression."));
- }
-
- @Test
- void assertExecuteSelectWithBetween() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey BETWEEN 1 AND 2";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertExecuteSelectWithNotBetween() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey not BETWEEN 1 AND 2";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported `not between...and...`"));
- }
-
- @Test
- void assertExecuteSelectWithBetweenErrorKey() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE age BETWEEN 1 AND 2";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("age is not a allowed key."));
- }
-
- @Test
- void assertExecuteSelectWithErrorBetweenExpr() {
- String sql = "SELECT /*+ HBase */ * FROM t_order WHERE rowKey BETWEEN 1 AND now()";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Between expr must literal or parameter marker."));
- }
-
- @Test
- void assertSelectWithGroupBy() {
- String sql = "SELECT /*+ HBase */ * FROM t_order GROUP BY order_id";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported group by segment."));
- }
-
- @Test
- void assertSelectWithNotAllowOperator() {
- String sql = "SELECT /*+ hbase */ * FROM t_order WHERE rowKey != 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only Supported `=` operator."));
- }
-
- @Test
- void assertSelectWithNotAllowColumn() {
- String sql = "SELECT /*+ hbase */ * FROM t_order WHERE age = 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("age is not a allowed key."));
- }
-
- @Test
- void assertSelectWithMultipleExpression() {
- String sql = "SELECT /*+ hbase */ * FROM t_order WHERE rowKey = 1 AND age = 2";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported multiple expressions."));
- }
-
- @Test
- void assertSelectWithNotColumnExpression() {
- String sql = "SELECT /*+ hbase */ * FROM t_order WHERE 1 = 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Left segment must column segment."));
- }
-
- @Test
- void assertSelectWithParameterMarker() {
- String sql = "SELECT /*+ hbase */ rowKey, name, ? FROM t_order WHERE rowKey = 'kid'";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only supported shorthand, column and crc32 expression projections."));
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(SupportedTestCaseArgumentsProvider.class)
+ void assertExecuteSuccess(final String name, final String sql) {
+ assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(HBaseSupportedSQLStatement.parseSQLStatement(sql)).execute());
+ }
+
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class)
+ void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) {
+ SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
+ Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
+ assertThat(ex.getMessage(), is(expectedErrorMessage));
+ }
+
+ private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("pointSelect", HBaseSupportedSQLStatement.getSelectStatement()),
+ Arguments.of("parameterMarker", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (?, ?, ?)"),
+ Arguments.of("selectIn", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (1, 2, 3)"),
+ Arguments.of("between", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey BETWEEN 1 AND 2"),
+ Arguments.of("useCrc32", "SELECT /*+ HBase */ crc32(concat_ws('#',rowKey)) FROM t_order WHERE rowKey IN (1, 2, 3)"),
+ Arguments.of("useCrc32", "SELECT /*+ HBase */ crc32(concat_ws('#',rowKey)) FROM t_order WHERE rowKey IN (1, 2, 3)"));
+ }
+ }
+
+ private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("largeRowCount", "SELECT /*+ hbase */ * FROM t_order WHERE id = 1 LIMIT 5001", "Row count must less than 5000."),
+ Arguments.of("limit", "SELECT /*+ hbase */ * FROM t_order WHERE id = 1 LIMIT 5 OFFSET 3", "Do not supported offset segment."),
+ Arguments.of("lock", "SELECT /*+ hbase */ * FROM t_order WHERE id = 1 lock in share mode", "Do not supported lock segment."),
+ Arguments.of("function", "SELECT /*+ HBase */ sum(score) FROM person", "Only supported shorthand, column and crc32 expression projections."),
+ Arguments.of("join", "SELECT /*+ HBase */ * FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id", "Only supported simple table segment."),
+ Arguments.of("multipleIn", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (?, ?) AND id IN (?, ?)", "Left segment must column segment."),
+ Arguments.of("errorKey", "SELECT /*+ HBase */ * FROM t_order WHERE age IN (1, 2, 3)", "age is not a allowed key."),
+ Arguments.of("notIn", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey NOT IN (1, 2, 3)", "Do not supported `not in`."),
+ Arguments.of("errorInExpression", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey IN (SELECT rowKey FROM t_order_item)", "Only supported list expression."),
+ Arguments.of("notBetween", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey not BETWEEN 1 AND 2", "Do not supported `not between...and...`"),
+ Arguments.of("betweenErrorKey", "SELECT /*+ HBase */ * FROM t_order WHERE age BETWEEN 1 AND 2", "age is not a allowed key."),
+ Arguments.of("errorBetweenExpr", "SELECT /*+ HBase */ * FROM t_order WHERE rowKey BETWEEN 1 AND now()", "Between expr must literal or parameter marker."),
+ Arguments.of("groupBy", "SELECT /*+ HBase */ * FROM t_order GROUP BY order_id", "Do not supported group by segment."),
+ Arguments.of("notAllowedOperator", "SELECT /*+ hbase */ * FROM t_order WHERE rowKey != 1", "Only Supported `=` operator."),
+ Arguments.of("notAllowedColumn", "SELECT /*+ hbase */ * FROM t_order WHERE age = 1", "age is not a allowed key."),
+ Arguments.of("multipleExpressions", "SELECT /*+ hbase */ * FROM t_order WHERE rowKey = 1 AND age = 2", "Do not supported multiple expressions."),
+ Arguments.of("notColumnExpression", "SELECT /*+ hbase */ * FROM t_order WHERE 1 = 1", "Left segment must column segment."),
+ Arguments.of("parameterMarker", "SELECT /*+ hbase */ rowKey, name, ? FROM t_order WHERE rowKey = 'kid'", "Only supported shorthand, column and crc32 expression projections."));
+ }
}
}
diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementCheckerTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementCheckerTest.java
index 0398b3c2049..7b413b89e91 100644
--- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementCheckerTest.java
+++ b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/checker/HeterogeneousUpdateStatementCheckerTest.java
@@ -19,7 +19,13 @@ package org.apache.shardingsphere.proxy.backend.hbase.checker;
import org.apache.shardingsphere.proxy.backend.hbase.result.HBaseSupportedSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -28,65 +34,41 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class HeterogeneousUpdateStatementCheckerTest {
- @Test
- void assertExecuteUpdateStatement() {
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(HBaseSupportedSQLStatement.getUpdateStatement());
- assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- }
-
- @Test
- void assertUpdateWithFunction() {
- String sql = "update /*+ hbase */ t_test_order set age = 10, name = 'bob', time = now() where rowKey = 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Assigment must is literal or parameter marker"));
- }
-
- @Test
- void assertOperatorIsNotEqual() {
- String sql = "update /*+ hbase */ t_test_order set age = 10 where rowKey > 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Only Supported `=` operator."));
- }
-
- @Test
- void assertColumnIsNotRowKey() {
- String sql = "update /*+ hbase */ t_test_order set age = 10 where age = 1";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("age is not a allowed key."));
- }
-
- @Test
- void assertLeftIsNotColumn() {
- String sql = "update /*+ hbase */ t_test_order set age = 10 where 1 = 1";
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(SupportedTestCaseArgumentsProvider.class)
+ void assertExecuteSuccess(final String name, final String sql) {
SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Left segment must column segment."));
+ assertDoesNotThrow(() -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
}
- @Test
- void assertMultiExpression() {
- String sql = "update /*+ hbase */ t_test_order set age = 10 WHERE order_id = ? AND user_id = ? AND status=?";
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(UnsupportedTestCaseArgumentsProvider.class)
+ void assertExecuteFailed(final String name, final String sql, final String expectedErrorMessage) {
SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not supported multiple expressions."));
+ assertThat(ex.getMessage(), is(expectedErrorMessage));
}
- @Test
- void assertNotWhereSegment() {
- String sql = "update /*+ hbase */ t_test_order set age = 10 ";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Must contain where segment."));
+ private static class SupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(Arguments.of("standard", HBaseSupportedSQLStatement.getUpdateStatement()));
+ }
}
- @Test
- void assertUpdateRowKey() {
- String sql = "update /*+ hbase */ t_test_order set rowKey = 10 where rowKey = 'kid'";
- SQLStatement sqlStatement = HBaseSupportedSQLStatement.parseSQLStatement(sql);
- Exception ex = assertThrows(IllegalArgumentException.class, () -> HBaseCheckerFactory.newInstance(sqlStatement).execute());
- assertThat(ex.getMessage(), is("Do not allow update rowKey"));
+ private static class UnsupportedTestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("function", "update /*+ hbase */ t_test_order set age = 10, name = 'bob', time = now() where rowKey = 1", "Assignment must is literal or parameter marker."),
+ Arguments.of("operatorIsNotEqual", "update /*+ hbase */ t_test_order set age = 10 where rowKey > 1", "Only Supported `=` operator."),
+ Arguments.of("columnIsNotRowKey", "update /*+ hbase */ t_test_order set age = 10 where age = 1", "age is not a allowed key."),
+ Arguments.of("leftIsNotColumn", "update /*+ hbase */ t_test_order set age = 10 where 1 = 1", "Left segment must column segment."),
+ Arguments.of("multiExpression", "update /*+ hbase */ t_test_order set age = 10 WHERE order_id = ? AND user_id = ? AND status=?", "Do not supported multiple expressions."),
+ Arguments.of("withoutWhere", "update /*+ hbase */ t_test_order set age = 10 ", "Must contain where segment."),
+ Arguments.of("updateRowKey", "update /*+ hbase */ t_test_order set rowKey = 10 where rowKey = 'kid'", "Do not allow update rowKey"));
+ }
}
}
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/authenticator/MySQLAuthenticatorTypeTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/authenticator/MySQLAuthenticatorTypeTest.java
index da8532c4c2c..97f84c02d63 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/authenticator/MySQLAuthenticatorTypeTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/authenticator/MySQLAuthenticatorTypeTest.java
@@ -21,11 +21,14 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.proxy.frontend.authentication.Authenticator;
import org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
-import org.apache.shardingsphere.proxy.frontend.mysql.authentication.authenticator.impl.MySQLClearPasswordAuthenticator;
-import org.apache.shardingsphere.proxy.frontend.mysql.authentication.authenticator.impl.MySQLNativePasswordAuthenticator;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -36,35 +39,23 @@ class MySQLAuthenticatorTypeTest {
private final AuthorityRule rule = mock(AuthorityRule.class);
- @Test
- void assertDefaultAuthenticatorType() {
- when(rule.getAuthenticatorType(any())).thenReturn("");
- Authenticator authenticator = new AuthenticatorFactory<>(MySQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(MySQLNativePasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("mysql_native_password"));
- }
-
- @Test
- void assertAuthenticatorTypeWithErrorName() {
- when(rule.getAuthenticatorType(any())).thenReturn("error");
- Authenticator authenticator = new AuthenticatorFactory<>(MySQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(MySQLNativePasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("mysql_native_password"));
- }
-
- @Test
- void assertAuthenticatorTypeWithNative() {
- when(rule.getAuthenticatorType(any())).thenReturn("NATIVE");
- Authenticator authenticator = new AuthenticatorFactory<>(MySQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(MySQLNativePasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("mysql_native_password"));
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestCaseArgumentsProvider.class)
+ void assertAuthenticator(final String name, final String authenticatorType, final String expectedAuthenticatorMethodName) {
+ when(rule.getAuthenticatorType(any())).thenReturn(authenticatorType);
+ Authenticator actual = new AuthenticatorFactory<>(MySQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
+ assertThat(actual.getAuthenticationMethod().getMethodName(), is(expectedAuthenticatorMethodName));
}
- @Test
- void assertAuthenticatorTypeWithPassword() {
- when(rule.getAuthenticatorType(any())).thenReturn("CLEAR_TEXT");
- Authenticator authenticator = new AuthenticatorFactory<>(MySQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(MySQLClearPasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("mysql_clear_password"));
+ private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("default", "", "mysql_native_password"),
+ Arguments.of("error", "error", "mysql_native_password"),
+ Arguments.of("native", "NATIVE", "mysql_native_password"),
+ Arguments.of("password", "CLEAR_TEXT", "mysql_clear_password"));
+ }
}
}
diff --git a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/authenticator/OpenGaussAuthenticatorTypeTest.java b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/authenticator/OpenGaussAuthenticatorTypeTest.java
index 3d5f661cae8..ab0c4f05d3d 100644
--- a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/authenticator/OpenGaussAuthenticatorTypeTest.java
+++ b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/authenticator/OpenGaussAuthenticatorTypeTest.java
@@ -21,11 +21,14 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.proxy.frontend.authentication.Authenticator;
import org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
-import org.apache.shardingsphere.proxy.frontend.opengauss.authentication.authenticator.impl.OpenGaussMD5PasswordAuthenticator;
-import org.apache.shardingsphere.proxy.frontend.opengauss.authentication.authenticator.impl.OpenGaussSCRAMSha256PasswordAuthenticator;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -36,35 +39,23 @@ class OpenGaussAuthenticatorTypeTest {
private final AuthorityRule rule = mock(AuthorityRule.class);
- @Test
- void assertDefaultAuthenticatorType() {
- when(rule.getAuthenticatorType(any())).thenReturn("");
- Authenticator authenticator = new AuthenticatorFactory<>(OpenGaussAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(OpenGaussSCRAMSha256PasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("scram-sha-256"));
- }
-
- @Test
- void assertAuthenticatorTypeWithErrorName() {
- when(rule.getAuthenticatorType(any())).thenReturn("error");
- Authenticator authenticator = new AuthenticatorFactory<>(OpenGaussAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(OpenGaussSCRAMSha256PasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("scram-sha-256"));
- }
-
- @Test
- void assertAuthenticatorTypeWithSCRAMSha256() {
- when(rule.getAuthenticatorType(any())).thenReturn("SCRAM_SHA256");
- Authenticator authenticator = new AuthenticatorFactory<>(OpenGaussAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(OpenGaussSCRAMSha256PasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("scram-sha-256"));
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestCaseArgumentsProvider.class)
+ void assertAuthenticator(final String name, final String authenticatorType, final String expectedAuthenticatorMethodName) {
+ when(rule.getAuthenticatorType(any())).thenReturn(authenticatorType);
+ Authenticator actual = new AuthenticatorFactory<>(OpenGaussAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
+ assertThat(actual.getAuthenticationMethod().getMethodName(), is(expectedAuthenticatorMethodName));
}
- @Test
- void assertAuthenticatorTypeWithMD5() {
- when(rule.getAuthenticatorType(any())).thenReturn("md5");
- Authenticator authenticator = new AuthenticatorFactory<>(OpenGaussAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(OpenGaussMD5PasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("md5"));
+ private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("default", "", "scram-sha-256"),
+ Arguments.of("error", "error", "scram-sha-256"),
+ Arguments.of("scramSha256", "SCRAM_SHA256", "scram-sha-256"),
+ Arguments.of("md5", "md5", "md5"));
+ }
}
}
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/authenticator/PostgreSQLAuthenticatorTypeTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/authenticator/PostgreSQLAuthenticatorTypeTest.java
index 0070d5d61af..ee5f974ae40 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/authenticator/PostgreSQLAuthenticatorTypeTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/authenticator/PostgreSQLAuthenticatorTypeTest.java
@@ -21,11 +21,14 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.proxy.frontend.authentication.Authenticator;
import org.apache.shardingsphere.proxy.frontend.authentication.AuthenticatorFactory;
-import org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.impl.PostgreSQLMD5PasswordAuthenticator;
-import org.apache.shardingsphere.proxy.frontend.postgresql.authentication.authenticator.impl.PostgreSQLPasswordAuthenticator;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -36,35 +39,23 @@ class PostgreSQLAuthenticatorTypeTest {
private final AuthorityRule rule = mock(AuthorityRule.class);
- @Test
- void assertDefaultAuthenticatorType() {
- when(rule.getAuthenticatorType(any())).thenReturn("");
- Authenticator authenticator = new AuthenticatorFactory<>(PostgreSQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(PostgreSQLMD5PasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("md5"));
- }
-
- @Test
- void assertAuthenticatorTypeWithErrorName() {
- when(rule.getAuthenticatorType(any())).thenReturn("error");
- Authenticator authenticator = new AuthenticatorFactory<>(PostgreSQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(PostgreSQLMD5PasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("md5"));
- }
-
- @Test
- void assertAuthenticatorTypeWithMD5() {
- when(rule.getAuthenticatorType(any())).thenReturn("MD5");
- Authenticator authenticator = new AuthenticatorFactory<>(PostgreSQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(PostgreSQLMD5PasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("md5"));
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestCaseArgumentsProvider.class)
+ void assertAuthenticator(final String name, final String authenticatorType, final String expectedAuthenticatorMethodName) {
+ when(rule.getAuthenticatorType(any())).thenReturn(authenticatorType);
+ Authenticator actual = new AuthenticatorFactory<>(PostgreSQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
+ assertThat(actual.getAuthenticationMethod().getMethodName(), is(expectedAuthenticatorMethodName));
}
- @Test
- void assertAuthenticatorTypeWithPassword() {
- when(rule.getAuthenticatorType(any())).thenReturn("PASSWORD");
- Authenticator authenticator = new AuthenticatorFactory<>(PostgreSQLAuthenticatorType.class, rule).newInstance(mock(ShardingSphereUser.class));
- assertThat(authenticator, instanceOf(PostgreSQLPasswordAuthenticator.class));
- assertThat(authenticator.getAuthenticationMethod().getMethodName(), is("password"));
+ private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.of("default", "", "md5"),
+ Arguments.of("error", "error", "md5"),
+ Arguments.of("md5", "MD5", "md5"),
+ Arguments.of("password", "PASSWORD", "password"));
+ }
}
}