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 259a5ef9ad1 Add ShardingSphereDatabaseDataTest (#34080)
259a5ef9ad1 is described below

commit 259a5ef9ad1860740e213e921c8d40f75531bc41
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Mon Dec 16 19:33:26 2024 +0800

    Add ShardingSphereDatabaseDataTest (#34080)
    
    * Add ShardingSphereDatabaseDataTest
    
    * Add ShardingSphereDatabaseDataTest
---
 .../statistics/ShardingSphereDatabaseData.java     | 28 +++++-----
 .../statistics/ShardingSphereDatabaseDataTest.java | 59 ++++++++++++++++++++++
 .../data/ShardingSphereDataPersistService.java     |  2 +-
 3 files changed, 74 insertions(+), 15 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/ShardingSphereDatabaseData.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/ShardingSphereDatabaseData.java
index 4aaa32a97a6..19cdb2cf2f4 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/ShardingSphereDatabaseData.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/ShardingSphereDatabaseData.java
@@ -30,42 +30,42 @@ public final class ShardingSphereDatabaseData {
     
     private final Map<String, ShardingSphereSchemaData> schemaData = new 
CaseInsensitiveMap<>();
     
+    /**
+     * Judge whether to contains schema.
+     *
+     * @param schemaName schema name
+     * @return contains schema or not
+     */
+    public boolean containsSchema(final String schemaName) {
+        return schemaData.containsKey(schemaName);
+    }
+    
     /**
      * Get ShardingSphere schema data.
      *
      * @param schemaName schema name
-     * @return ShardingSphere schema data
+     * @return schema data
      */
     public ShardingSphereSchemaData getSchema(final String schemaName) {
         return schemaData.get(schemaName);
     }
     
     /**
-     * Put ShardingSphere schema data.
+     * Put schema data.
      *
      * @param schemaName schema name
-     * @param schema ShardingSphere schema data
+     * @param schema schema data
      */
     public void putSchema(final String schemaName, final 
ShardingSphereSchemaData schema) {
         schemaData.put(schemaName, schema);
     }
     
     /**
-     * Remove ShardingSphere schema data.
+     * Remove schema data.
      *
      * @param schemaName schema name
      */
     public void removeSchema(final String schemaName) {
         schemaData.remove(schemaName);
     }
-    
-    /**
-     * Judge contains ShardingSphere schema from ShardingSphere database or 
not.
-     *
-     * @param schemaName schema name
-     * @return Contains schema from database or not
-     */
-    public boolean containsSchema(final String schemaName) {
-        return schemaData.containsKey(schemaName);
-    }
 }
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/ShardingSphereDatabaseDataTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/ShardingSphereDatabaseDataTest.java
new file mode 100644
index 00000000000..a8696badf14
--- /dev/null
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/statistics/ShardingSphereDatabaseDataTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.metadata.statistics;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class ShardingSphereDatabaseDataTest {
+    
+    private final ShardingSphereDatabaseData databaseData = new 
ShardingSphereDatabaseData();
+    
+    @BeforeEach
+    void setUp() {
+        databaseData.putSchema("foo_schema", new ShardingSphereSchemaData());
+    }
+    
+    @Test
+    void assertContainsSchema() {
+        assertTrue(databaseData.containsSchema("foo_schema"));
+        assertFalse(databaseData.containsSchema("bar_schema"));
+    }
+    
+    @Test
+    void assertGetSchema() {
+        
assertTrue(databaseData.getSchema("foo_schema").getTableData().isEmpty());
+        assertNull(databaseData.getSchema("bar_schema"));
+    }
+    
+    @Test
+    void assertPutSchema() {
+        databaseData.putSchema("bar_schema", new ShardingSphereSchemaData());
+        assertTrue(databaseData.containsSchema("bar_schema"));
+    }
+    
+    @Test
+    void assertRemoveSchema() {
+        databaseData.removeSchema("foo_schema");
+        assertFalse(databaseData.containsSchema("foo_schema"));
+    }
+}
diff --git 
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/data/ShardingSphereDataPersistService.java
 
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/data/ShardingSphereDataPersistService.java
index a09d909e553..f61da68b54e 100644
--- 
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/data/ShardingSphereDataPersistService.java
+++ 
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/data/ShardingSphereDataPersistService.java
@@ -69,7 +69,7 @@ public final class ShardingSphereDataPersistService {
     private ShardingSphereDatabaseData load(final String databaseName, final 
ShardingSphereDatabase database) {
         ShardingSphereDatabaseData result = new ShardingSphereDatabaseData();
         for (String each : 
repository.getChildrenKeys(ShardingSphereDataNode.getSchemasPath(databaseName)).stream().filter(database::containsSchema).collect(Collectors.toList()))
 {
-            result.getSchemaData().put(each, load(databaseName, each, 
database.getSchema(each)));
+            result.putSchema(each, load(databaseName, each, 
database.getSchema(each)));
         }
         return result;
     }

Reply via email to