You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/06/30 13:19:56 UTC
[shardingsphere] branch master updated: Refactor test cases of
create rule statement (#11078)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 2ced3cf Refactor test cases of create rule statement (#11078)
2ced3cf is described below
commit 2ced3cfab36d5f1635a025fefbcb232e146c3336
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Jun 30 21:19:29 2021 +0800
Refactor test cases of create rule statement (#11078)
* Refactor CreateDatabaseDiscoveryRuleStatementUpdaterTest
* Refactor CreateEncryptRuleStatementUpdaterTest
* Refactor CreateReadwriteSplittingRuleStatementUpdaterTest
---
...ateDatabaseDiscoveryRuleBackendHandlerTest.java | 125 ------------------
.../impl/CreateEncryptRuleBackendHandlerTest.java | 115 ----------------
...teReadwriteSplittingRuleBackendHandlerTest.java | 144 ---------------------
...AlterShardingTableRuleStatementUpdaterTest.java | 1 -
...eDatabaseDiscoveryRuleStatementUpdaterTest.java | 65 ++++++++++
.../CreateEncryptRuleStatementUpdaterTest.java | 59 +++++++++
...ReadwriteSplittingRuleStatementUpdaterTest.java | 71 ++++++++++
7 files changed, 195 insertions(+), 385 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandlerTest.java
deleted file mode 100644
index fcd493d..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateDatabaseDiscoveryRuleBackendHandlerTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-
-import com.google.common.collect.Maps;
-import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
-import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
-import org.apache.shardingsphere.transaction.context.TransactionContexts;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class CreateDatabaseDiscoveryRuleBackendHandlerTest {
-
- @Mock
- private BackendConnection backendConnection;
-
- @Mock
- private CreateDatabaseDiscoveryRuleStatement sqlStatement;
-
- @Mock
- private MetaDataContexts metaDataContexts;
-
- @Mock
- private TransactionContexts transactionContexts;
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ShardingSphereMetaData shardingSphereMetaData;
-
- @Mock
- private ShardingSphereRuleMetaData ruleMetaData;
-
- @Mock
- private ShardingSphereResource shardingSphereResource;
-
- private final RDLBackendHandler<CreateDatabaseDiscoveryRuleStatement> handler = new RDLBackendHandler<>(sqlStatement, backendConnection, DatabaseDiscoveryRuleConfiguration.class);
-
- @Before
- public void setUp() {
- ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
- ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
- when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
- when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
- }
-
- @Test(expected = DuplicateRuleNamesException.class)
- public void assertCheckSQLStatementWithDuplicateRuleNames() {
- DatabaseDiscoveryDataSourceRuleConfiguration databaseDiscoveryDataSourceRuleConfiguration
- = new DatabaseDiscoveryDataSourceRuleConfiguration("pr_ds", Collections.emptyList(), "test");
- when(ruleMetaData.getConfigurations()).thenReturn(
- Collections.singleton(new DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfiguration), Maps.newHashMap())));
- DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new DatabaseDiscoveryRuleSegment("pr_ds", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
- handler.execute("test", sqlStatement);
- }
-
- @Test(expected = ResourceNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistedResources() {
- DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new DatabaseDiscoveryRuleSegment("pr_ds", Arrays.asList("ds_read_0", "ds_read_1"), null, new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
- handler.execute("test", sqlStatement);
- }
-
- @Test(expected = InvalidDatabaseDiscoveryTypesException.class)
- public void assertCheckSQLStatementWithDatabaseDiscoveryType() {
- DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new DatabaseDiscoveryRuleSegment("pr_ds", Arrays.asList("ds_read_0", "ds_read_1"), "notExistDiscoveryType", new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
- when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- handler.execute("test", sqlStatement);
- }
-
- @Test
- public void assertUpdateCurrentRuleConfiguration() {
- DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new DatabaseDiscoveryRuleSegment("pr_ds", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
- when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- ResponseHeader responseHeader = handler.execute("test", sqlStatement);
- assertNotNull(responseHeader);
- assertTrue(responseHeader instanceof UpdateResponseHeader);
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandlerTest.java
deleted file mode 100644
index 72a3c79..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandlerTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-
-import com.google.common.collect.Maps;
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
-import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
-import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
-import org.apache.shardingsphere.transaction.context.TransactionContexts;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class CreateEncryptRuleBackendHandlerTest {
-
- @Mock
- private BackendConnection backendConnection;
-
- @Mock
- private CreateEncryptRuleStatement sqlStatement;
-
- @Mock
- private MetaDataContexts metaDataContexts;
-
- @Mock
- private TransactionContexts transactionContexts;
-
- @Mock
- private ShardingSphereMetaData shardingSphereMetaData;
-
- @Mock
- private ShardingSphereRuleMetaData ruleMetaData;
-
- private final RDLBackendHandler<CreateEncryptRuleStatement> handler = new RDLBackendHandler<>(sqlStatement, backendConnection, EncryptRuleConfiguration.class);
-
- @Before
- public void setUp() {
- ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
- ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("test"));
- when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
- when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
- }
-
- @Test(expected = DuplicateRuleNamesException.class)
- public void assertCheckSQLStatementWithDuplicateEncryptRule() {
- EncryptTableRuleConfiguration encryptTableRuleConfiguration = new EncryptTableRuleConfiguration("t_encrypt", Collections.emptyList());
- when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new EncryptRuleConfiguration(Collections
- .singleton(encryptTableRuleConfiguration), Maps.newHashMap())));
- EncryptRuleSegment encryptRuleSegment = new EncryptRuleSegment("t_encrypt", buildEncryptColumnSegments("MD5"));
- when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
- handler.execute("test", sqlStatement);
- }
-
- @Test(expected = InvalidEncryptorsException.class)
- public void assertCheckSQLStatementWithoutToBeCreatedEncryptors() {
- EncryptRuleSegment encryptRuleSegment = new EncryptRuleSegment("t_encrypt", buildEncryptColumnSegments("notExistEncryptor"));
- when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
- handler.execute("test", sqlStatement);
- }
-
- @Test
- public void assertUpdateCurrentRuleConfiguration() {
- EncryptRuleSegment encryptRuleSegment = new EncryptRuleSegment("t_encrypt", buildEncryptColumnSegments("MD5"));
- when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
- ResponseHeader responseHeader = handler.execute("test", sqlStatement);
- assertNotNull(responseHeader);
- assertTrue(responseHeader instanceof UpdateResponseHeader);
- }
-
- private Collection<EncryptColumnSegment> buildEncryptColumnSegments(final String encryptorName) {
- return Collections.singleton(new EncryptColumnSegment("user_id", "user_cipher", "user_plain", new AlgorithmSegment(encryptorName, new Properties())));
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandlerTest.java
deleted file mode 100644
index 948035d..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateReadwriteSplittingRuleBackendHandlerTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
-
-import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidLoadBalancersException;
-import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
-import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
-import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.CreateReadwriteSplittingRuleStatement;
-import org.apache.shardingsphere.readwritesplitting.spi.ReplicaLoadBalanceAlgorithm;
-import org.apache.shardingsphere.transaction.context.TransactionContexts;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Properties;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class CreateReadwriteSplittingRuleBackendHandlerTest {
-
- @Mock
- private BackendConnection backendConnection;
-
- @Mock
- private CreateReadwriteSplittingRuleStatement sqlStatement;
-
- @Mock
- private MetaDataContexts metaDataContexts;
-
- @Mock
- private TransactionContexts transactionContexts;
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private ShardingSphereMetaData shardingSphereMetaData;
-
- @Mock
- private ShardingSphereRuleMetaData ruleMetaData;
-
- @Mock
- private ShardingSphereResource shardingSphereResource;
-
- private final RDLBackendHandler<CreateReadwriteSplittingRuleStatement> handler = new RDLBackendHandler<>(sqlStatement, backendConnection, ReadwriteSplittingRuleConfiguration.class);
-
- @Before
- public void setUp() {
- ShardingSphereServiceLoader.register(ReplicaLoadBalanceAlgorithm.class);
- ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
- when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
- when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
- }
-
- @Test(expected = DuplicateRuleNamesException.class)
- public void assertCheckSQLStatementWithDuplicateRuleNames() {
- ReadwriteSplittingDataSourceRuleConfiguration readwriteSplittingDataSourceRuleConfiguration
- = new ReadwriteSplittingDataSourceRuleConfiguration("pr_ds", "",
- "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "test");
- when(ruleMetaData.getConfigurations()).thenReturn(
- Collections.singleton(new ReadwriteSplittingRuleConfiguration(Collections.singleton(readwriteSplittingDataSourceRuleConfiguration), Collections.emptyMap())));
- ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new ReadwriteSplittingRuleSegment("pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
- handler.execute("test", sqlStatement);
- }
-
- @Test
- public void assertCheckSQLStatementWithCurrentConfiguration() {
- ReadwriteSplittingDataSourceRuleConfiguration readwriteSplittingDataSourceRuleConfig = new ReadwriteSplittingDataSourceRuleConfiguration(
- "pr_ds_1", "", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "test");
- Collection<ReadwriteSplittingDataSourceRuleConfiguration> dataSources = new LinkedList<>();
- dataSources.add(readwriteSplittingDataSourceRuleConfig);
- when(ruleMetaData.getConfigurations()).thenReturn(Collections.singleton(new ReadwriteSplittingRuleConfiguration(dataSources, new HashMap<>())));
- ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new ReadwriteSplittingRuleSegment("pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
- when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- ResponseHeader responseHeader = handler.execute("test", sqlStatement);
- assertNotNull(responseHeader);
- assertTrue(responseHeader instanceof UpdateResponseHeader);
- }
-
- @Test(expected = ResourceNotExistedException.class)
- public void assertCheckSQLStatementWithoutExistedResources() {
- ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new ReadwriteSplittingRuleSegment("pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), null, new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
- handler.execute("test", sqlStatement);
- }
-
- @Test(expected = InvalidLoadBalancersException.class)
- public void assertCheckSQLStatementWithoutToBeCreatedLoadBalancers() {
- ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new ReadwriteSplittingRuleSegment(
- "pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "notExistLoadBalancer", new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
- when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- handler.execute("test", sqlStatement);
- }
-
- @Test
- public void assertUpdateCurrentRuleConfiguration() {
- ReadwriteSplittingRuleSegment readwriteSplittingRuleSegment = new ReadwriteSplittingRuleSegment("pr_ds", "ds_write", Arrays.asList("ds_read_0", "ds_read_1"), "TEST", new Properties());
- when(sqlStatement.getRules()).thenReturn(Collections.singleton(readwriteSplittingRuleSegment));
- when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
- ResponseHeader responseHeader = handler.execute("test", sqlStatement);
- assertNotNull(responseHeader);
- assertTrue(responseHeader instanceof UpdateResponseHeader);
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingTableRuleStatementUpdaterTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingTableRuleStatementUpdaterTest.java
index ba1fac0..536a383 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterShardingTableRuleStatementUpdaterTest.java
@@ -64,7 +64,6 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
public void assertUpdateCurrentRuleConfiguration() {
updater.updateCurrentRuleConfiguration("foo", createSQLStatement("t_order", "HASH_MOD"), createCurrentRuleConfiguration());
// TODO assert current rule configuration
-
}
private AlterShardingTableRuleStatement createSQLStatement(final String tableName, final String shardingAlgorithmName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
new file mode 100644
index 0000000..e3b0c73
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
+
+import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
+import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
+import org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
+import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class CreateDatabaseDiscoveryRuleStatementUpdaterTest {
+
+ private final CreateDatabaseDiscoveryRuleStatementUpdater updater = new CreateDatabaseDiscoveryRuleStatementUpdater();
+
+ @Test(expected = DuplicateRuleNamesException.class)
+ public void assertCheckSQLStatementWithDuplicateRuleNames() {
+ DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = new DatabaseDiscoveryDataSourceRuleConfiguration("pr_ds", Collections.emptyList(), "test");
+ updater.checkSQLStatement(
+ "foo", createSQLStatement("TEST"), new DatabaseDiscoveryRuleConfiguration(Collections.singleton(dataSourceRuleConfig), Collections.emptyMap()), mock(ShardingSphereResource.class));
+ }
+
+ @Test(expected = ResourceNotExistedException.class)
+ public void assertCheckSQLStatementWithoutExistedResources() {
+ ShardingSphereResource resource = mock(ShardingSphereResource.class);
+ when(resource.getNotExistedResources(any())).thenReturn(Collections.singleton("ds_read_0"));
+ updater.checkSQLStatement("foo", createSQLStatement("TEST"), null, resource);
+ }
+
+ @Test(expected = InvalidDatabaseDiscoveryTypesException.class)
+ public void assertCheckSQLStatementWithDatabaseDiscoveryType() {
+ updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), null, mock(ShardingSphereResource.class));
+ }
+
+ private CreateDatabaseDiscoveryRuleStatement createSQLStatement(final String discoveryTypeName) {
+ DatabaseDiscoveryRuleSegment ruleSegment = new DatabaseDiscoveryRuleSegment("pr_ds", Arrays.asList("ds_read_0", "ds_read_1"), discoveryTypeName, new Properties());
+ return new CreateDatabaseDiscoveryRuleStatement(Collections.singleton(ruleSegment));
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateEncryptRuleStatementUpdaterTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateEncryptRuleStatementUpdaterTest.java
new file mode 100644
index 0000000..61c2ab5
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateEncryptRuleStatementUpdaterTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
+
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
+import org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
+import org.apache.shardingsphere.encrypt.distsql.parser.statement.CreateEncryptRuleStatement;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
+import org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.mockito.Mockito.mock;
+
+public final class CreateEncryptRuleStatementUpdaterTest {
+
+ private final CreateEncryptRuleStatementUpdater updater = new CreateEncryptRuleStatementUpdater();
+
+ @Test(expected = DuplicateRuleNamesException.class)
+ public void assertCheckSQLStatementWithDuplicateEncryptRule() {
+ updater.checkSQLStatement("foo", createSQLStatement("MD5"), getCurrentRuleConfig(), mock(ShardingSphereResource.class));
+ }
+
+ @Test(expected = InvalidEncryptorsException.class)
+ public void assertCheckSQLStatementWithoutToBeCreatedEncryptors() {
+ updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), null, mock(ShardingSphereResource.class));
+ }
+
+ private CreateEncryptRuleStatement createSQLStatement(final String encryptorName) {
+ EncryptColumnSegment columnSegment = new EncryptColumnSegment("user_id", "user_cipher", "user_plain", new AlgorithmSegment(encryptorName, new Properties()));
+ EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", Collections.singleton(columnSegment));
+ return new CreateEncryptRuleStatement(Collections.singleton(ruleSegment));
+ }
+
+ private EncryptRuleConfiguration getCurrentRuleConfig() {
+ return new EncryptRuleConfiguration(Collections.singleton(new EncryptTableRuleConfiguration("t_encrypt", Collections.emptyList())), Collections.emptyMap());
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateReadwriteSplittingRuleStatementUpdaterTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateReadwriteSplittingRuleStatementUpdaterTest.java
new file mode 100644
index 0000000..64ec979
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/CreateReadwriteSplittingRuleStatementUpdaterTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl.updater;
+
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.proxy.backend.exception.DuplicateRuleNamesException;
+import org.apache.shardingsphere.proxy.backend.exception.InvalidLoadBalancersException;
+import org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
+import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
+import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
+import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.CreateReadwriteSplittingRuleStatement;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class CreateReadwriteSplittingRuleStatementUpdaterTest {
+
+ private final CreateReadwriteSplittingRuleStatementUpdater updater = new CreateReadwriteSplittingRuleStatementUpdater();
+
+ @Test(expected = DuplicateRuleNamesException.class)
+ public void assertCheckSQLStatementWithDuplicateRuleNames() {
+ updater.checkSQLStatement("foo", createSQLStatement("TEST"), getCurrentRuleConfig(), mock(ShardingSphereResource.class));
+ }
+
+ @Test(expected = ResourceNotExistedException.class)
+ public void assertCheckSQLStatementWithoutExistedResources() {
+ ShardingSphereResource resource = mock(ShardingSphereResource.class);
+ when(resource.getNotExistedResources(any())).thenReturn(Arrays.asList("read_ds_0", "read_ds_1"));
+ updater.checkSQLStatement("foo", createSQLStatement("TEST"), null, resource);
+ }
+
+ @Test(expected = InvalidLoadBalancersException.class)
+ public void assertCheckSQLStatementWithoutToBeCreatedLoadBalancers() {
+ updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), null, mock(ShardingSphereResource.class));
+ }
+
+ private CreateReadwriteSplittingRuleStatement createSQLStatement(final String loadBalancerName) {
+ ReadwriteSplittingRuleSegment ruleSegment = new ReadwriteSplittingRuleSegment("readwrite_ds", "write_ds", Arrays.asList("read_ds_0", "read_ds_1"), loadBalancerName, new Properties());
+ return new CreateReadwriteSplittingRuleStatement(Collections.singleton(ruleSegment));
+ }
+
+ private ReadwriteSplittingRuleConfiguration getCurrentRuleConfig() {
+ ReadwriteSplittingDataSourceRuleConfiguration dataSourceRuleConfig
+ = new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_ds", "", "write_ds", Arrays.asList("read_ds_0", "read_ds_1"), "TEST");
+ return new ReadwriteSplittingRuleConfiguration(new LinkedList<>(Collections.singleton(dataSourceRuleConfig)), new HashMap<>());
+ }
+}