You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/06/08 06:10:02 UTC

[shardingsphere] branch master updated: Add same order check for OrderedSPIRegistry (#10712)

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

menghaoran 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 e3297c0  Add same order check for OrderedSPIRegistry (#10712)
e3297c0 is described below

commit e3297c01a4987a220040ba0356d1c09113e01a72
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Jun 8 14:09:17 2021 +0800

    Add same order check for OrderedSPIRegistry (#10712)
---
 .../apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistry.java  | 2 ++
 .../shardingsphere/infra/spi/ordered/OrderedSPIRegistryTest.java     | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistry.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistry.java
index bcada99..5d547b8 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistry.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistry.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.spi.ordered;
 
+import com.google.common.base.Preconditions;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -86,6 +87,7 @@ public final class OrderedSPIRegistry {
     public static <T extends OrderedSPI<?>> Collection<T> getRegisteredServices(final Class<T> orderedSPIClass) {
         Map<Integer, T> result = new TreeMap<>();
         for (T each : ShardingSphereServiceLoader.getSingletonServiceInstances(orderedSPIClass)) {
+            Preconditions.checkArgument(!result.containsKey(each.getOrder()), "Found same order `%s` with `%s` and `%s`", each.getOrder(), result.get(each.getOrder()), each);
             result.put(each.getOrder(), each);
         }
         return result.values();
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistryTest.java
index bfd8607d..1c461c3 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistryTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/ordered/OrderedSPIRegistryTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.infra.spi.ordered;
 
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.fixture.FixtureCustomInterface;
 import org.apache.shardingsphere.infra.spi.fixture.FixtureCustomInterfaceImpl;
 import org.apache.shardingsphere.infra.spi.fixture.ordered.OrderedSPIFixture;
 import org.apache.shardingsphere.infra.spi.fixture.ordered.OrderedSPIFixtureImpl;
@@ -51,6 +52,7 @@ public final class OrderedSPIRegistryTest {
         field.set(null, new ConcurrentHashMap<>());
     }
     
+    @SuppressWarnings("rawtypes")
     @Test
     public void assertGetRegisteredServicesByClass() {
         Map<Class<?>, OrderedSPIFixture> actual = OrderedSPIRegistry.getRegisteredServicesByClass(Collections.singleton(FixtureCustomInterfaceImpl.class), OrderedSPIFixture.class);
@@ -58,6 +60,7 @@ public final class OrderedSPIRegistryTest {
         assertThat(actual.get(FixtureCustomInterfaceImpl.class), instanceOf(OrderedSPIFixtureImpl.class));
     }
     
+    @SuppressWarnings("rawtypes")
     @Test
     public void assertGetRegisteredServices() {
         FixtureCustomInterfaceImpl key = new FixtureCustomInterfaceImpl();
@@ -68,7 +71,7 @@ public final class OrderedSPIRegistryTest {
 
     @Test
     public void assertGetRegisteredServicesFromCache() {
-        FixtureCustomInterfaceImpl key = new FixtureCustomInterfaceImpl();
+        FixtureCustomInterface key = new FixtureCustomInterfaceImpl();
         assertThat(OrderedSPIRegistry.getRegisteredServices(Collections.singleton(key), OrderedSPIFixture.class), 
                 is(OrderedSPIRegistry.getRegisteredServices(Collections.singleton(key), OrderedSPIFixture.class)));
     }