From b2d38cc44e28dea62e873dea5f97f09d92f12f50 Mon Sep 17 00:00:00 2001 From: Chuxin Chen Date: Sun, 9 Oct 2022 13:57:02 +0800 Subject: [PATCH] add sharding sphere data. (#21387) * add sharding sphere data. * add sharding sphere data. * add sharding sphere data. --- .../collector/ProxyInfoCollectorTest.java | 3 +- .../PrometheusPluginBootServiceTest.java | 3 +- .../metadata/data/ShardingSphereData.java | 32 ++++++++++ .../data/ShardingSphereDatabaseData.java | 32 ++++++++++ .../metadata/data/ShardingSphereRowData.java | 33 ++++++++++ .../data/ShardingSphereSchemaData.java | 32 ++++++++++ .../data/ShardingSphereTableData.java | 36 +++++++++++ .../builder/ShardingSphereDataBuilder.java | 38 ++++++++++++ .../ShardingSphereDataBuilderFactory.java | 49 +++++++++++++++ .../MySQLShardingSphereDataBuilder.java | 61 +++++++++++++++++++ .../PostgreSQLShardingSphereDataBuilder.java | 60 ++++++++++++++++++ ...ata.data.builder.ShardingSphereDataBuilder | 19 ++++++ .../driver/state/DriverStateContextTest.java | 3 +- .../mode/manager/ContextManager.java | 14 +++-- .../mode/metadata/MetaDataContexts.java | 3 + .../metadata/MetaDataContextsFactory.java | 13 +++- .../persist/MetaDataPersistService.java | 4 ++ .../ShardingSphereDataPersistService.java | 47 ++++++++++++++ .../mode/metadata/MetaDataContextsTest.java | 3 +- .../ClusterContextManagerCoordinatorTest.java | 7 ++- ...atabaseCommunicationEngineFactoryTest.java | 3 +- .../communication/ProxySQLExecutorTest.java | 5 +- .../JDBCDatabaseCommunicationEngineTest.java | 5 +- .../connection/JDBCBackendConnectionTest.java | 3 +- .../datasource/JDBCBackendDataSourceTest.java | 3 +- .../context/BackendExecutorContextTest.java | 3 +- .../backend/context/ProxyContextTest.java | 15 ++--- .../DatabaseAdminQueryBackendHandlerTest.java | 5 +- ...abaseOperateBackendHandlerFactoryTest.java | 9 +-- .../DefaultDatabaseMetadataExecutorTest.java | 5 +- .../mysql/MySQLAdminExecutorCreatorTest.java | 5 +- .../ShowCreateDatabaseExecutorTest.java | 3 +- .../executor/ShowCurrentUserExecutorTest.java | 3 +- .../executor/ShowDatabasesExecutorTest.java | 3 +- .../ShowFunctionStatusExecutorTest.java | 3 +- .../ShowProcedureStatusExecutorTest.java | 3 +- .../executor/ShowTablesExecutorTest.java | 5 +- .../executor/UseDatabaseExecutorTest.java | 7 ++- ...SelectInformationSchemataExecutorTest.java | 7 ++- .../executor/SelectDatabaseExecutorTest.java | 3 +- .../executor/SelectTableExecutorTest.java | 3 +- .../UnicastDatabaseBackendHandlerTest.java | 3 +- .../DistSQLBackendHandlerFactoryTest.java | 5 +- .../SetVariableBackendHandlerTest.java | 5 +- .../updatable/SetVariableExecutorTest.java | 3 +- .../command/CommandExecutorTaskTest.java | 3 +- .../FrontDatabaseProtocolTypeFactoryTest.java | 9 +-- .../mysql/MySQLFrontendEngineTest.java | 5 +- .../MySQLAuthenticationEngineTest.java | 5 +- .../MySQLAuthenticationHandlerTest.java | 5 +- .../MySQLCommandExecutorFactoryTest.java | 3 +- .../MySQLComStmtExecuteExecutorTest.java | 5 +- .../OpenGaussAuthenticationEngineTest.java | 5 +- .../OpenGaussAuthenticationHandlerTest.java | 3 +- .../PostgreSQLAuthenticationEngineTest.java | 5 +- .../PostgreSQLAuthenticationHandlerTest.java | 3 +- .../PostgreSQLCommandExecuteEngineTest.java | 3 +- .../core/util/PipelineContextUtil.java | 9 +-- 58 files changed, 588 insertions(+), 84 deletions(-) create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereData.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereDatabaseData.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereRowData.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereSchemaData.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereTableData.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilder.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java create mode 100644 infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java create mode 100644 infra/common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder create mode 100644 mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereDataPersistService.java diff --git a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java index 5a65234bd24e0..591f070d1c380 100644 --- a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java +++ b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.lock.LockContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.schedule.ScheduleContext; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -40,7 +41,7 @@ public final class ProxyInfoCollectorTest extends ProxyContextRestorer { @Test public void assertCollect() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()); InstanceContext instanceContext = new InstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext(), mock(ScheduleContext.class)); diff --git a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java index 807596b140e45..19ee99da4fd52 100644 --- a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java +++ b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java @@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.lock.LockContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.schedule.ScheduleContext; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -53,7 +54,7 @@ public static void close() { @Test public void assertStart() throws IOException { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()); InstanceContext instanceContext = new InstanceContext( new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null), mock(LockContext.class), new EventBusContext(), mock(ScheduleContext.class)); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereData.java new file mode 100644 index 0000000000000..eda2db95eea5a --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereData.java @@ -0,0 +1,32 @@ +/* + * 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.infra.metadata.data; + +import lombok.Getter; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * ShardingSphere data. + */ +@Getter +public final class ShardingSphereData { + + private final Map databaseData = new LinkedHashMap<>(); +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereDatabaseData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereDatabaseData.java new file mode 100644 index 0000000000000..6577078ffbf2d --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereDatabaseData.java @@ -0,0 +1,32 @@ +/* + * 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.infra.metadata.data; + +import lombok.Getter; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * ShardingSphere database data. + */ +@Getter +public final class ShardingSphereDatabaseData { + + private final Map schemaData = new LinkedHashMap<>(); +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereRowData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereRowData.java new file mode 100644 index 0000000000000..fc979c399a3d7 --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereRowData.java @@ -0,0 +1,33 @@ +/* + * 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.infra.metadata.data; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +/** + * ShardingSphere row data. + */ +@RequiredArgsConstructor +@Getter +public final class ShardingSphereRowData { + + private final List rows; +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereSchemaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereSchemaData.java new file mode 100644 index 0000000000000..42a0b0e5beadd --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereSchemaData.java @@ -0,0 +1,32 @@ +/* + * 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.infra.metadata.data; + +import lombok.Getter; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * ShardingSphere schema data. + */ +@Getter +public final class ShardingSphereSchemaData { + + private final Map tableData = new LinkedHashMap<>(); +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereTableData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereTableData.java new file mode 100644 index 0000000000000..5fa7b2cf0c72e --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereTableData.java @@ -0,0 +1,36 @@ +/* + * 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.infra.metadata.data; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.LinkedList; +import java.util.List; + +/** + * ShardingSphere table data. + */ +@RequiredArgsConstructor +@Getter +public final class ShardingSphereTableData { + + private final String name; + + private final List rows = new LinkedList<>(); +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilder.java new file mode 100644 index 0000000000000..9b842ac8d4637 --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilder.java @@ -0,0 +1,38 @@ +/* + * 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.infra.metadata.data.builder; + +import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; +import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI; +import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI; + +/** + * ShardingSphere data Builder. + */ +@SingletonSPI +public interface ShardingSphereDataBuilder extends TypedSPI { + + /** + * Build ShardingSphere data. + * + * @param metaData meta data + * @return ShardingSphere data + */ + ShardingSphereData build(ShardingSphereMetaData metaData); +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.java new file mode 100644 index 0000000000000..6527715ac4c9c --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.java @@ -0,0 +1,49 @@ +/* + * 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.infra.metadata.data.builder; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.shardingsphere.infra.database.type.DatabaseType; +import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType; +import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader; +import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry; + +import java.util.Optional; + +/** + * ShardingSphere data builder factory. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ShardingSphereDataBuilderFactory { + + static { + ShardingSphereServiceLoader.register(ShardingSphereDataBuilder.class); + } + + /** + * Find instance of dialect ShardingSphere data builder. + * + * @param databaseType database type + * @return found instance + */ + public static Optional getInstance(final DatabaseType databaseType) { + String type = databaseType instanceof OpenGaussDatabaseType ? "PostgreSQL" : databaseType.getType(); + return TypedSPIRegistry.findRegisteredService(ShardingSphereDataBuilder.class, type); + } +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java new file mode 100644 index 0000000000000..9e7ef03858143 --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.java @@ -0,0 +1,61 @@ +/* + * 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.infra.metadata.data.builder.dialect; + +import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereDatabaseData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData; +import org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder; +import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema; +import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable; + +import java.util.Map; +import java.util.Optional; + +/** + * MySQL ShardingSphere data Builder. + */ + +public final class MySQLShardingSphereDataBuilder implements ShardingSphereDataBuilder { + + private static final String SHARDING_SPHERE = "shardingsphere"; + + @Override + public ShardingSphereData build(final ShardingSphereMetaData metaData) { + ShardingSphereData result = new ShardingSphereData(); + Optional shardingSphereSchema = Optional.ofNullable(metaData.getDatabase(SHARDING_SPHERE)).map(database -> database.getSchema(SHARDING_SPHERE)); + if (!shardingSphereSchema.isPresent()) { + return result; + } + ShardingSphereSchemaData schemaData = new ShardingSphereSchemaData(); + for (Map.Entry entry : shardingSphereSchema.get().getTables().entrySet()) { + schemaData.getTableData().put(entry.getKey(), new ShardingSphereTableData(entry.getValue().getName())); + } + ShardingSphereDatabaseData databaseData = new ShardingSphereDatabaseData(); + databaseData.getSchemaData().put(SHARDING_SPHERE, schemaData); + result.getDatabaseData().put(SHARDING_SPHERE, databaseData); + return result; + } + + @Override + public String getType() { + return "MySQL"; + } +} diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java new file mode 100644 index 0000000000000..7668d28f276b8 --- /dev/null +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/data/builder/dialect/PostgreSQLShardingSphereDataBuilder.java @@ -0,0 +1,60 @@ +/* + * 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.infra.metadata.data.builder.dialect; + +import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereDatabaseData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData; +import org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder; +import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema; + +import java.util.Map; +import java.util.Optional; + +/** + * Postgre SQL ShardingSphere data Builder. + */ + +public final class PostgreSQLShardingSphereDataBuilder implements ShardingSphereDataBuilder { + + private static final String SHARDING_SPHERE = "shardingsphere"; + + @Override + public ShardingSphereData build(final ShardingSphereMetaData metaData) { + ShardingSphereData result = new ShardingSphereData(); + for (Map.Entry entry : metaData.getDatabases().entrySet()) { + ShardingSphereDatabaseData databaseData = new ShardingSphereDatabaseData(); + Optional shardingSphereSchema = Optional.ofNullable(entry.getValue()).map(database -> database.getSchema(SHARDING_SPHERE)); + if (shardingSphereSchema.isPresent()) { + ShardingSphereSchemaData schemaData = new ShardingSphereSchemaData(); + shardingSphereSchema.get().getTables().forEach((key, value) -> schemaData.getTableData().put(key, new ShardingSphereTableData(entry.getValue().getName()))); + databaseData.getSchemaData().put(SHARDING_SPHERE, schemaData); + } + result.getDatabaseData().put(entry.getKey(), databaseData); + } + return result; + } + + @Override + public String getType() { + return "PostgreSQL"; + } +} diff --git a/infra/common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder b/infra/common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder new file mode 100644 index 0000000000000..db2c1349471c0 --- /dev/null +++ b/infra/common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder @@ -0,0 +1,19 @@ +# +# 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. +# + +org.apache.shardingsphere.infra.metadata.data.builder.dialect.MySQLShardingSphereDataBuilder +org.apache.shardingsphere.infra.metadata.data.builder.dialect.PostgreSQLShardingSphereDataBuilder diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java index 2a9beb85270f5..5281753f70864 100644 --- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java +++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.state.StateContext; @@ -63,7 +64,7 @@ public void setUp() { when(globalRuleMetaData.getSingleRule(TransactionRule.class)).thenReturn(mock(TransactionRule.class, RETURNS_DEEP_STUBS)); when(globalRuleMetaData.getSingleRule(TrafficRule.class)).thenReturn(mock(TrafficRule.class)); when(contextManager.getMetaDataContexts()).thenReturn(new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, globalRuleMetaData, mock(ConfigurationProperties.class)))); + new ShardingSphereMetaData(databases, globalRuleMetaData, mock(ConfigurationProperties.class)), new ShardingSphereData())); when(contextManager.getInstanceContext().getInstance().getState()).thenReturn(new StateContext()); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java index 58a8f6be272aa..3cfca2ecd56b7 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java @@ -30,6 +30,8 @@ import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; +import org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilderFactory; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; @@ -400,7 +402,9 @@ private MetaDataContexts createMetaDataContexts(final String databaseName, final ConfigurationProperties props = metaDataContexts.getMetaData().getProps(); ShardingSphereRuleMetaData changedGlobalMetaData = new ShardingSphereRuleMetaData( GlobalRulesBuilder.buildRules(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations(), changedDatabases, instanceContext, props)); - return newMetaDataContexts(new ShardingSphereMetaData(changedDatabases, changedGlobalMetaData, props)); + ShardingSphereMetaData changedMetaData = new ShardingSphereMetaData(changedDatabases, changedGlobalMetaData, props); + return newMetaDataContexts(changedMetaData, ShardingSphereDataBuilderFactory.getInstance(changedMetaData.getDatabases().values().iterator().next().getProtocolType()) + .map(builder -> builder.build(changedMetaData)).orElseGet(ShardingSphereData::new)); } private Map createChangedDatabases(final String databaseName, @@ -421,8 +425,8 @@ private Map createChangedDatabases(final String return result; } - private MetaDataContexts newMetaDataContexts(final ShardingSphereMetaData metaData) { - return new MetaDataContexts(metaDataContexts.getPersistService(), metaData); + private MetaDataContexts newMetaDataContexts(final ShardingSphereMetaData metaData, final ShardingSphereData shardingSphereData) { + return new MetaDataContexts(metaDataContexts.getPersistService(), metaData, shardingSphereData); } private Map newShardingSphereSchemas(final ShardingSphereDatabase database) { @@ -456,7 +460,7 @@ public synchronized void alterGlobalRuleConfiguration(final Collection databases = ShardingSphereDatabasesFactory.create(effectiveDatabaseConfigs, props, instanceContext); databases.putAll(reloadDatabases(databases, persistService)); ShardingSphereRuleMetaData globalMetaData = new ShardingSphereRuleMetaData(GlobalRulesBuilder.buildRules(globalRuleConfigs, databases, instanceContext, props)); - return new MetaDataContexts(persistService, new ShardingSphereMetaData(databases, globalMetaData, props)); + ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, globalMetaData, props); + ShardingSphereData shardingSphereData = initShardingSphereData(persistService, metaData, instanceContext); + return new MetaDataContexts(persistService, metaData, shardingSphereData); } private static Map createEffectiveDatabaseConfigurations(final Collection databaseNames, @@ -137,4 +141,11 @@ private static Map reloadDatabases(final Map builder.build(metaData)).orElseGet(ShardingSphereData::new)); + // TODO register to calcite + return result; + } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java index 20a01ca56ea24..1c67436e50b9e 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator; +import org.apache.shardingsphere.mode.metadata.persist.data.ShardingSphereDataPersistService; import org.apache.shardingsphere.mode.metadata.persist.service.DatabaseMetaDataPersistService; import org.apache.shardingsphere.mode.metadata.persist.service.MetaDataVersionPersistService; import org.apache.shardingsphere.mode.metadata.persist.service.config.database.DataSourcePersistService; @@ -59,6 +60,8 @@ public final class MetaDataPersistService { private final MetaDataVersionPersistService metaDataVersionPersistService; + private final ShardingSphereDataPersistService shardingSphereDataPersistService; + public MetaDataPersistService(final PersistRepository repository) { this.repository = repository; dataSourceService = new DataSourcePersistService(repository); @@ -67,6 +70,7 @@ public MetaDataPersistService(final PersistRepository repository) { globalRuleService = new GlobalRulePersistService(repository); propsService = new PropertiesPersistService(repository); metaDataVersionPersistService = new MetaDataVersionPersistService(repository); + shardingSphereDataPersistService = new ShardingSphereDataPersistService(repository); } /** diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereDataPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereDataPersistService.java new file mode 100644 index 0000000000000..e7c331a67dccf --- /dev/null +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/data/ShardingSphereDataPersistService.java @@ -0,0 +1,47 @@ +/* + * 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.mode.metadata.persist.data; + +import lombok.Getter; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; +import org.apache.shardingsphere.mode.persist.PersistRepository; + +import java.util.Optional; + +/** + * ShardingSphere data persist service. + */ +@Getter +public final class ShardingSphereDataPersistService { + + private final PersistRepository repository; + + public ShardingSphereDataPersistService(final PersistRepository repository) { + this.repository = repository; + } + + /** + * Load. + * + * @return ShardingSphere data + */ + public Optional load() { + // TODO add load ShardingSphere data logic + return Optional.empty(); + } +} diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java index 5908351ba4ca0..2c2a6905f83cd 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -48,6 +49,6 @@ public void assertGetDefaultMetaData() { Map databases = new LinkedHashMap<>(1, 1); databases.put(DefaultDatabase.LOGIC_NAME, database); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())); - assertThat(new MetaDataContexts(mock(MetaDataPersistService.class), metaData).getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME), is(database)); + assertThat(new MetaDataContexts(mock(MetaDataPersistService.class), metaData, new ShardingSphereData()).getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME), is(database)); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java index 4c87bbb9b45d2..8ebd956eda56b 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -104,9 +105,9 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; @@ -133,8 +134,8 @@ public final class ClusterContextManagerCoordinatorTest { @Before public void setUp() throws SQLException { contextManager = new ClusterContextManagerBuilder().build(createContextManagerBuilderParameter()); - contextManager.renewMetaDataContexts(new MetaDataContexts(contextManager.getMetaDataContexts().getPersistService(), - new ShardingSphereMetaData(createDatabases(), contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())))); + contextManager.renewMetaDataContexts(new MetaDataContexts(contextManager.getMetaDataContexts().getPersistService(), new ShardingSphereMetaData(createDatabases(), + contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), new ConfigurationProperties(new Properties())), new ShardingSphereData())); coordinator = new ClusterContextManagerCoordinator(persistService, new RegistryCenter(mock(ClusterPersistRepository.class), new EventBusContext(), mock(ProxyInstanceMetaData.class), null), contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java index 5f0cbec7f3a8a..5c7dfad53b952 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -49,7 +50,7 @@ public final class DatabaseCommunicationEngineFactoryTest extends ProxyContextRe @Before public void setUp() { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java index aab2ab9b4b6e0..e5702d8e0a168 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.proxy.backend.communication; +import org.apache.shardingsphere.dialect.exception.transaction.TableModifyInTransactionException; import org.apache.shardingsphere.infra.binder.QueryContext; import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.statement.ddl.CreateTableStatementContext; @@ -29,6 +30,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.route.context.RouteContext; @@ -38,7 +40,6 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine; import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; -import org.apache.shardingsphere.dialect.exception.transaction.TableModifyInTransactionException; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; @@ -83,7 +84,7 @@ public void setUp() { when(connectionSession.getTransactionStatus().isInTransaction()).thenReturn(true); when(connectionSession.getBackendConnection()).thenReturn(backendConnection); when(backendConnection.getConnectionSession()).thenReturn(connectionSession); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()); ProxyContext.init(new ContextManager(metaDataContexts, mock(InstanceContext.class))); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java index e248bad586eea..44bd74eabe753 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryMergedResult; import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn; @@ -83,9 +84,9 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -115,7 +116,7 @@ public final class JDBCDatabaseCommunicationEngineTest extends ProxyContextResto public void setUp() { when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("db"); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(mockDatabases(), globalRuleMetaData, new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(mockDatabases(), globalRuleMetaData, new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java index 4c78a4043ad86..fee46aad4176d 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -111,7 +112,7 @@ public void setUp() throws ReflectiveOperationException { private void setContextManager() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(createDatabases(), mockGlobalRuleMetaData(), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(createDatabases(), mockGlobalRuleMetaData(), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java index 20b61905af74b..aaa794e959918 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.exception.OverallConnectionNotEnoughException; import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -68,7 +69,7 @@ public final class JDBCBackendDataSourceTest extends ProxyContextRestorer { public void setUp() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(createDatabases(), mockGlobalRuleMetaData(), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(createDatabases(), mockGlobalRuleMetaData(), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java index 80d89da955a96..d33015beae725 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/BackendExecutorContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.proxy.backend.context; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -35,7 +36,7 @@ public final class BackendExecutorContextTest extends ProxyContextRestorer { @Before public void setUp() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java index df15064a73537..864f63ec3bd10 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java @@ -17,16 +17,17 @@ package org.apache.shardingsphere.proxy.backend.context; +import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; -import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; import org.junit.Test; @@ -36,9 +37,9 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -50,7 +51,7 @@ public final class ProxyContextTest extends ProxyContextRestorer { @Test public void assertInit() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()); ProxyContext.init(new ContextManager(metaDataContexts, mock(InstanceContext.class, RETURNS_DEEP_STUBS))); assertThat(ProxyContext.getInstance().getContextManager().getMetaDataContexts(), is(ProxyContext.getInstance().getContextManager().getMetaDataContexts())); assertTrue(ProxyContext.getInstance().getStateContext().isPresent()); @@ -62,7 +63,7 @@ public void assertDatabaseExists() { Map databases = mockDatabases(); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); assertTrue(ProxyContext.getInstance().databaseExists("db")); @@ -84,7 +85,7 @@ public void assertGetDatabaseWhenNotExisted() { Map databases = mockDatabases(); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); ProxyContext.getInstance().getDatabase("db1"); @@ -95,7 +96,7 @@ public void assertGetDatabase() { Map databases = mockDatabases(); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); assertThat(databases.get("db"), is(ProxyContext.getInstance().getDatabase("db"))); @@ -106,7 +107,7 @@ public void assertGetAllDatabaseNames() { Map databases = createDatabases(); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); assertThat(new LinkedHashSet<>(ProxyContext.getInstance().getAllDatabaseNames()), is(databases.keySet())); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java index a7355049ee6c3..fc508d954350b 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseAdminQueryBackendHandlerTest.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -44,8 +45,8 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -58,7 +59,7 @@ public final class DatabaseAdminQueryBackendHandlerTest extends ProxyContextRest @Before public void before() throws SQLException { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = new ContextManager(metaDataContexts, mock(InstanceContext.class)); ProxyContext.init(contextManager); ConnectionSession connectionSession = mock(ConnectionSession.class); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseOperateBackendHandlerFactoryTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseOperateBackendHandlerFactoryTest.java index b2991fb5ecca8..b998ada62444f 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseOperateBackendHandlerFactoryTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/DatabaseOperateBackendHandlerFactoryTest.java @@ -17,16 +17,17 @@ package org.apache.shardingsphere.proxy.backend.handler.admin; +import org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseCreateExistsException; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; -import org.apache.shardingsphere.dialect.exception.syntax.database.DatabaseCreateExistsException; import org.apache.shardingsphere.proxy.backend.handler.database.DatabaseOperateBackendHandlerFactory; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; @@ -53,8 +54,8 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertNull; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -72,7 +73,7 @@ public final class DatabaseOperateBackendHandlerFactoryTest extends ProxyContext @Before public void setUp() { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); when(connectionSession.getDatabaseName()).thenReturn("db"); @@ -146,7 +147,7 @@ private void setGovernanceMetaDataContexts(final boolean isGovernance) { ContextManager contextManager = ProxyContext.getInstance().getContextManager(); MetaDataContexts metaDataContexts = isGovernance ? mockMetaDataContexts() - : new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + : new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetadataExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetadataExecutorTest.java index 65318bf530fa7..75e5614132d49 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetadataExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultDatabaseMetadataExecutorTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -76,8 +77,8 @@ private ContextManager mockContextManager() { AuthorityRule authorityRule = mock(AuthorityRule.class); when(authorityRule.findPrivileges(grantee)).thenReturn(Optional.of(new DatabasePermittedPrivileges(Collections.singleton("auth_db")))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(new HashMap<>(), new ShardingSphereRuleMetaData(Collections.singleton(authorityRule)), new ConfigurationProperties(new Properties()))); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(new HashMap<>(), + new ShardingSphereRuleMetaData(Collections.singleton(authorityRule)), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLAdminExecutorCreatorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLAdminExecutorCreatorTest.java index 3a8ba74a96e26..1899a69179fde 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLAdminExecutorCreatorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/MySQLAdminExecutorCreatorTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -76,8 +77,8 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -343,7 +344,7 @@ public void assertCreateWithSelectStatementFromPerformanceSchema() { private void initProxyContext(final Map databases) { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java index 8c0732568d943..137a261d12b07 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; @@ -52,7 +53,7 @@ public final class ShowCreateDatabaseExecutorTest extends ProxyContextRestorer { public void setUp() { Map databases = getDatabases(); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCurrentUserExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCurrentUserExecutorTest.java index 6d4ed8153aa0d..5977b09defc41 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCurrentUserExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowCurrentUserExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.authority.rule.AuthorityRule; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; @@ -52,7 +53,7 @@ public final class ShowCurrentUserExecutorTest extends ProxyContextRestorer { public void setUp() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(new HashMap<>(), mockShardingSphereRuleMetaData(), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(new HashMap<>(), mockShardingSphereRuleMetaData(), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowDatabasesExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowDatabasesExecutorTest.java index 5786fd3e4dc91..fd83452ccce27 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowDatabasesExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowDatabasesExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; @@ -60,7 +61,7 @@ public void setUp() { showDatabasesExecutor = new ShowDatabasesExecutor(new MySQLShowDatabasesStatement()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowFunctionStatusExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowFunctionStatusExecutorTest.java index 99cb9cd53a514..fd49f520bae9a 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowFunctionStatusExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowFunctionStatusExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; @@ -55,7 +56,7 @@ public void setUp() { showFunctionStatusExecutor = new ShowFunctionStatusExecutor(new MySQLShowFunctionStatusStatement()); Map databases = getDatabases(); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowProcedureStatusExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowProcedureStatusExecutorTest.java index f9b3ed9b617cd..3131145796382 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowProcedureStatusExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowProcedureStatusExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; @@ -52,7 +53,7 @@ public final class ShowProcedureStatusExecutorTest extends ProxyContextRestorer public void setUp() { Map databases = getDatabases(); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowTablesExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowTablesExecutorTest.java index c2d8147201060..3f042d61de77f 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowTablesExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/ShowTablesExecutorTest.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData; import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema; @@ -51,8 +52,8 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -65,7 +66,7 @@ public final class ShowTablesExecutorTest extends ProxyContextRestorer { public void setUp() { Map databases = getDatabases(); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UseDatabaseExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UseDatabaseExecutorTest.java index eed93f841b272..4ef7b30bfdaef 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UseDatabaseExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/UseDatabaseExecutorTest.java @@ -17,16 +17,17 @@ package org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor; +import org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; -import org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUseStatement; @@ -59,7 +60,7 @@ public final class UseDatabaseExecutorTest extends ProxyContextRestorer { public void setUp() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } @@ -81,7 +82,7 @@ public void assertExecuteUseStatementBackendHandler() { when(useStatement.getSchema()).thenReturn(String.format(DATABASE_PATTERN, 0)); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); UseDatabaseExecutor useSchemaBackendHandler = new UseDatabaseExecutor(useStatement); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/information/SelectInformationSchemataExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/information/SelectInformationSchemataExecutorTest.java index fe39d282f8a77..fc5effba21c24 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/information/SelectInformationSchemataExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/information/SelectInformationSchemataExecutorTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -54,8 +55,8 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -85,8 +86,8 @@ private ContextManager mockContextManager() { AuthorityRule authorityRule = mock(AuthorityRule.class); when(authorityRule.findPrivileges(grantee)).thenReturn(Optional.of(new DatabasePermittedPrivileges(Collections.singleton("auth_db")))); ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(new HashMap<>(), new ShardingSphereRuleMetaData(Collections.singleton(authorityRule)), new ConfigurationProperties(new Properties()))); + MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(new HashMap<>(), + new ShardingSphereRuleMetaData(Collections.singleton(authorityRule)), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(result.getMetaDataContexts()).thenReturn(metaDataContexts); return result; } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectDatabaseExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectDatabaseExecutorTest.java index ae612aa4b297d..601ac399a04a6 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectDatabaseExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectDatabaseExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -62,7 +63,7 @@ public final class SelectDatabaseExecutorTest extends ProxyContextRestorer { public void setUp() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(new HashMap<>(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(new HashMap<>(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectTableExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectTableExecutorTest.java index ac3863c6b6cb8..db26aa5041a22 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectTableExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/admin/postgresql/executor/SelectTableExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -60,7 +61,7 @@ public final class SelectTableExecutorTest extends ProxyContextRestorer { public void setUp() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(new HashMap<>(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(new HashMap<>(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java index 1eac8bf1ee21c..4a8a5cd55099a 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -82,7 +83,7 @@ public final class UnicastDatabaseBackendHandlerTest extends ProxyContextRestore public void setUp() throws SQLException { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); when(connectionSession.getDefaultDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0)); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java index f8ab741cb3fa1..7177c4060cef6 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.distsql.exception.rule.MissingRequiredRuleException; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -82,7 +83,7 @@ public final class DistSQLBackendHandlerFactoryTest extends ProxyContextRestorer @Before public void setUp() { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); @@ -237,7 +238,7 @@ private void setContextManager(final boolean isGovernance) { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = isGovernance ? mockMetaDataContexts() - : new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()); + : new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableBackendHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableBackendHandlerTest.java index 305957fa1e560..4769cdb5fbcc1 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableBackendHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableBackendHandlerTest.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -32,8 +33,8 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; -import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum; import org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException; +import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; @@ -65,7 +66,7 @@ public final class SetVariableBackendHandlerTest extends ProxyContextRestorer { @Before public void setUp() { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(createDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(createProperties()))); + new ShardingSphereMetaData(createDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(createProperties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableExecutorTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableExecutorTest.java index 21ad793253faf..4e36d38147f32 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableExecutorTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetVariableExecutorTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.SetVariableStatement; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -70,7 +71,7 @@ public void assertExecuteWithAgent() throws SQLException { @Test public void assertExecuteWithConfigurationKey() throws SQLException { - ContextManager contextManager = new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()), null); + ContextManager contextManager = new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()), null); ProxyContext.init(contextManager); SetVariableStatement statement = new SetVariableStatement("proxy_frontend_flush_threshold", "1024"); SetVariableHandler handler = new SetVariableHandler(); diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java index db63ccce12bda..7408633401d82 100644 --- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java +++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.db.protocol.payload.PacketPayload; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -99,7 +100,7 @@ public final class CommandExecutorTaskTest extends ProxyContextRestorer { @Before public void setup() { - ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()), mock(InstanceContext.class))); + ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()), mock(InstanceContext.class))); when(connectionSession.getBackendConnection()).thenReturn(backendConnection); when(handlerContext.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get()).thenReturn(StandardCharsets.UTF_8); } diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java index fd55f0d2ad6fe..e6d3aa721b330 100644 --- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java +++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -40,8 +41,8 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -52,7 +53,7 @@ public final class FrontDatabaseProtocolTypeFactoryTest extends ProxyContextRest @Test public void assertGetDatabaseTypeWhenThrowShardingSphereConfigurationException() { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(Collections.emptyMap(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(Collections.emptyMap(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ProxyContext.init(new ContextManager(metaDataContexts, mock(InstanceContext.class))); assertTrue(metaDataContexts.getMetaData().getDatabases().isEmpty()); assertThat(FrontDatabaseProtocolTypeFactory.getDatabaseType().getType(), is("MySQL")); @@ -61,7 +62,7 @@ public void assertGetDatabaseTypeWhenThrowShardingSphereConfigurationException() @Test public void assertGetDatabaseTypeInstanceOfMySQLDatabaseTypeFromMetaDataContextsSchemaName() { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(mockDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(mockDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); ProxyContext.init(new ContextManager(metaDataContexts, mock(InstanceContext.class))); assertFalse(metaDataContexts.getMetaData().getDatabases().isEmpty()); String configuredDatabaseType = metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE); @@ -75,7 +76,7 @@ public void assertGetDatabaseTypeInstanceOfMySQLDatabaseTypeFromMetaDataContexts @Test public void assertGetDatabaseTypeOfPostgreSQLDatabaseTypeFromMetaDataContextsProps() { MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(mockDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(createProperties()))); + new ShardingSphereMetaData(mockDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(createProperties())), new ShardingSphereData()); ProxyContext.init(new ContextManager(metaDataContexts, mock(InstanceContext.class))); assertFalse(metaDataContexts.getMetaData().getDatabases().isEmpty()); String configuredDatabaseType = metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE); diff --git a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java index 69b0d04951301..86798e6f3486b 100644 --- a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java +++ b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; @@ -63,8 +64,8 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNull; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.isA; @@ -174,7 +175,7 @@ private void initProxyContext(final ShardingSphereUser user) { private MetaDataContexts getMetaDataContexts(final ShardingSphereUser user) { return new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties())), new ShardingSphereData()); } private Map getDatabases() { diff --git a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java index 10853726f24d1..630484486aa80 100644 --- a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java +++ b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngineTest.java @@ -25,14 +25,15 @@ import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCapabilityFlag; import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConnectionPhase; import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants; -import org.apache.shardingsphere.dialect.mysql.vendor.MySQLVendorError; import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket; import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket; import org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData; import org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLHandshakePacket; import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload; +import org.apache.shardingsphere.dialect.mysql.vendor.MySQLVendorError; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -164,7 +165,7 @@ private void setMetaDataContexts() { Map databases = new LinkedHashMap<>(1, 1); databases.put("sharding_db", mock(ShardingSphereDatabase.class)); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), - new ConfigurationProperties(new Properties()))); + new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java index 1396dc1d4e1bc..bc8d5a4d99ef5 100644 --- a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java +++ b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationHandlerTest.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; @@ -52,8 +53,8 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -138,7 +139,7 @@ private void initProxyContext(final ShardingSphereUser user, final boolean isNee private MetaDataContexts getMetaDataContexts(final ShardingSphereUser user, final boolean isNeedSuper) throws NoSuchFieldException, IllegalAccessException { return new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user, isNeedSuper), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user, isNeedSuper), new ConfigurationProperties(new Properties())), new ShardingSphereData()); } private Map getDatabases() { diff --git a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java index bb8dff0837078..68506cb59bd18 100644 --- a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java +++ b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -91,7 +92,7 @@ public void setUp() { databases.put("logic_db", database); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(new Properties())), new ShardingSphereData()); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); } diff --git a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java index 5285077974787..88af659c8487b 100644 --- a/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java +++ b/proxy/frontend/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -82,8 +83,8 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -112,7 +113,7 @@ public void setUp() { databases.put("logic_db", mockDatabase()); ShardingSphereRuleMetaData metaData = mock(ShardingSphereRuleMetaData.class); MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(databases, metaData, new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(databases, metaData, new ConfigurationProperties(new Properties())), new ShardingSphereData()); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); diff --git a/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java b/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java index 717cbbc39468c..2f5e48629ae09 100644 --- a/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java +++ b/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java @@ -37,6 +37,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -61,8 +62,8 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -169,7 +170,7 @@ private ByteBuf createByteBuf(final int initialCapacity, final int maxCapacity) private MetaDataContexts getMetaDataContexts(final ShardingSphereUser user) { return new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(new LinkedHashMap<>(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(new LinkedHashMap<>(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties())), new ShardingSphereData()); } private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user) { diff --git a/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java b/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java index 84a87435309bf..9c3a95b8e9684 100644 --- a/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java +++ b/proxy/frontend/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandlerTest.java @@ -34,6 +34,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -119,7 +120,7 @@ private void initProxyContext(final ShardingSphereUser user) { private MetaDataContexts getMetaDataContexts(final ShardingSphereUser user) { return new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties())), new ShardingSphereData()); } private ByteBuf createByteBuf(final int initialCapacity, final int maxCapacity) { diff --git a/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java b/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java index 1ddb63fa68b44..8ec398a000e82 100644 --- a/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java +++ b/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java @@ -38,6 +38,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -64,8 +65,8 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -178,7 +179,7 @@ private ByteBuf createByteBuf(final int initialCapacity, final int maxCapacity) private MetaDataContexts getMetaDataContexts(final ShardingSphereUser user) { return new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(new LinkedHashMap<>(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(new LinkedHashMap<>(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties())), new ShardingSphereData()); } private ShardingSphereRuleMetaData buildGlobalRuleMetaData(final ShardingSphereUser user) { diff --git a/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java b/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java index 1a80db7401e91..95750b3447d62 100644 --- a/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java +++ b/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandlerTest.java @@ -34,6 +34,7 @@ import org.apache.shardingsphere.infra.database.DefaultDatabase; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResource; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; @@ -126,7 +127,7 @@ private void initProxyContext(final ShardingSphereUser user) { private MetaDataContexts getMetaDataContexts(final ShardingSphereUser user) { return new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties()))); + new ShardingSphereMetaData(getDatabases(), buildGlobalRuleMetaData(user), new ConfigurationProperties(new Properties())), new ShardingSphereData()); } private ByteBuf createByteBuf(final int initialCapacity, final int maxCapacity) { diff --git a/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java b/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java index f47b0e40551a7..279378a451297 100644 --- a/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java +++ b/proxy/frontend/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java @@ -24,6 +24,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; @@ -68,7 +69,7 @@ public final class PostgreSQLCommandExecuteEngineTest extends ProxyContextRestor @Before public void setUp() { - ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()), mock(InstanceContext.class))); + ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData(), new ShardingSphereData()), mock(InstanceContext.class))); when(channelHandlerContext.channel()).thenReturn(channel); when(connectionSession.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.LOCAL)); } diff --git a/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java b/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java index b6f578fdae8ac..f942fcf65add5 100644 --- a/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java +++ b/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java @@ -22,9 +22,6 @@ import org.apache.commons.lang3.concurrent.LazyInitializer; import org.apache.shardingsphere.data.pipeline.api.config.job.MigrationJobConfiguration; import org.apache.shardingsphere.data.pipeline.api.config.process.PipelineProcessConfiguration; -import org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineProcessConfiguration; -import org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineProcessConfigurationSwapper; -import org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineReadConfiguration; import org.apache.shardingsphere.data.pipeline.api.datasource.config.impl.ShardingSpherePipelineDataSourceConfiguration; import org.apache.shardingsphere.data.pipeline.core.config.process.PipelineProcessConfigurationUtil; import org.apache.shardingsphere.data.pipeline.core.context.PipelineContext; @@ -38,9 +35,13 @@ import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationProcessContext; import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationTaskConfiguration; import org.apache.shardingsphere.data.pipeline.spi.ingest.channel.PipelineChannelCreator; +import org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineProcessConfiguration; +import org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineProcessConfigurationSwapper; +import org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineReadConfiguration; import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.database.DefaultDatabase; +import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -128,7 +129,7 @@ private static MetaDataContexts renewMetaDataContexts(final MetaDataContexts old tables.put("t_order", new ShardingSphereTable("t_order", Arrays.asList(new ShardingSphereColumn("order_id", Types.INTEGER, true, false, false, true), new ShardingSphereColumn("user_id", Types.VARCHAR, false, false, false, true)), Collections.emptyList(), Collections.emptyList())); old.getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).putAll(tables); - return new MetaDataContexts(persistService, old.getMetaData()); + return new MetaDataContexts(persistService, old.getMetaData(), new ShardingSphereData()); } /**