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 f29e6011e4b Add test cases on ShadowDataNodeBuilder (#33535)
f29e6011e4b is described below

commit f29e6011e4bf4da9a054da8daf511737be61a46c
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Nov 4 16:48:11 2024 +0800

    Add test cases on ShadowDataNodeBuilder (#33535)
---
 .../ReadwriteSplittingDataNodeBuilder.java         |  2 +
 .../shadow/datanode/ShadowDataNodeBuilder.java     |  2 +
 .../shadow/datanode/ShadowDataNodeBuilderTest.java | 63 ++++++++++++++++++++++
 .../decider/ShardingSQLFederationDecider.java      |  2 +
 .../shardingsphere/infra/datanode/DataNodes.java   |  2 +
 5 files changed, 71 insertions(+)

diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
index 35ee19a16bd..135343ecccc 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.readwritesplitting.datanode;
 
+import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.datanode.DataNodeBuilder;
 import org.apache.shardingsphere.infra.datanode.DataNodeUtils;
@@ -31,6 +32,7 @@ import java.util.Map;
 /**
  * Readwrite-splitting data node builder.
  */
+@HighFrequencyInvocation
 public final class ReadwriteSplittingDataNodeBuilder implements 
DataNodeBuilder<ReadwriteSplittingRule> {
     
     @Override
diff --git 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
index bbd0e9e642d..1ebaca50f73 100644
--- 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
+++ 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.shadow.datanode;
 
+import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.datanode.DataNodeBuilder;
 import org.apache.shardingsphere.infra.datanode.DataNodeUtils;
@@ -31,6 +32,7 @@ import java.util.Map;
 /**
  * Shadow data node builder.
  */
+@HighFrequencyInvocation
 public final class ShadowDataNodeBuilder implements 
DataNodeBuilder<ShadowRule> {
     
     @Override
diff --git 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilderTest.java
 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilderTest.java
new file mode 100644
index 00000000000..31427860bab
--- /dev/null
+++ 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilderTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.shadow.datanode;
+
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.datanode.DataNodeBuilder;
+import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
+import 
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
+import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
+import org.apache.shardingsphere.shadow.rule.ShadowRule;
+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.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class ShadowDataNodeBuilderTest {
+    
+    @Mock
+    private ShadowRule rule;
+    
+    @Mock
+    private DataSourceMapperRuleAttribute dataSourceMapperRuleAttribute;
+    
+    private ShadowDataNodeBuilder builder;
+    
+    @BeforeEach
+    void setUp() {
+        
when(dataSourceMapperRuleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("foo_db",
 Arrays.asList("foo_prod_db", "foo_shadow_db")));
+        when(rule.getAttributes()).thenReturn(new 
RuleAttributes(dataSourceMapperRuleAttribute));
+        builder = (ShadowDataNodeBuilder) 
OrderedSPILoader.getServices(DataNodeBuilder.class, 
Collections.singleton(rule)).get(rule);
+    }
+    
+    @Test
+    void assertBuild() {
+        Collection<DataNode> actual = builder.build(Collections.singleton(new 
DataNode("foo_db.foo_tbl")), rule);
+        assertThat(actual, is(Arrays.asList(new 
DataNode("foo_prod_db.foo_tbl"), new DataNode("foo_shadow_db.foo_tbl"))));
+    }
+}
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/decider/ShardingSQLFederationDecider.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/decider/ShardingSQLFederationDecider.java
index 7a6036121f3..436be746662 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/decider/ShardingSQLFederationDecider.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/decider/ShardingSQLFederationDecider.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.sharding.decider;
 
+import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
 import 
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.datanode.DataNodes;
@@ -33,6 +34,7 @@ import java.util.List;
 /**
  * Sharding SQL federation decider.
  */
+@HighFrequencyInvocation
 public final class ShardingSQLFederationDecider implements 
SQLFederationDecider<ShardingRule> {
     
     @Override
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
index 98e039727d9..44935845d7c 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.infra.datanode;
 
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import 
org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
@@ -49,6 +50,7 @@ public final class DataNodes {
      * @param tableName table name
      * @return data nodes
      */
+    @HighFrequencyInvocation
     @SuppressWarnings({"unchecked", "rawtypes"})
     public Collection<DataNode> getDataNodes(final String tableName) {
         Collection<DataNode> result = getDataNodesByTableName(tableName);

Reply via email to