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 2020/08/21 09:30:14 UTC
[shardingsphere] branch master updated: using SPI to instantiate
MasterSlaveRouteDecorator (#6954)
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 c6d5cbf using SPI to instantiate MasterSlaveRouteDecorator (#6954)
c6d5cbf is described below
commit c6d5cbfa51713edc8ea19bad8886582a05a7876d
Author: DanielWei <da...@gmail.com>
AuthorDate: Fri Aug 21 17:30:02 2020 +0800
using SPI to instantiate MasterSlaveRouteDecorator (#6954)
---
.../route/engine/MasterSlaveRouteDecoratorTest.java | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java
index 936bdd7..5c2f334 100644
--- a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java
@@ -17,6 +17,9 @@
package org.apache.shardingsphere.masterslave.route.engine;
+import org.apache.shardingsphere.infra.route.decorator.RouteDecorator;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
@@ -72,12 +75,18 @@ public final class MasterSlaveRouteDecoratorTest {
private SelectStatement selectStatement;
private MasterSlaveRouteDecorator routeDecorator;
-
+
+ static {
+ ShardingSphereServiceLoader.register(RouteDecorator.class);
+ }
+
@Before
public void setUp() {
- routeDecorator = new MasterSlaveRouteDecorator();
masterSlaveRule = new MasterSlaveRule(new MasterSlaveRuleConfiguration(
Collections.singleton(new MasterSlaveDataSourceRuleConfiguration(DATASOURCE_NAME, MASTER_DATASOURCE, Collections.singletonList(SLAVE_DATASOURCE), null)), Collections.emptyMap()));
+ routeDecorator = (MasterSlaveRouteDecorator) OrderedSPIRegistry
+ .getRegisteredServices(Collections.singleton(masterSlaveRule), RouteDecorator.class)
+ .get(masterSlaveRule);
}
@After
@@ -148,7 +157,7 @@ public final class MasterSlaveRouteDecoratorTest {
assertThat(routedDataSourceNames.next(), is(MASTER_DATASOURCE));
assertThat(actual.getParameters().get(0), is("true"));
}
-
+
private RouteContext mockSQLRouteContext(final SQLStatement sqlStatement) {
when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
return new RouteContext(sqlStatementContext, Collections.emptyList(), mockRouteResult());