You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/11/29 13:46:40 UTC

(shardingsphere) branch master updated: Add TableMetaDataPersistDisabledServiceTest (#37222)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 5a0bca4f79e Add TableMetaDataPersistDisabledServiceTest (#37222)
5a0bca4f79e is described below

commit 5a0bca4f79eb5ee35238989f6a28dc2fc30c87c4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Nov 29 21:46:34 2025 +0800

    Add TableMetaDataPersistDisabledServiceTest (#37222)
---
 .../TableMetaDataPersistDisabledService.java       |  6 +-
 .../TableMetaDataPersistDisabledServiceTest.java   | 90 ++++++++++++++++++++++
 2 files changed, 92 insertions(+), 4 deletions(-)

diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableMetaDataPersistDisabledService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableMetaDataPersistDisabledService.java
index 2741a43d442..5c51704a9b5 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableMetaDataPersistDisabledService.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableMetaDataPersistDisabledService.java
@@ -54,8 +54,7 @@ public final class TableMetaDataPersistDisabledService implements TableMetaDataP
     @Override
     public void persist(final String databaseName, final String schemaName, final Collection<ShardingSphereTable> tables) {
         for (ShardingSphereTable each : tables) {
-            TableCoordinatorTypeNodePath tableCoordinatorTypeNodePath = new TableCoordinatorTypeNodePath(Joiner.on(".").join(databaseName, schemaName, each.getName()),
-                    CoordinatorType.CREATE.name());
+            TableCoordinatorTypeNodePath tableCoordinatorTypeNodePath = new TableCoordinatorTypeNodePath(Joiner.on(".").join(databaseName, schemaName, each.getName()), CoordinatorType.CREATE.name());
             repository.persist(NodePathGenerator.toPath(tableCoordinatorTypeNodePath), YamlEngine.marshal(swapper.swapToYamlConfiguration(each)));
             repository.delete(NodePathGenerator.toPath(tableCoordinatorTypeNodePath.getTableCoordinatorPath()));
         }
@@ -63,8 +62,7 @@ public final class TableMetaDataPersistDisabledService implements TableMetaDataP
     
     @Override
     public void drop(final String databaseName, final String schemaName, final String tableName) {
-        TableCoordinatorTypeNodePath tableCoordinatorTypeNodePath = new TableCoordinatorTypeNodePath(Joiner.on(".").join(databaseName, schemaName, tableName),
-                CoordinatorType.DROP.name());
+        TableCoordinatorTypeNodePath tableCoordinatorTypeNodePath = new TableCoordinatorTypeNodePath(Joiner.on(".").join(databaseName, schemaName, tableName), CoordinatorType.DROP.name());
         repository.persist(NodePathGenerator.toPath(tableCoordinatorTypeNodePath), tableName);
         repository.delete(NodePathGenerator.toPath(tableCoordinatorTypeNodePath.getTableCoordinatorPath()));
     }
diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableMetaDataPersistDisabledServiceTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableMetaDataPersistDisabledServiceTest.java
new file mode 100644
index 00000000000..22cae1584bb
--- /dev/null
+++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/TableMetaDataPersistDisabledServiceTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.metadata.service;
+
+import com.google.common.base.Joiner;
+import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import org.apache.shardingsphere.infra.yaml.schema.swapper.YamlTableSwapper;
+import org.apache.shardingsphere.mode.node.path.engine.generator.NodePathGenerator;
+import org.apache.shardingsphere.mode.node.path.type.global.state.coordinator.CoordinatorType;
+import org.apache.shardingsphere.mode.node.path.type.global.state.coordinator.TableCoordinatorTypeNodePath;
+import org.apache.shardingsphere.mode.spi.repository.PersistRepository;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class TableMetaDataPersistDisabledServiceTest {
+    
+    private TableMetaDataPersistDisabledService persistService;
+    
+    @Mock
+    private PersistRepository repository;
+    
+    @BeforeEach
+    void setUp() {
+        persistService = new TableMetaDataPersistDisabledService(repository);
+    }
+    
+    @Test
+    void assertLoadTables() {
+        assertTrue(persistService.load("foo_db", "foo_schema").isEmpty());
+    }
+    
+    @Test
+    void assertLoadTable() {
+        assertNull(persistService.load("foo_db", "foo_schema", "foo_tbl"));
+    }
+    
+    @Test
+    void assertPersist() {
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+        String qualifiedTableName = Joiner.on(".").join("foo_db", "foo_schema", "foo_tbl");
+        TableCoordinatorTypeNodePath tableCoordinatorTypeNodePath = new TableCoordinatorTypeNodePath(qualifiedTableName, CoordinatorType.CREATE.name());
+        String expectedPersistPath = NodePathGenerator.toPath(tableCoordinatorTypeNodePath);
+        String expectedDeletePath = NodePathGenerator.toPath(tableCoordinatorTypeNodePath.getTableCoordinatorPath());
+        String expectedContent = YamlEngine.marshal(new YamlTableSwapper().swapToYamlConfiguration(table));
+        persistService.persist("foo_db", "foo_schema", Collections.singleton(table));
+        verify(repository).persist(expectedPersistPath, expectedContent);
+        verify(repository).delete(expectedDeletePath);
+    }
+    
+    @Test
+    void assertDrop() {
+        ShardingSphereTable table = mock(ShardingSphereTable.class);
+        when(table.getName()).thenReturn("foo_tbl");
+        String qualifiedTableName = Joiner.on(".").join("foo_db", "foo_schema", "foo_tbl");
+        TableCoordinatorTypeNodePath tableCoordinatorTypeNodePath = new TableCoordinatorTypeNodePath(qualifiedTableName, CoordinatorType.DROP.name());
+        String expectedPersistPath = NodePathGenerator.toPath(tableCoordinatorTypeNodePath);
+        String expectedDeletePath = NodePathGenerator.toPath(tableCoordinatorTypeNodePath.getTableCoordinatorPath());
+        persistService.drop("foo_db", "foo_schema", Collections.singleton(table));
+        verify(repository).persist(expectedPersistPath, "foo_tbl");
+        verify(repository).delete(expectedDeletePath);
+    }
+}